diff options
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/admin.c | 782 | ||||
-rw-r--r-- | mbbsd/announce.c | 1122 | ||||
-rw-r--r-- | mbbsd/args.c | 60 | ||||
-rw-r--r-- | mbbsd/bbcall.c | 131 | ||||
-rw-r--r-- | mbbsd/bbs.c | 2736 | ||||
-rw-r--r-- | mbbsd/board.c | 1078 | ||||
-rw-r--r-- | mbbsd/cache.c | 1114 | ||||
-rw-r--r-- | mbbsd/cal.c | 456 | ||||
-rw-r--r-- | mbbsd/calendar.c | 260 | ||||
-rw-r--r-- | mbbsd/card.c | 964 | ||||
-rw-r--r-- | mbbsd/chat.c | 369 | ||||
-rw-r--r-- | mbbsd/chc_draw.c | 119 | ||||
-rw-r--r-- | mbbsd/chc_net.c | 22 | ||||
-rw-r--r-- | mbbsd/chc_play.c | 133 | ||||
-rw-r--r-- | mbbsd/chc_rule.c | 212 | ||||
-rw-r--r-- | mbbsd/chicken.c | 848 | ||||
-rw-r--r-- | mbbsd/dark.c | 725 | ||||
-rw-r--r-- | mbbsd/descrypt.c | 451 | ||||
-rw-r--r-- | mbbsd/dice.c | 445 | ||||
-rw-r--r-- | mbbsd/edit.c | 1722 | ||||
-rw-r--r-- | mbbsd/friend.c | 311 | ||||
-rw-r--r-- | mbbsd/gamble.c | 586 | ||||
-rw-r--r-- | mbbsd/gomo.c | 303 | ||||
-rw-r--r-- | mbbsd/gomo1.c | 108 | ||||
-rw-r--r-- | mbbsd/guess.c | 308 | ||||
-rw-r--r-- | mbbsd/indict.c | 150 | ||||
-rw-r--r-- | mbbsd/io.c | 478 | ||||
-rw-r--r-- | mbbsd/kaede.c | 77 | ||||
-rw-r--r-- | mbbsd/lovepaper.c | 81 | ||||
-rw-r--r-- | mbbsd/mail.c | 1119 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 1504 | ||||
-rw-r--r-- | mbbsd/menu.c | 446 | ||||
-rw-r--r-- | mbbsd/more.c | 782 | ||||
-rw-r--r-- | mbbsd/name.c | 671 | ||||
-rw-r--r-- | mbbsd/osdep.c | 74 | ||||
-rw-r--r-- | mbbsd/othello.c | 427 | ||||
-rw-r--r-- | mbbsd/page.c | 128 | ||||
-rw-r--r-- | mbbsd/passwd.c | 94 | ||||
-rw-r--r-- | mbbsd/read.c | 810 | ||||
-rw-r--r-- | mbbsd/record.c | 467 | ||||
-rw-r--r-- | mbbsd/register.c | 296 | ||||
-rw-r--r-- | mbbsd/screen.c | 410 | ||||
-rw-r--r-- | mbbsd/stuff.c | 549 | ||||
-rw-r--r-- | mbbsd/syspost.c | 118 | ||||
-rw-r--r-- | mbbsd/talk.c | 1741 | ||||
-rw-r--r-- | mbbsd/term.c | 98 | ||||
-rw-r--r-- | mbbsd/toolkit.c | 10 | ||||
-rw-r--r-- | mbbsd/topsong.c | 72 | ||||
-rw-r--r-- | mbbsd/user.c | 896 | ||||
-rw-r--r-- | mbbsd/var.c | 971 | ||||
-rw-r--r-- | mbbsd/vice.c | 155 | ||||
-rw-r--r-- | mbbsd/vote.c | 810 | ||||
-rw-r--r-- | mbbsd/voteboard.c | 302 | ||||
-rw-r--r-- | mbbsd/xyz.c | 301 |
54 files changed, 15255 insertions, 14147 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index f31ee516..ffe594dc 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -1,17 +1,19 @@ -/* $Id: admin.c,v 1.24 2002/06/23 01:56:13 ptt Exp $ */ +/* $Id: admin.c,v 1.25 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" /* ¨Ï¥ÎªÌºÞ²z */ -int m_user() { - userec_t muser; - int id; - char genbuf[200]; - +int +m_user() +{ + userec_t muser; + int id; + char genbuf[200]; + stand_title("¨Ï¥ÎªÌ³]©w"); usercomplete(msg_uid, genbuf); - if(*genbuf) { + if (*genbuf) { move(2, 0); - if((id = getuser(genbuf))) { + if ((id = getuser(genbuf))) { memcpy(&muser, &xuser, sizeof(muser)); user_display(&muser, 1); uinfo_query(&muser, 1, id); @@ -24,49 +26,51 @@ int m_user() { return 0; } -static int search_key_user(char *passwdfile, int mode) { - userec_t user; - int ch; - int coun = 0; - FILE *fp1 = fopen(passwdfile, "r"); - char buf[128], key[22], genbuf[8]; - +static int +search_key_user(char *passwdfile, int mode) +{ + userec_t user; + int ch; + int coun = 0; + FILE *fp1 = fopen(passwdfile, "r"); + char buf[128], key[22], genbuf[8]; + clear(); getdata(0, 0, mode ? "½Ð¿é¤J¨Ï¥ÎªÌÃöÁä¦r[¹q¸Ü|¦a§}|©m¦W|¤W¯¸¦aÂI|" "email|¤pÂûid] :" : "½Ð¿é¤Jid :", key, sizeof(key), DOECHO); - while((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { - if(!(++coun & 15)) { + while ((fread(&user, sizeof(user), 1, fp1)) > 0 && coun < MAX_USERS) { + if (!(++coun & 15)) { move(1, 0); sprintf(buf, "²Ä [%d] µ§¸ê®Æ\n", coun); outs(buf); refresh(); } - if(!strcasecmp(user.userid, key) || - (mode && ( - strstr(user.realname, key) || strstr(user.username, key) || - strstr(user.lasthost, key) || strstr(user.email, key) || - strstr(user.address, key) || strstr(user.justify, key) || - strstr(user.mychicken.name, key)))) { + if (!strcasecmp(user.userid, key) || + (mode && ( + strstr(user.realname, key) || strstr(user.username, key) || + strstr(user.lasthost, key) || strstr(user.email, key) || + strstr(user.address, key) || strstr(user.justify, key) || + strstr(user.mychicken.name, key)))) { move(1, 0); sprintf(buf, "²Ä [%d] µ§¸ê®Æ\n", coun); outs(buf); refresh(); - + user_display(&user, 1); uinfo_query(&user, 1, coun); outs("\033[44m ªÅ¥ÕÁä\033[37m:·j´M¤U¤@Ó" " \033[33m Q\033[37m: Â÷¶}"); outs(mode ? " \033[m " : " S: ¨ú¥Î³Æ¥÷¸ê®Æ \033[m "); - while(1) { - while((ch = igetch()) == 0); - if(ch == ' ') - break; - if(ch == 'q' || ch == 'Q') + while (1) { + while ((ch = igetch()) == 0); + if (ch == ' ') + break; + if (ch == 'q' || ch == 'Q') return 0; - if(ch == 's' && !mode) { - if((ch = searchuser(user.userid))) { - setumoney(ch,user.money); + if (ch == 's' && !mode) { + if ((ch = searchuser(user.userid))) { + setumoney(ch, user.money); passwd_update(ch, &user); return 0; } else { @@ -75,23 +79,22 @@ static int search_key_user(char *passwdfile, int mode) { getdata(0, 0, "¥Ø«eªº PASSWD ÀɨS¦³¦¹ ID¡A·s¼W¶Ü¡H[y/N]", genbuf, 3, LCECHO); - if(genbuf[0] == 'n') { + if (genbuf[0] == 'n') { outs("¥Ø«eªºPASSWDSÀɨS¦³¦¹id " "½Ð¥ýnew¤@Ó³oÓidªº±b¸¹"); } else { - int allocid = getnewuserid(); - - if(allocid > MAX_USERS || allocid <= 0) { + int allocid = getnewuserid(); + + if (allocid > MAX_USERS || allocid <= 0) { fprintf(stderr, "¥»¯¸¤H¤f¤w¹F¹¡©M¡I\n"); exit(1); } - - if(passwd_update(allocid, &user) == -1) { + if (passwd_update(allocid, &user) == -1) { fprintf(stderr, "«Èº¡¤F¡A¦A¨£¡I\n"); exit(1); } setuserid(allocid, user.userid); - if(!searchuser(user.userid)) { + if (!searchuser(user.userid)) { fprintf(stderr, "µLªk«Ø¥ß±b¸¹\n"); exit(1); } @@ -102,26 +105,30 @@ static int search_key_user(char *passwdfile, int mode) { } } } - + fclose(fp1); return 0; } /* ¥H¥ô·N key ´M§ä¨Ï¥ÎªÌ */ -int search_user_bypwd() { +int +search_user_bypwd() +{ search_key_user(FN_PASSWD, 1); return 0; } /* ´M§ä³Æ¥÷ªº¨Ï¥ÎªÌ¸ê®Æ */ -int search_user_bybakpwd() { - char *choice[] = { +int +search_user_bybakpwd() +{ + char *choice[] = { "PASSWDS.NEW1", "PASSWDS.NEW2", "PASSWDS.NEW3", "PASSWDS.NEW4", "PASSWDS.NEW5", "PASSWDS.NEW6", "PASSWDS.BAK" }; - int ch; - + int ch; + clear(); move(1, 1); outs("½Ð¿é¤J§An¥Î¨Ó´M§ä³Æ¥÷ªºÀÉ®× ©Î«ö 'q' Â÷¶}\n"); @@ -134,7 +141,7 @@ int search_user_bybakpwd() { move(5, 1); outs("¿ï¾Ü => "); ch = igetch(); - if(ch == 'q' || ch == 'Q') + if (ch == 'q' || ch == 'Q') return 0; } while (ch < '1' || ch > '8'); ch -= '1'; @@ -142,17 +149,21 @@ int search_user_bybakpwd() { return 0; } -static void bperm_msg(boardheader_t *board) { +static void +bperm_msg(boardheader_t * board) +{ prints("\n³]©w [%s] ¬ÝªO¤§(%s)Åv¡G", board->brdname, board->brdattr & BRD_POSTMASK ? "µoªí" : "¾\\Ū"); } -unsigned int setperms(unsigned int pbits, char *pstring[]) { - register int i; - char choice[4]; - +unsigned int +setperms(unsigned int pbits, char *pstring[]) +{ + register int i; + char choice[4]; + move(4, 0); - for(i = 0; i < NUMPERMS / 2; i++) { + for (i = 0; i < NUMPERMS / 2; i++) { prints("%c. %-20s %-15s %c. %-20s %s\n", 'A' + i, pstring[i], ((pbits >> i) & 1 ? "£¾" : "¢æ"), @@ -161,12 +172,12 @@ unsigned int setperms(unsigned int pbits, char *pstring[]) { ((pbits >> (i + 16)) & 1 ? "£¾" : "¢æ")); } clrtobot(); - while(getdata(b_lines - 1, 0, "½Ð«ö [A-5] ¤Á´«³]©w¡A«ö [Return] µ²§ô¡G", - choice, sizeof(choice), LCECHO)) { + while (getdata(b_lines - 1, 0, "½Ð«ö [A-5] ¤Á´«³]©w¡A«ö [Return] µ²§ô¡G", + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; - if(i < 0) + if (i < 0) i = choice[0] - '0' + 26; - if(i >= NUMPERMS) + if (i >= NUMPERMS) bell(); else { pbits ^= (1 << i); @@ -178,57 +189,60 @@ unsigned int setperms(unsigned int pbits, char *pstring[]) { } /* ¦Û°Ê³]¥ßºëµØ°Ï */ -void setup_man(boardheader_t * board) { - char genbuf[200]; - +void +setup_man(boardheader_t * board) +{ + char genbuf[200]; + setapath(genbuf, board->brdname); mkdir(genbuf, 0755); } -int m_mod_board(char *bname) { - boardheader_t bh, newbh; - int bid; - char genbuf[256], ans[4]; - +int +m_mod_board(char *bname) +{ + boardheader_t bh, newbh; + int bid; + char genbuf[256], ans[4]; + bid = getbnum(bname); - if(!bid || !bname[0] || get_record(fn_board, &bh, sizeof(bh), bid) == -1) { + if (!bid || !bname[0] || get_record(fn_board, &bh, sizeof(bh), bid) == -1) { outs(err_bid); pressanykey(); return -1; } - prints("¬ÝªO¦WºÙ¡G%s\n¬ÝªO»¡©ú¡G%s\n¬ÝªObid¡G%d\n¬ÝªOGID¡G%d\n" "ªO¥D¦W³æ¡G%s", bh.brdname, bh.title, bid, bh.gid, bh.BM); bperm_msg(&bh); - + /* Ptt ³oÃäÂ_¦æ·|Àɨì¤U± */ move(9, 0); sprintf(genbuf, "(E)³]©w (V)¹Hªk/¸Ñ°£ %s (D)§R°£ [Q]¨ú®ø¡H", HAS_PERM(PERM_SYSOP) ? " (B)BVote (S)±Ï¦^¤å³¹ (G)½ä½L¸Ñ¥d" : ""); getdata(10, 0, genbuf, ans, sizeof(ans), LCECHO); - - switch(*ans) { + + switch (*ans) { case 'g': - if(HAS_PERM(PERM_SYSOP) ) { - char path[256]; - setbfile(genbuf,bname,FN_TICKET_LOCK); - setbfile(path,bname,FN_TICKET_END); - rename(genbuf,path); - } - break; + if (HAS_PERM(PERM_SYSOP)) { + char path[256]; + setbfile(genbuf, bname, FN_TICKET_LOCK); + setbfile(path, bname, FN_TICKET_END); + rename(genbuf, path); + } + break; case 's': - if(HAS_PERM(PERM_SYSOP) ) { + if (HAS_PERM(PERM_SYSOP)) { sprintf(genbuf, BBSHOME "/bin/buildir boards/%c/%s &", bh.brdname[0], bh.brdname); system(genbuf); } break; case 'b': - if(HAS_PERM(PERM_SYSOP)) { - char bvotebuf[10]; - + if (HAS_PERM(PERM_SYSOP)) { + char bvotebuf[10]; + memcpy(&newbh, &bh, sizeof(bh)); sprintf(bvotebuf, "%d", newbh.bvote); move(20, 0); @@ -246,8 +260,8 @@ int m_mod_board(char *bname) { outs("¬ÝªO¥Ø«e¬°"); outs((bh.brdattr & BRD_BAD) ? "¹Hªk" : "¥¿±`"); getdata(21, 0, "½T©w§ó§ï¡H", genbuf, 5, LCECHO); - if(genbuf[0] == 'y') { - if(newbh.brdattr & BRD_BAD) + if (genbuf[0] == 'y') { + if (newbh.brdattr & BRD_BAD) newbh.brdattr = newbh.brdattr & (!BRD_BAD); else newbh.brdattr = newbh.brdattr | BRD_BAD; @@ -257,87 +271,85 @@ int m_mod_board(char *bname) { } break; case 'd': - getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); - if(genbuf[0] != 'y' || !bname[0]) - outs(MSG_DEL_CANCEL); - else { - strcpy(bname, bh.brdname); - sprintf(genbuf, - "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" - "/bin/rm -fr boards/%c/%s man/boards/%c/%s", - bname, bname[0], bname, bname[0], - bname, bname[0], bname, bname[0], bname); - system(genbuf); - memset(&bh, 0, sizeof(bh)); - sprintf(bh.title, "%s ¬ÝªO %s §R°£", bname, cuser.userid); - post_msg("Security", bh.title,"½Ðª`·N§R°£ªº¦Xªk©Ê","[¨t²Î¦w¥þ§½]"); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); - log_usies("DelBoard", bh.title); - outs("§RªO§¹²¦"); - } + getdata_str(9, 0, msg_sure_ny, genbuf, 3, LCECHO, "N"); + if (genbuf[0] != 'y' || !bname[0]) + outs(MSG_DEL_CANCEL); + else { + strcpy(bname, bh.brdname); + sprintf(genbuf, + "/bin/tar zcvf tmp/board_%s.tgz boards/%c/%s man/boards/%c/%s >/dev/null 2>&1;" + "/bin/rm -fr boards/%c/%s man/boards/%c/%s", + bname, bname[0], bname, bname[0], + bname, bname[0], bname, bname[0], bname); + system(genbuf); + memset(&bh, 0, sizeof(bh)); + sprintf(bh.title, "%s ¬ÝªO %s §R°£", bname, cuser.userid); + post_msg("Security", bh.title, "½Ðª`·N§R°£ªº¦Xªk©Ê", "[¨t²Î¦w¥þ§½]"); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("DelBoard", bh.title); + outs("§RªO§¹²¦"); + } break; case 'e': move(8, 0); outs("ª½±µ«ö [Return] ¤£×§ï¸Ó¶µ³]©w"); memcpy(&newbh, &bh, sizeof(bh)); - while(getdata(9, 0, "·s¬ÝªO¦WºÙ¡G", genbuf, IDLEN + 1, DOECHO)) { - if(getbnum(genbuf)) { + while (getdata(9, 0, "·s¬ÝªO¦WºÙ¡G", genbuf, IDLEN + 1, DOECHO)) { + if (getbnum(genbuf)) { move(3, 0); outs("¿ù»~! ªO¦W¹p¦P"); - } else if(!invalid_brdname(genbuf)) { + } else if (!invalid_brdname(genbuf)) { strcpy(newbh.brdname, genbuf); break; } } - + do { getdata_str(12, 0, "¬ÝªOÃþ§O¡G", genbuf, 5, DOECHO, bh.title); - if(strlen(genbuf) == 4) + if (strlen(genbuf) == 4) break; } while (1); - if(strlen(genbuf) >= 4) + if (strlen(genbuf) >= 4) strncpy(newbh.title, genbuf, 4); - + newbh.title[4] = ' '; - getdata_str(14, 0, "¬ÝªO¥DÃD¡G", genbuf, BTLEN + 1, DOECHO, + getdata_str(14, 0, "¬ÝªO¥DÃD¡G", genbuf, BTLEN + 1, DOECHO, bh.title + 7); - if(genbuf[0]) + if (genbuf[0]) strcpy(newbh.title + 7, genbuf); - if(getdata_str(15, 0, "·sªO¥D¦W³æ¡G", genbuf, IDLEN * 3 + 3, DOECHO, - bh.BM)) { + if (getdata_str(15, 0, "·sªO¥D¦W³æ¡G", genbuf, IDLEN * 3 + 3, DOECHO, + bh.BM)) { trim(genbuf); strcpy(newbh.BM, genbuf); } - - if(HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_SYSOP)) { move(1, 0); clrtobot(); newbh.brdattr = setperms(newbh.brdattr, str_permboard); move(1, 0); clrtobot(); } - - if(newbh.brdattr & BRD_GROUPBOARD) + if (newbh.brdattr & BRD_GROUPBOARD) strncpy(newbh.title + 5, "£U", 2); - else if(newbh.brdattr & BRD_NOTRAN) + else if (newbh.brdattr & BRD_NOTRAN) strncpy(newbh.title + 5, "¡·", 2); else strncpy(newbh.title + 5, "¡´", 2); - - if(HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { + + if (HAS_PERM(PERM_SYSOP) && !(newbh.brdattr & BRD_HIDE)) { getdata_str(14, 0, "³]©wŪ¼gÅv(Y/N)¡H", ans, sizeof(ans), LCECHO, "N"); - if(*ans == 'y') { + if (*ans == 'y') { getdata_str(15, 0, "¨î [R]¾\\Ū (P)µoªí¡H", ans, sizeof(ans), LCECHO, "R"); - if(*ans == 'p') + if (*ans == 'p') newbh.brdattr |= BRD_POSTMASK; else newbh.brdattr &= ~BRD_POSTMASK; - + move(1, 0); clrtobot(); bperm_msg(&newbh); @@ -345,17 +357,16 @@ int m_mod_board(char *bname) { clear(); } } - getdata_str(b_lines - 1, 0, msg_sure_ny, genbuf, 4, LCECHO, "Y"); - if((*genbuf == 'y') && memcmp(&newbh, &bh, sizeof(bh))) { - if(strcmp(bh.brdname, newbh.brdname)) { - char src[60], tar[60]; - + if ((*genbuf == 'y') && memcmp(&newbh, &bh, sizeof(bh))) { + if (strcmp(bh.brdname, newbh.brdname)) { + char src[60], tar[60]; + setbpath(src, bh.brdname); setbpath(tar, newbh.brdname); Rename(src, tar); - + setapath(src, bh.brdname); setapath(tar, newbh.brdname); Rename(src, tar); @@ -370,37 +381,41 @@ int m_mod_board(char *bname) { } /* ³]©w¬ÝªO */ -int m_board() { - char bname[32]; - +int +m_board() +{ + char bname[32]; + stand_title("¬ÝªO³]©w"); generalnamecomplete(msg_bid, bname, sizeof(bname), SHM->Bnumber, completeboard_compar, completeboard_permission, completeboard_getname); - if(!*bname) + if (!*bname) return 0; m_mod_board(bname); return 0; } /* ³]©w¨t²ÎÀÉ®× */ -int x_file() { - int aborted; - char ans[4], *fpath; - +int +x_file() +{ + int aborted; + char ans[4], *fpath; + move(b_lines - 4, 0); /* Ptt */ outs("³]©w (1)¨¥÷½T»{«H (4)postª`·N¨Æ¶µ (5)¿ù»~µn¤J°T®§ (6)µù¥U½d¨Ò (7)³q¹L½T»{³qª¾\n"); outs(" (8)email post³qª¾ (9)¨t²Î¥\\¯àºëÆF (A)¯ù¼Ó (B)¯¸ªø¦W³æ (C)email³q¹L½T»{\n"); outs(" (D)·s¨Ï¥ÎªÌ»Ýª¾ (E)¨¥÷½T»{¤èªk (F)Åwªïµe± (G)¶i¯¸µe± " #ifdef MULTI_WELCOME_LOGIN -"(X)§R°£¶i¯¸µe±" + "(X)§R°£¶i¯¸µe±" #endif -"\n"); + "\n"); getdata(b_lines - 1, 0, " (H)¬ÝªO´Á (I)¬G¶m (J)¥X¯¸µe± (K)¥Í¤é¥d (L)¸`¤é [Q]¨ú®ø¡H", ans, sizeof(ans), LCECHO); - - switch(ans[0]) { + + switch (ans[0]) { case '1': fpath = "etc/confirm"; break; @@ -443,11 +458,17 @@ int x_file() { case 'g': #ifdef MULTI_WELCOME_LOGIN getdata(b_lines - 1, 0, "²Ä´XÓ¶i¯¸µe±[0-4]", ans, sizeof(ans), LCECHO); - if( ans[0] == '1' ) { fpath = "etc/Welcome_login.1"; } - else if( ans[0] == '2' ){ fpath = "etc/Welcome_login.2"; } - else if( ans[0] == '3' ){ fpath = "etc/Welcome_login.3"; } - else if( ans[0] == '4' ){ fpath = "etc/Welcome_login.4"; } - else { fpath = "etc/Welcome_login.0"; } + if (ans[0] == '1') { + fpath = "etc/Welcome_login.1"; + } else if (ans[0] == '2') { + fpath = "etc/Welcome_login.2"; + } else if (ans[0] == '3') { + fpath = "etc/Welcome_login.3"; + } else if (ans[0] == '4') { + fpath = "etc/Welcome_login.4"; + } else { + fpath = "etc/Welcome_login.0"; + } #else fpath = "etc/Welcome_login"; #endif @@ -456,11 +477,21 @@ int x_file() { #ifdef MULTI_WELCOME_LOGIN case 'x': getdata(b_lines - 1, 0, "²Ä´XÓ¶i¯¸µe±[1-4]", ans, sizeof(ans), LCECHO); - if( ans[0] == '1' ) { unlink("etc/Welcome_login.1"); outs("ok"); } - else if( ans[0] == '2' ){ unlink("etc/Welcome_login.2"); outs("ok"); } - else if( ans[0] == '3' ){ unlink("etc/Welcome_login.3"); outs("ok"); } - else if( ans[0] == '4' ){ unlink("etc/Welcome_login.4"); outs("ok"); } - else {outs("©Ò«ü©wªº¶i¯¸µe±µLªk§R°£"); } + if (ans[0] == '1') { + unlink("etc/Welcome_login.1"); + outs("ok"); + } else if (ans[0] == '2') { + unlink("etc/Welcome_login.2"); + outs("ok"); + } else if (ans[0] == '3') { + unlink("etc/Welcome_login.3"); + outs("ok"); + } else if (ans[0] == '4') { + unlink("etc/Welcome_login.4"); + outs("ok"); + } else { + outs("©Ò«ü©wªº¶i¯¸µe±µLªk§R°£"); + } pressanykey(); return FULLUPDATE; @@ -491,15 +522,17 @@ int x_file() { return FULLUPDATE; } -int m_newbrd(int recover) { - boardheader_t newboard; - char ans[4]; - int bid; - char genbuf[200]; +int +m_newbrd(int recover) +{ + boardheader_t newboard; + char ans[4]; + int bid; + char genbuf[200]; stand_title("«Ø¥ß·sªO"); memset(&newboard, 0, sizeof(newboard)); - + newboard.gid = class_bid; if (newboard.gid == 0) { move(6, 0); @@ -507,46 +540,44 @@ int m_newbrd(int recover) { pressanykey(); return -1; } - do { - if(!getdata(3, 0, msg_bid, newboard.brdname, - sizeof(newboard.brdname), DOECHO)) + if (!getdata(3, 0, msg_bid, newboard.brdname, + sizeof(newboard.brdname), DOECHO)) return -1; - } while(invalid_brdname(newboard.brdname)); + } while (invalid_brdname(newboard.brdname)); do { getdata(6, 0, "¬ÝªOÃþ§O¡G", genbuf, 5, DOECHO); - if(strlen(genbuf) == 4) + if (strlen(genbuf) == 4) break; } while (1); - - if(strlen(genbuf) >= 4) + + if (strlen(genbuf) >= 4) strncpy(newboard.title, genbuf, 4); - + newboard.title[4] = ' '; - + getdata(8, 0, "¬ÝªO¥DÃD¡G", genbuf, BTLEN + 1, DOECHO); - if(genbuf[0]) + if (genbuf[0]) strcpy(newboard.title + 7, genbuf); setbpath(genbuf, newboard.brdname); - - if(recover) { - struct stat sb; - - if(stat(genbuf, &sb) == -1 || !(sb.st_mode & S_IFDIR)) { + + if (recover) { + struct stat sb; + + if (stat(genbuf, &sb) == -1 || !(sb.st_mode & S_IFDIR)) { outs("¦¹¬ÝªO¤w¸g¦s¦b! ½Ð¨ú¤£¦P^¤åªO¦W"); pressanykey(); return -1; } - } else if(getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1) { + } else if (getbnum(newboard.brdname) > 0 || mkdir(genbuf, 0755) == -1) { outs("¦¹¬ÝªO¤w¸g¦s¦b! ½Ð¨ú¤£¦P^¤åªO¦W"); pressanykey(); return -1; } - newboard.brdattr = BRD_NOTRAN; - - if(HAS_PERM(PERM_SYSOP)) { + + if (HAS_PERM(PERM_SYSOP)) { move(1, 0); clrtobot(); newboard.brdattr = setperms(newboard.brdattr, str_permboard); @@ -554,28 +585,28 @@ int m_newbrd(int recover) { clrtobot(); } getdata(9, 0, "¬O¬ÝªO? (N:¥Ø¿ý) (Y/n)¡G", genbuf, 3, LCECHO); - if(genbuf[0]=='n') + if (genbuf[0] == 'n') newboard.brdattr |= BRD_GROUPBOARD; - if(newboard.brdattr & BRD_GROUPBOARD) + if (newboard.brdattr & BRD_GROUPBOARD) strncpy(newboard.title + 5, "£U", 2); - else if(newboard.brdattr & BRD_NOTRAN) + else if (newboard.brdattr & BRD_NOTRAN) strncpy(newboard.title + 5, "¡·", 2); else strncpy(newboard.title + 5, "¡´", 2); - + newboard.level = 0; getdata(11, 0, "ªO¥D¦W³æ¡G", newboard.BM, sizeof(newboard.BM), DOECHO); - if(HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { + if (HAS_PERM(PERM_SYSOP) && !(newboard.brdattr & BRD_HIDE)) { getdata_str(14, 0, "³]©wŪ¼gÅv(Y/N)¡H", ans, sizeof(ans), LCECHO, "N"); - if(*ans == 'y') { + if (*ans == 'y') { getdata_str(15, 0, "¨î [R]¾\\Ū (P)µoªí¡H", ans, sizeof(ans), LCECHO, "R"); - if(*ans == 'p') + if (*ans == 'p') newboard.brdattr |= BRD_POSTMASK; else newboard.brdattr &= (~BRD_POSTMASK); - + move(1, 0); clrtobot(); bperm_msg(&newboard); @@ -583,20 +614,15 @@ int m_newbrd(int recover) { clear(); } } - - if((bid = getbnum("")) > 0) - { + if ((bid = getbnum("")) > 0) { substitute_record(fn_board, &newboard, sizeof(newboard), bid); - reset_board(bid); - } - else if(append_record(fn_board, (fileheader_t *) & newboard, - sizeof(newboard)) == -1) { + reset_board(bid); + } else if (append_record(fn_board, (fileheader_t *) & newboard, + sizeof(newboard)) == -1) { pressanykey(); return -1; - } - else - { - addbrd_touchcache(); + } else { + addbrd_touchcache(); } setup_man(&newboard); @@ -607,54 +633,51 @@ int m_newbrd(int recover) { return 0; } -static int auto_scan(char fdata[][STRLEN], char ans[]) { - int good = 0; - int count = 0; - int i; - char temp[10]; - - if(!strncmp(fdata[2], "¤p", 2) || strstr(fdata[2], "¤X") +static int +auto_scan(char fdata[][STRLEN], char ans[]) +{ + int good = 0; + int count = 0; + int i; + char temp[10]; + + if (!strncmp(fdata[2], "¤p", 2) || strstr(fdata[2], "¤X") || strstr(fdata[2], "½Ö") || strstr(fdata[2], "¤£")) { ans[0] = '0'; return 1; } - strncpy(temp, fdata[2], 2); temp[2] = '\0'; - + /* Å|¦r */ - if(!strncmp(temp, &(fdata[2][2]), 2)) { + if (!strncmp(temp, &(fdata[2][2]), 2)) { ans[0] = '0'; return 1; } - - if(strlen(fdata[2]) >= 6) { - if(strstr(fdata[2], "³¯¤ô«ó")) { + if (strlen(fdata[2]) >= 6) { + if (strstr(fdata[2], "³¯¤ô«ó")) { ans[0] = '0'; return 1; } - - if(strstr("»¯¿ú®]§õ©P§d¾G¤ý", temp)) + if (strstr("»¯¿ú®]§õ©P§d¾G¤ý", temp)) good++; - else if(strstr("§ùÃC¶ÀªL³¯©x§E¨¯¼B", temp)) + else if (strstr("§ùÃC¶ÀªL³¯©x§E¨¯¼B", temp)) good++; - else if(strstr("Ĭ¤è§d§f§õªò±i¹ùÀ³Ä¬", temp)) + else if (strstr("Ĭ¤è§d§f§õªò±i¹ùÀ³Ä¬", temp)) good++; - else if(strstr("®}ÁÂ¥Û¿c¬IÀ¹¯Îð", temp)) + else if (strstr("®}ÁÂ¥Û¿c¬IÀ¹¯Îð", temp)) good++; } - - if(!good) + if (!good) return 0; - if(!strcmp(fdata[3], fdata[4]) || - !strcmp(fdata[3], fdata[5]) || - !strcmp(fdata[4], fdata[5])) { + if (!strcmp(fdata[3], fdata[4]) || + !strcmp(fdata[3], fdata[5]) || + !strcmp(fdata[4], fdata[5])) { ans[0] = '4'; return 5; } - - if(strstr(fdata[3], "¤j")) { + if (strstr(fdata[3], "¤j")) { if (strstr(fdata[3], "¥x") || strstr(fdata[3], "²H") || strstr(fdata[3], "¥æ") || strstr(fdata[3], "¬F") || strstr(fdata[3], "²M") || strstr(fdata[3], "ĵ") || @@ -662,34 +685,32 @@ static int auto_scan(char fdata[][STRLEN], char ans[]) { strstr(fdata[3], "¤¤¥¡") || strstr(fdata[3], "¦¨") || strstr(fdata[3], "»²") || strstr(fdata[3], "ªF§d")) good++; - } else if(strstr(fdata[3], "¤k¤¤")) + } else if (strstr(fdata[3], "¤k¤¤")) good++; - - if(strstr(fdata[4], "¦a²y") || strstr(fdata[4], "¦t©z") || - strstr(fdata[4], "«H½c")) { + + if (strstr(fdata[4], "¦a²y") || strstr(fdata[4], "¦t©z") || + strstr(fdata[4], "«H½c")) { ans[0] = '2'; return 3; } - - if(strstr(fdata[4], "¥«") || strstr(fdata[4], "¿¤")) { - if(strstr(fdata[4], "¸ô") || strstr(fdata[4], "µó")) { - if(strstr(fdata[4], "¸¹")) + if (strstr(fdata[4], "¥«") || strstr(fdata[4], "¿¤")) { + if (strstr(fdata[4], "¸ô") || strstr(fdata[4], "µó")) { + if (strstr(fdata[4], "¸¹")) good++; } } - - for(i = 0; fdata[5][i]; i++) { - if(isdigit(fdata[5][i])) + for (i = 0; fdata[5][i]; i++) { + if (isdigit(fdata[5][i])) count++; } - - if(count <= 4) { + + if (count <= 4) { ans[0] = '3'; return 4; - } else if(count >= 7) + } else if (count >= 7) good++; - if(good >= 3) { + if (good >= 3) { ans[0] = 'y'; return -1; } else @@ -697,17 +718,19 @@ static int auto_scan(char fdata[][STRLEN], char ans[]) { } /* ³B²z Register Form */ -int scan_register_form(char *regfile, int automode, int neednum) { - char genbuf[200]; - static char *logfile = "register.log"; - static char *field[] = { +int +scan_register_form(char *regfile, int automode, int neednum) +{ + char genbuf[200]; + static char *logfile = "register.log"; + static char *field[] = { "uid", "ident", "name", "career", "addr", "phone", "email", NULL }; - static char *finfo[] = { + static char *finfo[] = { "±b¸¹", "¨¤ÀÃÒ¸¹", "¯u¹ê©m¦W", "ªA°È³æ¦ì", "¥Ø«e¦í§}", "³sµ¸¹q¸Ü", "¹q¤l¶l¥ó«H½c", NULL }; - static char *reason[] = { + static char *reason[] = { "¿é¤J¯u¹ê©m¦W", "¸Ô²Ó¶ñ¼g±zªº¡u¾Ç®Õ¥H¤Î¡y¬ì¨t¡z¡y¦~¯Å¡z¡v©Î¡uªA°È³æ¦ì(¸Ô²Ó¦Ü¾ºÙ)¡v", "¶ñ¼g§¹¾ãªº¦í§}¸ê®Æ (§t¿¤¥«¦WºÙ, ¥x¥_¥«½Ð§t¦æ¬F°Ï°ì¡^", @@ -716,32 +739,32 @@ int scan_register_form(char *regfile, int automode, int neednum) { "¥Î¤¤¤å¶ñ¼g¥Ó½Ð³æ", NULL }; - static char *autoid = "AutoScan"; - userec_t muser; - FILE *fn, *fout, *freg; - char fdata[7][STRLEN]; - char fname[STRLEN], buf[STRLEN]; - char ans[4], *ptr, *uid; - int n = 0, unum = 0; - int nSelf = 0, nAuto = 0; - + static char *autoid = "AutoScan"; + userec_t muser; + FILE *fn, *fout, *freg; + char fdata[7][STRLEN]; + char fname[STRLEN], buf[STRLEN]; + char ans[4], *ptr, *uid; + int n = 0, unum = 0; + int nSelf = 0, nAuto = 0; + uid = cuser.userid; sprintf(fname, "%s.tmp", regfile); move(2, 0); - if(dashf(fname)) { - if(neednum == 0) { /* ¦Û¤v¶i Admin ¨Ó¼fªº */ + if (dashf(fname)) { + if (neednum == 0) { /* ¦Û¤v¶i Admin ¨Ó¼fªº */ outs("¨ä¥L SYSOP ¤]¦b¼f®Öµù¥U¥Ó½Ð³æ"); pressanykey(); } return -1; } Rename(regfile, fname); - if((fn = fopen(fname, "r")) == NULL) { + if ((fn = fopen(fname, "r")) == NULL) { prints("¨t²Î¿ù»~¡AµLªkŪ¨úµù¥U¸ê®ÆÀÉ: %s", fname); pressanykey(); return -1; } - if(neednum) { /* ³Q±j¢¼fªº */ + if (neednum) { /* ³Q±j¢¼fªº */ move(1, 0); clrtobot(); prints("¦U¦ì¨ã¦³¯¸ªøÅvªº¤H¡Aµù¥U³æ²Ö¿n¶W¹L¤@¦Ê¥÷¤F¡A³Â·Ð±zÀ°¦£¼f %d ¥÷\n", neednum); @@ -749,13 +772,13 @@ int scan_register_form(char *regfile, int automode, int neednum) { pressanykey(); } memset(fdata, 0, sizeof(fdata)); - while(fgets(genbuf, STRLEN, fn)) { - if ((ptr = (char *) strstr(genbuf, ": "))) { + while (fgets(genbuf, STRLEN, fn)) { + if ((ptr = (char *)strstr(genbuf, ": "))) { *ptr = '\0'; - for(n = 0; field[n]; n++) { - if(strcmp(genbuf, field[n]) == 0) { + for (n = 0; field[n]; n++) { + if (strcmp(genbuf, field[n]) == 0) { strcpy(fdata[n], ptr + 2); - if((ptr = (char *) strchr(fdata[n], '\n'))) + if ((ptr = (char *)strchr(fdata[n], '\n'))) *ptr = '\0'; } } @@ -770,61 +793,60 @@ int scan_register_form(char *regfile, int automode, int neednum) { } else { neednum--; memcpy(&muser, &xuser, sizeof(muser)); - if(automode) + if (automode) uid = autoid; - - if( (!automode || !auto_scan(fdata, ans)) ) { + + if ((!automode || !auto_scan(fdata, ans))) { uid = cuser.userid; - + move(1, 0); prints("±b¸¹¦ì¸m ¡G%d\n", unum); user_display(&muser, 1); move(14, 0); prints("\033[1;32m------------- ½Ð¯¸ªøÄY®æ¼f®Ö¨Ï¥ÎªÌ¸ê®Æ¡A±zÁÙ¦³ %d ¥÷---------------\033[m\n", neednum); - for(n = 0; field[n]; n++) { - if(n >= 2 && n <= 5) + for (n = 0; field[n]; n++) { + if (n >= 2 && n <= 5) prints("%d.", n - 2); else prints(" "); prints("%-12s¡G%s\n", finfo[n], fdata[n]); } - if(muser.userlevel & PERM_LOGINOK) { + if (muser.userlevel & PERM_LOGINOK) { getdata(b_lines - 1, 0, "\033[1;32m¦¹±b¸¹¤w¸g§¹¦¨µù¥U, " - "§ó·s(Y/N/Skip)¡H\033[m[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y' && ans[0] != 's') + "§ó·s(Y/N/Skip)¡H\033[m[N] ", ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 's') ans[0] = 'd'; } else { move(b_lines - 1, 0); prints("¬O§_±µ¨ü¦¹¸ê®Æ(Y/N/Q/Del/Skip)¡H[S] "); - if( search_ulist(unum) == NULL ) + if (search_ulist(unum) == NULL) ans[0] = igetch(); else ans[0] = 's'; - if( 'A' <= ans[0] && ans[0] <= 'Z' ) + if ('A' <= ans[0] && ans[0] <= 'Z') ans[0] += 32; - if( ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && - ans[0] != 'd' && !('0' <= ans[0] && ans[0] <= '4') ) + if (ans[0] != 'y' && ans[0] != 'n' && ans[0] != 'q' && + ans[0] != 'd' && !('0' <= ans[0] && ans[0] <= '4')) ans[0] = 's'; ans[1] = 0; } nSelf++; } else nAuto++; - if(neednum > 0 && ans[0] == 'q') { + if (neednum > 0 && ans[0] == 'q') { move(2, 0); clrtobot(); prints("¨S¼f§¹¤£¯à°h¥X"); pressanykey(); ans[0] = 's'; } - - switch(ans[0]) { + switch (ans[0]) { case 'q': - if((freg = fopen(regfile, "a"))) { - for(n = 0; field[n]; n++) + if ((freg = fopen(regfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(freg, "%s: %s\n", field[n], fdata[n]); fprintf(freg, "----\n"); - while(fgets(genbuf, STRLEN, fn)) + while (fgets(genbuf, STRLEN, fn)) fputs(genbuf, freg); fclose(freg); } @@ -836,8 +858,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { case '3': case '4': case 'n': - if(ans[0] == 'n') { - for(n = 0; field[n]; n++) + if (ans[0] == 'n') { + for (n = 0; field[n]; n++) prints("%s: %s\n", finfo[n], fdata[n]); move(9, 0); prints("½Ð´£¥X°h¦^¥Ó½Ðªíì¦]¡A«ö <enter> ¨ú®ø\n"); @@ -845,33 +867,33 @@ int scan_register_form(char *regfile, int automode, int neednum) { prints("%d) ½Ð%s\n", n, reason[n]); } else buf[0] = ans[0]; - if(ans[0] != 'n' || + if (ans[0] != 'n' || getdata(10 + n, 0, "°h¦^ì¦]¡G", buf, 60, DOECHO)) - if((buf[0] - '0') >= 0 && (buf[0] - '0') < n) { - int i; - fileheader_t mhdr; - char title[128], buf1[80]; - FILE *fp; - + if ((buf[0] - '0') >= 0 && (buf[0] - '0') < n) { + int i; + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + i = buf[0] - '0'; strcpy(buf, reason[i]); sprintf(genbuf, "[°h¦^ì¦]] ½Ð%s", buf); - + sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, "[µù¥U¥¢±Ñ]", TTLEN); mhdr.filemode = 0; sethomedir(title, muser.userid); - if(append_record(title, &mhdr, sizeof(mhdr)) != -1) { + if (append_record(title, &mhdr, sizeof(mhdr)) != -1) { fp = fopen(buf1, "w"); fprintf(fp, "%s\n", genbuf); fclose(fp); } - if((fout = fopen(logfile, "a"))) { - for(n = 0; field[n]; n++) + if ((fout = fopen(logfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); - fprintf(fout, "Date: %s\n", Cdate(& now)); + fprintf(fout, "Date: %s\n", Cdate(&now)); fprintf(fout, "Rejected: %s [%s]\n----\n", uid, buf); fclose(fout); @@ -882,8 +904,8 @@ int scan_register_form(char *regfile, int automode, int neednum) { clrtobot(); prints("¨ú®ø°h¦^¦¹µù¥U¥Ó½Ðªí"); case 's': - if((freg = fopen(regfile, "a"))) { - for(n = 0; field[n]; n++) + if ((freg = fopen(regfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(freg, "%s: %s\n", field[n], fdata[n]); fprintf(freg, "----\n"); fclose(freg); @@ -901,16 +923,15 @@ int scan_register_form(char *regfile, int automode, int neednum) { sethomefile(buf, muser.userid, "justify"); log_file(buf, genbuf); passwd_update(unum, &muser); - - if((fout = fopen(logfile, "a"))) { - for(n = 0; field[n]; n++) + + if ((fout = fopen(logfile, "a"))) { + for (n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); fprintf(fout, "Date: %s\n", Cdate(&now)); fprintf(fout, "Approved: %s\n", uid); fprintf(fout, "----\n"); fclose(fout); } - sethomefile(genbuf, muser.userid, "justify.wait"); unlink(genbuf); break; @@ -926,56 +947,49 @@ int scan_register_form(char *regfile, int automode, int neednum) { move(5, 0); prints("±z¼f¤F %d ¥÷µù¥U³æ¡AAutoScan ¼f¤F %d ¥÷", nSelf, nAuto); -/** DickG: ±N¼f¤F´X¥÷ªº¬ÛÃö¸ê®Æ post ¨ì Security ªO¤W ***********/ -/* DickG: ¦]À³·sªº¯¸ªø¤W¯¸»Ý¼f®Ö¤è®×¡A¬O¬G¨S¦³¥²n¯d¤U record ¦ÓÃö±¼ - strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); - - strcpy(xboard, "Security"); - setbpath(xfpath, xboard); - stampfile(xfpath, &xfile); - strcpy(xfile.owner, "¨t²Î"); - strcpy(xfile.title, "[³ø§i] ¼f®Ö°O¿ý"); - xptr = fopen(xfpath, "w"); - fprintf(xptr, "\n®É¶¡¡G%s - %s ¼f¤F %d ¥÷µù¥U³æ\n - AutoScan ¼f¤F %d ¥÷µù¥U³æ\n - ¦@p %d ¥÷¡C", - buf, cuser.userid, nSelf, nAuto, nSelf+nAuto); - fclose(xptr); - setbdir(fname, xboard); - append_record(fname, &xfile, sizeof(xfile)); - outgo_post(&xfile, xboard); - touchbtotal(getbnum(xboard)); - cuser.numposts++; -*/ -/*********************************************/ + /** DickG: ±N¼f¤F´X¥÷ªº¬ÛÃö¸ê®Æ post ¨ì Security ªO¤W ***********/ + /* + * DickG: ¦]À³·sªº¯¸ªø¤W¯¸»Ý¼f®Ö¤è®×¡A¬O¬G¨S¦³¥²n¯d¤U record + * ime(buf, 200, "%Y/%m/%d/%H:%M", pt); + * + * strcpy(xboard, "Security"); setbpath(xfpath, xboard); stampfile(xfpath, + * &xfile); strcpy(xfile.owner, "¨t²Î"); strcpy(xfile.title, "[³ø§i] + * ¼f®Ö°O¿ý"); xptr = fopen(xfpath, "w"); fprintf(xptr, "\n®É¶¡¡G%s %s + * ¼f¤F %d ¥÷µù¥U³æ\n AutoScan ¼f¤F %d ¥÷µù¥U³æ\n ¦@p %d ¥÷¡C", buf, + * cuser.userid, nSelf, nAuto, nSelf+nAuto); fclose(xptr); setbdir(fname, + * xboard); append_record(fname, &xfile, sizeof(xfile)); + * outgo_post(&xfile, xboard); touchbtotal(getbnum(xboard)); + * cuser.numposts++; + */ + /*********************************************/ pressanykey(); return (0); } -int m_register() { - FILE *fn; - int x, y, wid, len; - char ans[4]; - char genbuf[200]; - - if((fn = fopen(fn_register, "r")) == NULL) { +int +m_register() +{ + FILE *fn; + int x, y, wid, len; + char ans[4]; + char genbuf[200]; + + if ((fn = fopen(fn_register, "r")) == NULL) { outs("¥Ø«e¨ÃµL·sµù¥U¸ê®Æ"); return XEASY; } - stand_title("¼f®Ö¨Ï¥ÎªÌµù¥U¸ê®Æ"); y = 2; x = wid = 0; - - while(fgets(genbuf, STRLEN, fn) && x < 65) { - if(strncmp(genbuf, "uid: ", 5) == 0) { + + while (fgets(genbuf, STRLEN, fn) && x < 65) { + if (strncmp(genbuf, "uid: ", 5) == 0) { move(y++, x); outs(genbuf + 5); len = strlen(genbuf + 5); - if(len > wid) + if (len > wid) wid = len; - if(y >= t_lines - 3) { + if (y >= t_lines - 3) { y = 2; x += wid + 2; } @@ -983,17 +997,19 @@ int m_register() { } fclose(fn); getdata(b_lines - 1, 0, "¶}©l¼f®Ö¶Ü(Auto/Yes/No)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'a') + if (ans[0] == 'a') scan_register_form(fn_register, 1, 0); - else if(ans[0] == 'y') + else if (ans[0] == 'y') scan_register_form(fn_register, 0, 0); - + return 0; } -int cat_register() { - if(system("cat register.new.tmp >> register.new") == 0 && - system("rm -f register.new.tmp") == 0) +int +cat_register() +{ + if (system("cat register.new.tmp >> register.new") == 0 && + system("rm -f register.new.tmp") == 0) mprints(22, 0, "OK ÂP~~ Ä~Äò¥h¾Ä°«§a!! "); else mprints(22, 0, "¨S¿ìªkCAT¹L¥h©O ¥hÀˬd¤@¤U¨t²Î§a!! "); @@ -1001,93 +1017,97 @@ int cat_register() { return 0; } -static void give_id_money(char *user_id, int money, FILE *log_fp, char *mail_title, time_t t) { - char tt[TTLEN + 1] = {0}; - - if(deumoney(searchuser(user_id), money) < 0) { - move(12, 0); - clrtoeol(); - prints("id:%s money:%d ¤£¹ï§a!!", user_id, money); - pressanykey(); +static void +give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time_t t) +{ + char tt[TTLEN + 1] = {0}; + + if (deumoney(searchuser(user_id), money) < 0) { + move(12, 0); + clrtoeol(); + prints("id:%s money:%d ¤£¹ï§a!!", user_id, money); + pressanykey(); } else { - fprintf(log_fp, "%ld %s %d", t, user_id, money); - sprintf(tt, "%s : %d ptt ¹ô", mail_title, money); - mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT »È¦æ]"); + fprintf(log_fp, "%ld %s %d", t, user_id, money); + sprintf(tt, "%s : %d ptt ¹ô", mail_title, money); + mail_id(user_id, tt, "~bbs/etc/givemoney.why", "[PTT »È¦æ]"); } -} - -int give_money() { - FILE *fp, *fp2; - char *ptr, *id, *mn; - char buf[200] = {0}, tt[TTLEN + 1] = {0}; - struct tm *pt = localtime(&now); - int to_all = 0, money = 0; - +} + +int +give_money() +{ + FILE *fp, *fp2; + char *ptr, *id, *mn; + char buf[200] = {0}, tt[TTLEN + 1] = {0}; + struct tm *pt = localtime(&now); + int to_all = 0, money = 0; + getdata(0, 0, "«ü©w¨Ï¥ÎªÌ(S) ¥þ¯¸¨Ï¥ÎªÌ(A) ¨ú®ø(Q)¡H[S]", buf, sizeof(buf), LCECHO); - if(buf[0] == 'q') + if (buf[0] == 'q') return 1; - else if( buf[0] == 'a') { + else if (buf[0] == 'a') { to_all = 1; getdata(1, 0, "µo¦h¤Ö¿ú©O?", buf, 20, DOECHO); money = atoi(buf); - if(money <= 0) { + if (money <= 0) { move(2, 0); prints("¿é¤J¿ù»~!!"); pressanykey(); return 1; } } else { - if(vedit("etc/givemoney.txt", NA, NULL) < 0) + if (vedit("etc/givemoney.txt", NA, NULL) < 0) return 1; } - + clear(); getdata(0, 0, "nµo¿ú¤F¶Ü(Y/N)[N]", buf, 3, LCECHO); - if(buf[0] != 'y') + if (buf[0] != 'y') return 1; - if(!(fp2 = fopen("etc/givemoney.log", "a"))) + if (!(fp2 = fopen("etc/givemoney.log", "a"))) return 1; strftime(buf, 200, "%Y/%m/%d/%H:%M", pt); fprintf(fp2, "%s\n", buf); - + getdata(1, 0, "¬õ¥]³U¼ÐÃD ¡G", tt, TTLEN, DOECHO); move(2, 0); - + prints("½s¬õ¥]³U¤º®e"); pressanykey(); - if(vedit("etc/givemoney.why", NA, NULL) < 0) + if (vedit("etc/givemoney.why", NA, NULL) < 0) return 1; - + stand_title("µo¿ú¤¤..."); - if(to_all) { - int i, unum; - for(unum = SHM->number, i=0; i<unum; i++) { - if(bad_user_id(SHM->userid[i])) + if (to_all) { + int i, unum; + for (unum = SHM->number, i = 0; i < unum; i++) { + if (bad_user_id(SHM->userid[i])) continue; id = SHM->userid[i]; give_id_money(id, money, fp2, tt, now); } - // something wrong @_@ - //give_money_post("¥þ¯¸¨Ï¥ÎªÌ", atoi(money) ); + //something wrong @ _ @ + //give_money_post("¥þ¯¸¨Ï¥ÎªÌ", atoi(money)); } else { - if(!(fp = fopen("etc/givemoney.txt", "r+"))) { + if (!(fp = fopen("etc/givemoney.txt", "r+"))) { fclose(fp2); return 1; } - while(fgets(buf, 255, fp)) { - clear(); + while (fgets(buf, 255, fp)) { + clear(); if (!(ptr = strchr(buf, ':'))) continue; *ptr = '\0'; id = buf; mn = ptr + 1; give_id_money(id, atoi(mn), fp2, tt, now); - give_money_post(id, atoi(mn) ); + give_money_post(id, atoi(mn)); } fclose(fp); } - + fclose(fp2); pressanykey(); return FULLUPDATE; diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 5eb58ef6..3e8700bf 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -1,21 +1,23 @@ -/* $Id: announce.c,v 1.12 2002/06/19 13:20:27 lwms Exp $ */ +/* $Id: announce.c,v 1.13 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -static void g_showmenu(gmenu_t *pm) { - static char *mytype = "½s ¿ï µ·¸ô¤§®È"; - char *title, ch; - int n, max; - item_t *item; +static void +g_showmenu(gmenu_t * pm) +{ + static char *mytype = "½s ¿ï µ·¸ô¤§®È"; + char *title, ch; + int n, max; + item_t *item; showtitle("ºëµØ¤å³¹", pm->mtitle); prints(" \033[1;36m½s¸¹ ¼Ð ÃD%56s\033[m", mytype); - - if(pm->num) { + + if (pm->num) { n = pm->page; max = n + p_lines; - if(max > pm->num) + if (max > pm->num) max = pm->num; - while(n < max) { + while (n < max) { item = pm->item[n++]; title = item->title; ch = title[1]; @@ -34,35 +36,37 @@ static void g_showmenu(gmenu_t *pm) { "\033[31m(enter/¡÷)\033[30mŪ¨ú¸ê®Æ \033[m"); } -static FILE *go_cmd(item_t *node, int *sock) { +static FILE * +go_cmd(item_t * node, int *sock) +{ struct sockaddr_in sin; struct hostent *host; - char *site; - FILE *fp; - + char *site; + FILE *fp; + *sock = socket(AF_INET, SOCK_STREAM, 0); - - if(*sock < 0) { + + if (*sock < 0) { syslog(LOG_ERR, "socket(): %m"); return NULL; } memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(node->X.G.port); - + host = gethostbyname(site = node->X.G.server); - if(host == NULL) + if (host == NULL) sin.sin_addr.s_addr = inet_addr(site); else memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length); - - if(connect(*sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + + if (connect(*sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) { syslog(LOG_ERR, "connect(): %m"); return NULL; } fp = fdopen(*sock, "r+"); - if(fp != NULL) { - setbuf(fp, (char *) 0); + if (fp != NULL) { + setbuf(fp, (char *)0); fprintf(fp, "%s\r\n", node->X.G.path); fflush(fp); } else @@ -70,12 +74,14 @@ static FILE *go_cmd(item_t *node, int *sock) { return fp; } -static char *nextfield(char *data, char *field) { - register int ch; - - while((ch = *data)) { +static char * +nextfield(char *data, char *field) +{ + register int ch; + + while ((ch = *data)) { data++; - if((ch == '\t') || (ch == '\r' && *data == '\n')) + if ((ch == '\t') || (ch == '\r' && *data == '\n')) break; *field++ = ch; } @@ -83,90 +89,94 @@ static char *nextfield(char *data, char *field) { return data; } -static FILE* my_open(char* path) { - FILE* ans = 0; - char buf[80]; - struct stat st; +static FILE * +my_open(char *path) +{ + FILE *ans = 0; + char buf[80]; + struct stat st; - if(stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { + if (stat(path, &st) == 0 && st.st_mtime < now - 3600 * 24 * 7) { return fopen(path, "w"); } - - if((ans = fopen(path, "r+"))) { + if ((ans = fopen(path, "r+"))) { fclose(ans); return 0; /* - return directly due to currutmp->pager > 1 mode (real copy) - */ + * return directly due to currutmp->pager > 1 mode (real copy) + */ fgets(buf, 80, ans); - if(!strncmp(buf, str_author1, strlen(str_author1)) || - *buf == '0' || *buf == '1') { + if (!strncmp(buf, str_author1, strlen(str_author1)) || + *buf == '0' || *buf == '1') { fclose(ans); return 0; } - rewind(ans); } else ans = fopen(path, "w"); return ans; } -static jmp_buf jbuf; +static jmp_buf jbuf; -static void isig(int sig) { +static void +isig(int sig) +{ longjmp(jbuf, 1); } #define PROXY_HOME "proxy/" -static void go_proxy(char* fpath, item_t *node, int update) { - char *ptr, *str, *server; - int ch; - static FILE *fo; - +static void +go_proxy(char *fpath, item_t * node, int update) +{ + char *ptr, *str, *server; + int ch; + static FILE *fo; + strcpy(fpath, PROXY_HOME); ptr = fpath + sizeof(PROXY_HOME) - 1; str = server = node->X.G.server; - while((ch = *str)) { + while ((ch = *str)) { str++; - if(ch == '.') { - if(!strcmp(str, "edu.tw")) + if (ch == '.') { + if (!strcmp(str, "edu.tw")) break; - } else if(ch >= 'A' && ch <= 'Z') { + } else if (ch >= 'A' && ch <= 'Z') { ch |= 0x20; } *ptr++ = ch; } *ptr = '\0'; mkdir(fpath, 0755); - + *ptr++ = '/'; str = node->X.G.path; - while((ch = *str)) { + while ((ch = *str)) { str++; - if(ch == '/') { + if (ch == '/') { ch = '.'; } *ptr++ = ch; } *ptr = '\0'; - + /* expire proxy data */ - - if((fo = update ? fopen(fpath, "w") : my_open(fpath))) { - FILE *fp; - char buf[512]; - int sock; - - if(fo == NULL) + + if ((fo = update ? fopen(fpath, "w") : my_open(fpath))) { + FILE *fp; + char buf[512]; + int sock; + + if (fo == NULL) return; - + outmsg("¡¹ «Ø¥ß proxy ¸ê®Æ³s½u¤¤ ... "); refresh(); - + sock = -1; - if(setjmp(jbuf)) { - if(sock != -1) + if (setjmp(jbuf)) { + if (sock != -1) close(sock); fseek(fo, 0, SEEK_SET); fwrite("", 0, 0, fo); @@ -174,7 +184,6 @@ static void go_proxy(char* fpath, item_t *node, int update) { alarm(0); return; } - signal(SIGALRM, isig); alarm(5); fp = go_cmd(node, &sock); @@ -182,17 +191,16 @@ static void go_proxy(char* fpath, item_t *node, int update) { str = node->title; ch = str[1]; - if(ch == (char) 0xbc && - !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { + if (ch == (char)0xbc && + !(HAS_PERM(PERM_SYSOP) && currutmp->pager > 1)) { fprintf(fo, "§@ªÌ: %s (³s½uºëµØ°Ï)\n¼ÐÃD: %s\n®É¶¡: %s\n", server, str + 3, ctime(&now) ); } - - while(fgets(buf, 511, fp)) { - if(!strcmp(buf, ".\r\n")) + while (fgets(buf, 511, fp)) { + if (!strcmp(buf, ".\r\n")) break; - if((ptr = strstr(buf, "\r\n"))) + if ((ptr = strstr(buf, "\r\n"))) strcpy(ptr, "\n"); fputs(buf, fo); } @@ -201,46 +209,50 @@ static void go_proxy(char* fpath, item_t *node, int update) { } } -static void g_additem(gmenu_t *pm, item_t *myitem) { - if(pm->num < MAX_ITEMS) { - item_t *newitem = (item_t *)malloc(sizeof(item_t)); - +static void +g_additem(gmenu_t * pm, item_t * myitem) +{ + if (pm->num < MAX_ITEMS) { + item_t *newitem = (item_t *) malloc(sizeof(item_t)); + memcpy(newitem, myitem, sizeof(item_t)); pm->item[(pm->num)++] = newitem; } } -static void go_menu(gmenu_t *pm, item_t *node, int update) { - FILE *fp; - char buf[512], *ptr, *title; - item_t item; - int ch; - +static void +go_menu(gmenu_t * pm, item_t * node, int update) +{ + FILE *fp; + char buf[512], *ptr, *title; + item_t item; + int ch; + go_proxy(buf, node, update); pm->num = 0; - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { title = item.title; - while(fgets(buf, 511, fp)) { + while (fgets(buf, 511, fp)) { ptr = buf; ch = *ptr++; - if(ch != '0' && ch != '1') + if (ch != '0' && ch != '1') continue; - + strcpy(title, "¡¼ "); - if(ch == '1') - title[1] = (char) 0xbd; + if (ch == '1') + title[1] = (char)0xbd; ptr = nextfield(ptr, title + 3); - if(!*ptr) + if (!*ptr) continue; title[sizeof(item.title) - 1] = '\0'; ptr = nextfield(ptr, item.X.G.path); - if(!*ptr) + if (!*ptr) continue; ptr = nextfield(ptr, item.X.G.server); - if(!*ptr) + if (!*ptr) continue; nextfield(ptr, buf); @@ -252,12 +264,14 @@ static void go_menu(gmenu_t *pm, item_t *node, int update) { } } -static int g_searchtitle(gmenu_t* pm, int rev) { - static char search_str[30] = ""; - int pos; - - if(getdata(b_lines - 1, 1,"[·j´M]ÃöÁä¦r:", search_str, sizeof(search_str), DOECHO)) - if(!*search_str) +static int +g_searchtitle(gmenu_t * pm, int rev) +{ + static char search_str[30] = ""; + int pos; + + if (getdata(b_lines - 1, 1, "[·j´M]ÃöÁä¦r:", search_str, sizeof(search_str), DOECHO)) + if (!*search_str) return pm->now; str_lower(search_str, search_str); @@ -266,17 +280,19 @@ static int g_searchtitle(gmenu_t* pm, int rev) { pos = pm->now; do { pos += rev; - if(pos == pm->num) + if (pos == pm->num) pos = 0; - else if(pos < 0) + else if (pos < 0) pos = pm->num - 1; - if(strstr_lower(pm->item[pos]->title, search_str)) + if (strstr_lower(pm->item[pos]->title, search_str)) return pos; - } while(pos != pm->now); + } while (pos != pm->now); return pm->now; } -static void g_showhelp() { +static void +g_showhelp() +{ clear(); outs("\033[36m¡i " BBSNAME "³s½uºëµØ°Ï¨Ï¥Î»¡©ú ¡j\033[m\n\n" "[¡ö][q] Â÷¶}¨ì¤W¤@¼h¥Ø¿ý\n" @@ -296,24 +312,26 @@ static void g_showhelp() { #define PATHLEN 256 -static char paste_fname[200]; +static char paste_fname[200]; -static void load_paste() { - struct stat st; - FILE *fp; - - if(!*paste_fname) +static void +load_paste() +{ + struct stat st; + FILE *fp; + + if (!*paste_fname) setuserfile(paste_fname, "paste_path"); - if(stat(paste_fname, &st) == 0 && st.st_mtime > paste_time && - (fp = fopen(paste_fname, "r"))) { - int i; + if (stat(paste_fname, &st) == 0 && st.st_mtime > paste_time && + (fp = fopen(paste_fname, "r"))) { + int i; fgets(paste_path, PATHLEN, fp); i = strlen(paste_path) - 1; - if(paste_path[i] == '\n') + if (paste_path[i] == '\n') paste_path[i] = 0; fgets(paste_title, STRLEN, fp); i = strlen(paste_title) - 1; - if(paste_title[i] == '\n') + if (paste_title[i] == '\n') paste_title[i] = 0; fscanf(fp, "%d", &paste_level); paste_time = st.st_mtime; @@ -321,18 +339,20 @@ static void load_paste() { } } -static char copyfile[PATHLEN]; -static char copytitle[TTLEN+1]; -static char copyowner[IDLEN + 2]; +static char copyfile[PATHLEN]; +static char copytitle[TTLEN + 1]; +static char copyowner[IDLEN + 2]; -void a_copyitem(char* fpath, char* title, char* owner, int mode) { +void +a_copyitem(char *fpath, char *title, char *owner, int mode) +{ strcpy(copyfile, fpath); strcpy(copytitle, title); - if(owner) + if (owner) strcpy(copyowner, owner); else *copyowner = 0; - if(mode) { + if (mode) { outmsg("Àɮ׼аO§¹¦¨¡C[ª`·N] «þ¨©«á¤~¯à§R°£ì¤å!"); igetch(); } @@ -340,50 +360,56 @@ void a_copyitem(char* fpath, char* title, char* owner, int mode) { #define FHSZ sizeof(fileheader_t) -static void a_loadname(menu_t *pm) { - char buf[PATHLEN]; - int len; - +static void +a_loadname(menu_t * pm) +{ + char buf[PATHLEN]; + int len; + setadir(buf, pm->path); - len = get_records(buf, pm->header, FHSZ, pm->page+1, p_lines); - if(len < p_lines) - bzero(&pm->header[len], FHSZ*(p_lines-len)); + len = get_records(buf, pm->header, FHSZ, pm->page + 1, p_lines); + if (len < p_lines) + bzero(&pm->header[len], FHSZ * (p_lines - len)); } -static void a_timestamp(char *buf, time_t *time) { - struct tm *pt = localtime(time); - +static void +a_timestamp(char *buf, time_t * time) +{ + struct tm *pt = localtime(time); + sprintf(buf, "%02d/%02d/%02d", pt->tm_mon + 1, pt->tm_mday, (pt->tm_year + 1900) % 100); } -static void a_showmenu(menu_t *pm) { - char *title, *editor; - int n; - fileheader_t *item; - char buf[PATHLEN]; - time_t dtime; +static void +a_showmenu(menu_t * pm) +{ + char *title, *editor; + int n; + fileheader_t *item; + char buf[PATHLEN]; + time_t dtime; showtitle("ºëµØ¤å³¹", pm->mtitle); prints(" \033[1;36m½s¸¹ ¼Ð ÃD%56s\033[0m", "½s ¿ï ¤é ´Á"); - if(pm->num) { + if (pm->num) { setadir(buf, pm->path); a_loadname(pm); - for(n = 0; n < p_lines && pm->page + n < pm->num; n++) { + for (n = 0; n < p_lines && pm->page + n < pm->num; n++) { item = &pm->header[n]; title = item->title; editor = item->owner; - /* Ptt §â®É¶¡§ï¬°¨úÀɮ׮ɶ¡ - dtime = atoi(&item->filename[2]); - */ - sprintf(buf,"%s/%s",pm->path,item->filename); + /* + * Ptt §â®É¶¡§ï¬°¨úÀɮ׮ɶ¡ dtime = atoi(&item->filename[2]); + */ + sprintf(buf, "%s/%s", pm->path, item->filename); dtime = dasht(buf); a_timestamp(buf, &dtime); - prints("\n%6d%c %-47.46s%-13s[%s]", pm->page+n+1, - (item->filemode & FILE_BM) ?'X': - (item->filemode & FILE_HIDE) ?')':'.', - title, editor, + prints("\n%6d%c %-47.46s%-13s[%s]", pm->page + n + 1, + (item->filemode & FILE_BM) ? 'X' : + (item->filemode & FILE_HIDE) ? ')' : '.', + title, editor, buf); } } else @@ -399,38 +425,44 @@ static void a_showmenu(menu_t *pm) { "\033[31m(enter/¡÷)\033[30mŪ¨ú¸ê®Æ \033[m"); } -static int a_searchtitle(menu_t *pm, int rev) { - static char search_str[40] = ""; - int pos; - +static int +a_searchtitle(menu_t * pm, int rev) +{ + static char search_str[40] = ""; + int pos; + getdata(b_lines - 1, 1, "[·j´M]ÃöÁä¦r:", search_str, sizeof(search_str), DOECHO); - - if(!*search_str) + + if (!*search_str) return pm->now; - + str_lower(search_str, search_str); - + rev = rev ? -1 : 1; pos = pm->now; do { pos += rev; - if(pos == pm->num) + if (pos == pm->num) pos = 0; - else if(pos < 0) + else if (pos < 0) pos = pm->num - 1; - if(pos < pm->page || pos >= pm->page + p_lines) { + if (pos < pm->page || pos >= pm->page + p_lines) { pm->page = pos - pos % p_lines; a_loadname(pm); } - if(strstr_lower(pm->header[pos - pm->page].title, search_str)) + if (strstr_lower(pm->header[pos - pm->page].title, search_str)) return pos; - } while(pos != pm->now); + } while (pos != pm->now); return pm->now; } -enum {NOBODY, MANAGER, SYSOP}; +enum { + NOBODY, MANAGER, SYSOP +}; -static void a_showhelp(int level) { +static void +a_showhelp(int level) +{ clear(); outs("\033[36m¡i " BBSNAME "¤½§GÄæ¨Ï¥Î»¡©ú ¡j\033[m\n\n" "[¡ö][q] Â÷¶}¨ì¤W¤@¼h¥Ø¿ý\n" @@ -442,17 +474,16 @@ static void a_showhelp(int level) { "[##] ²¾¨ì¸Ó¿ï¶µ\n" "[F][U] ±N¤å³¹±H¦^ Internet ¶l½c/" "±N¤å³¹ uuencode «á±H¦^¶l½c\n"); - if(level >= MANAGER) { + if (level >= MANAGER) { outs("\n\033[36m¡i ªO¥D±M¥ÎÁä ¡j\033[m\n" - "[H] ¤Á´«¬° ¤½¶}/·|û/ªO¥D ¤~¯à¾\\Ū\n" + "[H] ¤Á´«¬° ¤½¶}/·|û/ªO¥D ¤~¯à¾\\Ū\n" "[n/g/G] ¦¬¿ýºëµØ¤å³¹/¶}ÅP¥Ø¿ý/«Ø¥ß³s½u\n" "[m/d/D] ²¾°Ê/§R°£¤å³¹/§R°£¤@Ó½d³òªº¤å³¹\n" "[f/T/e] ½s¿è¼ÐÃD²Å¸¹/קï¤å³¹¼ÐÃD/¤º®e\n" "[c/p/a] «þ¨©/Ö߶K/ªþ¥[¤å³¹\n" "[^P/^A] Ö߶K/ªþ¥[¤w¥Î't'¼Ð°O¤å³¹\n"); } - - if(level >= SYSOP) { + if (level >= SYSOP) { outs("\n\033[36m¡i ¯¸ªø±M¥ÎÁä ¡j\033[m\n" "[l] «Ø symbolic link\n" "[N] ¬d¸ßÀɦW\n"); @@ -460,11 +491,13 @@ static void a_showhelp(int level) { pressanykey(); } -static int AnnounceSelect() { - static char xboard[20]; - char buf[20]; - char fpath[256]; - boardheader_t *bp; +static int +AnnounceSelect() +{ + static char xboard[20]; + char buf[20]; + char fpath[256]; + boardheader_t *bp; move(2, 0); clrtoeol(); @@ -476,9 +509,9 @@ static int AnnounceSelect() { completeboard_compar, completeboard_permission, completeboard_getname); - if(*buf) + if (*buf) strcpy(xboard, buf); - if(*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, @@ -488,57 +521,58 @@ static int AnnounceSelect() { return FULLUPDATE; } -void gem(char* maintitle, item_t* path, int update) { - gmenu_t me; - int ch; - char fname[PATHLEN]; - +void +gem(char *maintitle, item_t * path, int update) +{ + gmenu_t me; + int ch; + char fname[PATHLEN]; + strncpy(me.mtitle, maintitle, 40); me.mtitle[40] = 0; go_menu(&me, path, update); - + /* ºëµØ°Ï-tree ¤¤³¡¥÷µ²ºcÄÝ©ó cuser ==> BM */ - + me.level = 0; me.page = 9999; me.now = 0; - for(;;) { - if(me.now >= me.num && me.num > 0) + for (;;) { + if (me.now >= me.num && me.num > 0) me.now = me.num - 1; - else if(me.now < 0) + else if (me.now < 0) me.now = 0; - - if(me.now < me.page || me.now >= me.page + p_lines) { + + if (me.now < me.page || me.now >= me.page + p_lines) { me.page = me.now - (me.now % p_lines); g_showmenu(&me); } ch = cursor_key(2 + me.now - me.page, 0); - if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT) break; - - if(ch >= '0' && ch <= '9') { - if((ch = search_num(ch, me.num)) != -1) + + if (ch >= '0' && ch <= '9') { + if ((ch = search_num(ch, me.num)) != -1) me.now = ch; me.page = 9999; continue; } - - switch(ch) { + switch (ch) { case KEY_UP: case 'k': - if(--me.now < 0) + if (--me.now < 0) me.now = me.num - 1; break; case KEY_DOWN: case 'j': - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; case KEY_PGUP: case 'b': - if(me.now >= p_lines) + if (me.now >= p_lines) me.now -= p_lines; - else if(me.now > 0) + else if (me.now > 0) me.now = 0; else me.now = me.num - 1; @@ -546,9 +580,9 @@ void gem(char* maintitle, item_t* path, int update) { case ' ': case KEY_PGDN: case Ctrl('F'): - if(me.now < me.num - p_lines) + if (me.now < me.num - p_lines) me.now += p_lines; - else if(me.now < me.num - 1) + else if (me.now < me.num - 1) me.now = me.num - 1; else me.now = 0; @@ -563,7 +597,7 @@ void gem(char* maintitle, item_t* path, int update) { me.page = 9999; break; case 'N': - if(HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_SYSOP)) { go_proxy(fname, me.item[me.now], 0); move(b_lines - 1, 0); outs(fname); @@ -574,21 +608,21 @@ void gem(char* maintitle, item_t* path, int update) { case 'c': case 'C': case Ctrl('C'): - if(me.now < me.num) { - item_t *node = me.item[me.now]; - char *title = node->title; - int mode = title[1]; + if (me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; load_paste(); - if(mode == (char) 0xbc || ch == Ctrl('C')) { - if(mode == (char) 0xbc) + if (mode == (char)0xbc || ch == Ctrl('C')) { + if (mode == (char)0xbc) go_proxy(fname, node, 0); - if(ch == Ctrl('C') && *paste_path && paste_level) { - char newpath[PATHLEN]; - fileheader_t item; + if (ch == Ctrl('C') && *paste_path && paste_level) { + char newpath[PATHLEN]; + fileheader_t item; strcpy(newpath, paste_path); - if(mode == (char) 0xbc) { + if (mode == (char)0xbc) { stampfile(newpath, &item); unlink(newpath); Link(fname, newpath); @@ -597,19 +631,19 @@ void gem(char* maintitle, item_t* path, int update) { strcpy(item.owner, cuser.userid); sprintf(item.title, "%s%.72s", (currutmp->pager > 1) ? "" : - (mode == (char) 0xbc) ? "¡º " : "¡» ", + (mode == (char)0xbc) ? "¡º " : "¡» ", title + 3); strcpy(strrchr(newpath, '/') + 1, ".DIR"); append_record(newpath, &item, FHSZ); - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; } - if(mode == (char) 0xbc) { + if (mode == (char)0xbc) { a_copyitem(fname, title + ((currutmp->pager > 1) ? 3 : 0), 0, 1); - if(ch == 'C' && *paste_path) { + if (ch == 'C' && *paste_path) { setutmpmode(ANNOUNCE); a_menu(paste_title, paste_path, paste_level); } @@ -636,39 +670,39 @@ void gem(char* maintitle, item_t* path, int update) { case KEY_RIGHT: case 'r': case 'R': - if(me.now < me.num) { - item_t *node = me.item[me.now]; - char *title = node->title; - int mode = title[1]; - int update = (ch == 'R') ? 1 : 0; + if (me.now < me.num) { + item_t *node = me.item[me.now]; + char *title = node->title; + int mode = title[1]; + int update = (ch == 'R') ? 1 : 0; title += 3; - if(mode == (char) 0xbc) { - int more_result; + if (mode == (char)0xbc) { + int more_result; go_proxy(fname, node, update); strcpy(vetitle, title); - while((more_result = more(fname, YEA))) { - if(more_result == 1) { - if(--me.now < 0) { + while ((more_result = more(fname, YEA))) { + if (more_result == 1) { + if (--me.now < 0) { me.now = 0; break; } - } else if(more_result == 3) { - if(++me.now >= me.num) { + } else if (more_result == 3) { + if (++me.now >= me.num) { me.now = me.num - 1; break; } } else break; node = me.item[me.now]; - if(node->title[1] != (char) 0xbc) + if (node->title[1] != (char)0xbc) break; go_proxy(fname, node, update); strcpy(vetitle, title); } - } else if(mode == (char) 0xbd) { + } else if (mode == (char)0xbd) { gem(title, node, update); } me.page = 9999; @@ -676,16 +710,18 @@ void gem(char* maintitle, item_t* path, int update) { break; } } - for(ch = 0; ch < me.num; ch++) + for (ch = 0; ch < me.num; ch++) free(me.item[ch]); } -static void a_forward(char *path, fileheader_t *pitem, int mode) { - fileheader_t fhdr; - +static void +a_forward(char *path, fileheader_t * pitem, int mode) +{ + fileheader_t fhdr; + strcpy(fhdr.filename, pitem->filename); strcpy(fhdr.title, pitem->title); - switch(doforward(path, &fhdr, mode)) { + switch (doforward(path, &fhdr, mode)) { case 0: outmsg(msg_fwd_ok); break; @@ -698,20 +734,21 @@ static void a_forward(char *path, fileheader_t *pitem, int mode) { } } -static void a_additem(menu_t *pm, fileheader_t *myheader) { - char buf[PATHLEN]; - +static void +a_additem(menu_t * pm, fileheader_t * myheader) +{ + char buf[PATHLEN]; + setadir(buf, pm->path); - if(append_record(buf, myheader, FHSZ) == -1) + if (append_record(buf, myheader, FHSZ) == -1) return; pm->now = pm->num++; - - if(pm->now >= pm->page + p_lines) { + + if (pm->now >= pm->page + p_lines) { pm->page = pm->now - ((pm->page == 10000 && pm->now > p_lines / 2) ? (p_lines / 2) : (pm->now % p_lines)); - } - - /*Ptt*/ + } + /* Ptt */ strcpy(pm->header[pm->now - pm->page].filename, myheader->filename); } @@ -720,80 +757,81 @@ static void a_additem(menu_t *pm, fileheader_t *myheader) { #define ADDGOPHER 2 #define ADDLINK 3 -static void a_newitem(menu_t *pm, int mode) { - static char *mesg[4] = { - "[·s¼W¤å³¹] ½Ð¿é¤J¼ÐÃD¡G", /* ADDITEM */ - "[·s¼W¥Ø¿ý] ½Ð¿é¤J¼ÐÃD¡G", /* ADDGROUP */ - "[·s¼W³s½u] ½Ð¿é¤J¼ÐÃD¡G", /* ADDGOPHER */ - "½Ð¿é¤J¼ÐÃD¡G" /* ADDLINK */ +static void +a_newitem(menu_t * pm, int mode) +{ + static char *mesg[4] = { + "[·s¼W¤å³¹] ½Ð¿é¤J¼ÐÃD¡G", /* ADDITEM */ + "[·s¼W¥Ø¿ý] ½Ð¿é¤J¼ÐÃD¡G", /* ADDGROUP */ + "[·s¼W³s½u] ½Ð¿é¤J¼ÐÃD¡G", /* ADDGOPHER */ + "½Ð¿é¤J¼ÐÃD¡G" /* ADDLINK */ }; - char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN]; - fileheader_t item; - int d; + char fpath[PATHLEN], buf[PATHLEN], lpath[PATHLEN]; + fileheader_t item; + int d; strcpy(fpath, pm->path); - switch(mode) { + switch (mode) { case ADDITEM: stampfile(fpath, &item); - strcpy(item.title, "¡º "); /* A1BA */ + strcpy(item.title, "¡º "); /* A1BA */ break; - + case ADDGROUP: stampdir(fpath, &item); - strcpy(item.title, "¡» "); /* A1BB */ + strcpy(item.title, "¡» "); /* A1BB */ break; case ADDGOPHER: bzero(&item, sizeof(item)); - strcpy(item.title, "¡ó "); /* A1BB */ - if(!getdata(b_lines - 2, 1, "¿é¤JURL¦ì§}¡G", - item.filename+2,61, DOECHO)) + strcpy(item.title, "¡ó "); /* A1BB */ + if (!getdata(b_lines - 2, 1, "¿é¤JURL¦ì§}¡G", + item.filename + 2, 61, DOECHO)) return; break; case ADDLINK: stamplink(fpath, &item); if (!getdata(b_lines - 2, 1, "·s¼W³s½u¡G", buf, 61, DOECHO)) return; - if(invalid_pname(buf)) { + if (invalid_pname(buf)) { unlink(fpath); outs("¥Øªº¦a¸ô®|¤£¦Xªk¡I"); igetch(); return; } - item.title[0] = 0; - for(d = 0; d <= 3; d++) { - switch(d) { + for (d = 0; d <= 3; d++) { + switch (d) { case 0: sprintf(lpath, BBSHOME "/man/boards/%c/%s/%s", currboard[0], currboard, buf); break; case 1: sprintf(lpath, "%s%s/%c/%s", - BBSHOME, "/man/boards/" , buf[0], buf); + BBSHOME, "/man/boards/", buf[0], buf); break; case 2: sprintf(lpath, "%s%s%s", - BBSHOME, "/" , buf); + BBSHOME, "/", buf); break; case 3: sprintf(lpath, "%s%s%s", - BBSHOME, "/etc/" , buf); + BBSHOME, "/etc/", buf); break; } - if(dashf(lpath)) { - strcpy(item.title, "¡¸ "); /* A1B3 */ + if (dashf(lpath)) { + strcpy(item.title, "¡¸ "); /* A1B3 */ break; } else if (dashd(lpath)) { - strcpy(item.title, "¡¹ "); /* A1B4 */ + strcpy(item.title, "¡¹ "); /* A1B4 */ break; } - if(!HAS_PERM(PERM_BBSADM) && d==1) + if (!HAS_PERM(PERM_BBSADM) && d == 1) break; } - - if(!item.title[0]) { + + if (!item.title[0]) { unlink(fpath); outs("¥Øªº¦a¸ô®|¤£¦Xªk¡I"); igetch(); @@ -801,17 +839,16 @@ static void a_newitem(menu_t *pm, int mode) { } } - if(!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { - if(mode == ADDGROUP) + if (!getdata(b_lines - 1, 1, mesg[mode], &item.title[3], 55, DOECHO)) { + if (mode == ADDGROUP) rmdir(fpath); - else if(mode != ADDGOPHER) + else if (mode != ADDGOPHER) unlink(fpath); return; } - - switch(mode) { + switch (mode) { case ADDITEM: - if(vedit(fpath, 0, NULL) == -1) { + if (vedit(fpath, 0, NULL) == -1) { unlink(fpath); pressanykey(); return; @@ -819,7 +856,7 @@ static void a_newitem(menu_t *pm, int mode) { break; case ADDLINK: unlink(fpath); - if(symlink(lpath, fpath) == -1) { + if (symlink(lpath, fpath) == -1) { outs("µLªk«Ø¥ß symbolic link"); igetch(); return; @@ -827,7 +864,7 @@ static void a_newitem(menu_t *pm, int mode) { break; case ADDGOPHER: strcpy(item.date, "70"); - strncpy(item.filename, "H.",2); + strncpy(item.filename, "H.", 2); break; } @@ -835,54 +872,56 @@ static void a_newitem(menu_t *pm, int mode) { a_additem(pm, &item); } -static void a_pasteitem(menu_t *pm, int mode) { - char newpath[PATHLEN]; - char buf[PATHLEN]; - char ans[2]; - int i; - fileheader_t item; +static void +a_pasteitem(menu_t * pm, int mode) +{ + char newpath[PATHLEN]; + char buf[PATHLEN]; + char ans[2]; + int i; + fileheader_t item; move(b_lines - 1, 1); - if(copyfile[0]) { - if(dashd(copyfile)) { - for(i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); - if(!copyfile[i]) { + if (copyfile[0]) { + if (dashd(copyfile)) { + for (i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); + if (!copyfile[i]) { outs("±N¥Ø¿ý«þ¶i¦Û¤vªº¤l¥Ø¿ý¤¤¡A·|³y¦¨µL½a°j°é¡I"); igetch(); return; } } - if(mode) { + if (mode) { sprintf(buf, "½T©wn«þ¨©[%s]¶Ü(Y/N)¡H[N] ", copytitle); getdata(b_lines - 1, 1, buf, ans, sizeof(ans), LCECHO); } else - ans[0]='y'; - if(ans[0] == 'y') { + ans[0] = 'y'; + if (ans[0] == 'y') { strcpy(newpath, pm->path); - if(*copyowner) { - char* fname = strrchr(copyfile, '/'); + if (*copyowner) { + char *fname = strrchr(copyfile, '/'); - if(fname) + if (fname) strcat(newpath, fname); else return; - if(access(pm->path, X_OK | R_OK | W_OK)) + if (access(pm->path, X_OK | R_OK | W_OK)) mkdir(pm->path, 0755); memset(&item, 0, sizeof(fileheader_t)); strcpy(item.filename, fname + 1); memcpy(copytitle, "¡·", 2); - if(HAS_PERM(PERM_BBSADM)) + if (HAS_PERM(PERM_BBSADM)) Link(copyfile, newpath); else { sprintf(buf, "/bin/cp %s %s", copyfile, newpath); system(buf); } - } else if(dashf(copyfile)) { + } else if (dashf(copyfile)) { stampfile(newpath, &item); memcpy(copytitle, "¡º", 2); sprintf(buf, "/bin/cp %s %s", copyfile, newpath); - } else if(dashd(copyfile)) { + } else if (dashd(copyfile)) { stampdir(newpath, &item); memcpy(copytitle, "¡»", 2); sprintf(buf, "/bin/cp -r %s/* %s/.D* %s", copyfile, copyfile, @@ -894,7 +933,7 @@ static void a_pasteitem(menu_t *pm, int mode) { } strcpy(item.owner, *copyowner ? copyowner : cuser.userid); strcpy(item.title, copytitle); - if(!*copyowner) + if (!*copyowner) system(buf); a_additem(pm, &item); copyfile[0] = '\0'; @@ -905,36 +944,38 @@ static void a_pasteitem(menu_t *pm, int mode) { } } -static void a_appenditem(menu_t *pm, int isask) { - char fname[PATHLEN]; - char buf[ANSILINELEN]; - char ans[2] = "y"; - FILE *fp, *fin; +static void +a_appenditem(menu_t * pm, int isask) +{ + char fname[PATHLEN]; + char buf[ANSILINELEN]; + char ans[2] = "y"; + FILE *fp, *fin; move(b_lines - 1, 1); - if(copyfile[0]) { - if(dashf(copyfile)) { + if (copyfile[0]) { + if (dashf(copyfile)) { sprintf(fname, "%s/%s", pm->path, - pm->header[pm->now-pm->page].filename); - if(dashf(fname)) { - if(isask) { + pm->header[pm->now - pm->page].filename); + if (dashf(fname)) { + if (isask) { sprintf(buf, "½T©wn±N[%s]ªþ¥[©ó¦¹¶Ü(Y/N)¡H[N] ", copytitle); getdata(b_lines - 2, 1, buf, ans, sizeof(ans), LCECHO); } - if(ans[0] == 'y') { - if((fp = fopen(fname, "a+"))) { - if((fin = fopen(copyfile, "r"))) { + if (ans[0] == 'y') { + if ((fp = fopen(fname, "a+"))) { + if ((fin = fopen(copyfile, "r"))) { memset(buf, '-', 74); buf[74] = '\0'; fprintf(fp, "\n> %s <\n\n", buf); - if(isask) + if (isask) getdata(b_lines - 1, 1, "¬O§_¦¬¿ýñ¦WÀɳ¡¥÷(Y/N)¡H[Y] ", ans, sizeof(ans), LCECHO); - while(fgets(buf, sizeof(buf), fin)) { - if((ans[0] == 'n' ) && - !strcmp(buf, "--\n")) + while (fgets(buf, sizeof(buf), fin)) { + if ((ans[0] == 'n') && + !strcmp(buf, "--\n")) break; fputs(buf, fp); } @@ -958,56 +999,57 @@ static void a_appenditem(menu_t *pm, int isask) { } } -static int a_pastetagpost(menu_t *pm, int mode) { - fileheader_t fhdr; - int ans = 0, ent=0, tagnum; - char title[TTLEN + 1]= "¡º "; - char dirname[200],buf[200]; +static int +a_pastetagpost(menu_t * pm, int mode) +{ + fileheader_t fhdr; + int ans = 0, ent = 0, tagnum; + char title[TTLEN + 1] = "¡º "; + char dirname[200], buf[200]; setbdir(dirname, currboard); tagnum = TagNum; - if (!tagnum) return ans; - - while (tagnum--) - { - EnumTagFhdr (&fhdr, dirname, ent++); - setbfile (buf, currboard, fhdr.filename); - - if (dashf (buf)) - { - strncpy(title+3, fhdr.title, TTLEN-3); - title[TTLEN] = '\0'; - a_copyitem(buf, title, 0, 0); - if(mode) - { - mode--; - a_pasteitem(pm,0); - } - else a_appenditem(pm, 0); - ++ans; - UnTagger (tagnum); - } + if (!tagnum) + return ans; + while (tagnum--) { + EnumTagFhdr(&fhdr, dirname, ent++); + setbfile(buf, currboard, fhdr.filename); + + if (dashf(buf)) { + strncpy(title + 3, fhdr.title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(buf, title, 0, 0); + if (mode) { + mode--; + a_pasteitem(pm, 0); + } else + a_appenditem(pm, 0); + ++ans; + UnTagger(tagnum); + } }; return ans; -} +} -static void a_moveitem(menu_t *pm) { - fileheader_t *tmp; - char newnum[4]; - int num, max, min; - char buf[PATHLEN]; - int fail; +static void +a_moveitem(menu_t * pm) +{ + fileheader_t *tmp; + char newnum[4]; + int num, max, min; + char buf[PATHLEN]; + int fail; sprintf(buf, "½Ð¿é¤J²Ä %d ¿ï¶µªº·s¦¸§Ç¡G", pm->now + 1); - if(!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) + if (!getdata(b_lines - 1, 1, buf, newnum, sizeof(newnum), DOECHO)) return; num = (newnum[0] == '$') ? 9999 : atoi(newnum) - 1; - if(num >= pm->num) + if (num >= pm->num) num = pm->num - 1; - else if(num < 0) + else if (num < 0) num = 0; setadir(buf, pm->path); min = num < pm->now ? num : pm->now; @@ -1015,137 +1057,146 @@ static void a_moveitem(menu_t *pm) { tmp = (fileheader_t *) calloc(max + 1, FHSZ); fail = 0; - if(get_records(buf, tmp, FHSZ, 1, min) != min) + if (get_records(buf, tmp, FHSZ, 1, min) != min) fail = 1; - if(num > pm->now) { - if(get_records(buf, &tmp[min], FHSZ, pm->now+2, max-min) != max-min) + if (num > pm->now) { + if (get_records(buf, &tmp[min], FHSZ, pm->now + 2, max - min) != max - min) fail = 1; - if(get_records(buf, &tmp[max], FHSZ, pm->now+1, 1) != 1) + if (get_records(buf, &tmp[max], FHSZ, pm->now + 1, 1) != 1) fail = 1; } else { - if(get_records(buf, &tmp[min], FHSZ, pm->now+1, 1) != 1) + if (get_records(buf, &tmp[min], FHSZ, pm->now + 1, 1) != 1) fail = 1; - if(get_records(buf, &tmp[min+1], FHSZ, num+1, max-min) != max-min) + if (get_records(buf, &tmp[min + 1], FHSZ, num + 1, max - min) != max - min) fail = 1; } - if(!fail) + if (!fail) substitute_record(buf, tmp, FHSZ * (max + 1), 1); pm->now = num; free(tmp); } -static void a_delrange(menu_t *pm) { - char fname[256]; +static void +a_delrange(menu_t * pm) +{ + char fname[256]; - sprintf(fname,"%s/.DIR",pm->path); + sprintf(fname, "%s/.DIR", pm->path); del_range(0, NULL, fname); pm->num = get_num_records(fname, FHSZ); } -static void a_delete(menu_t *pm) { - char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; - char ans[4]; - fileheader_t backup; +static void +a_delete(menu_t * pm) +{ + char fpath[PATHLEN], buf[PATHLEN], cmd[PATHLEN]; + char ans[4]; + fileheader_t backup; sprintf(fpath, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); setadir(buf, pm->path); - - if(pm->header[pm->now - pm->page].filename[0] == 'H' && - pm->header[pm->now - pm->page].filename[1] == '.') { + + if (pm->header[pm->now - pm->page].filename[0] == 'H' && + pm->header[pm->now - pm->page].filename[1] == '.') { getdata(b_lines - 1, 1, "±z½T©wn§R°£¦¹ºëµØ°Ï³s½u¶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; } else if (dashl(fpath)) { getdata(b_lines - 1, 1, "±z½T©wn§R°£¦¹ symbolic link ¶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; unlink(fpath); - } else if(dashf(fpath)) { + } else if (dashf(fpath)) { getdata(b_lines - 1, 1, "±z½T©wn§R°£¦¹Àɮ׶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') + return; + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) - return; setbpath(buf, "deleted"); stampfile(buf, &backup); strcpy(backup.owner, cuser.userid); - strcpy(backup.title,pm->header[pm->now - pm->page].title + 2); + strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); - sprintf(cmd, "mv -f %s %s", fpath,buf); + sprintf(cmd, "mv -f %s %s", fpath, buf); system(cmd); - setbdir(buf, "deleted"); - append_record(buf, &backup, sizeof(backup)); + setbdir(buf, "deleted"); + append_record(buf, &backup, sizeof(backup)); } else if (dashd(fpath)) { - getdata(b_lines - 1, 1, "±z½T©wn§R°£¾ãӥؿý¶Ü(Y/N)¡H[N] ", ans, + getdata(b_lines - 1, 1, "±z½T©wn§R°£¾ãӥؿý¶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; - setapath(buf, "deleted"); - stampdir(buf, &backup); + setapath(buf, "deleted"); + stampdir(buf, &backup); - sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s",buf,fpath,buf); - system(cmd); + sprintf(cmd, "rm -rf %s;/bin/mv -f %s %s", buf, fpath, buf); + system(cmd); - strcpy(backup.owner, cuser.userid); - strcpy(backup.title,pm->header[pm->now - pm->page].title +2); - setapath(buf, "deleted"); - setadir(buf,buf); - append_record(buf, &backup, sizeof(backup)); - } else { /* Ptt ·l·´ªº¶µ¥Ø */ + strcpy(backup.owner, cuser.userid); + strcpy(backup.title, pm->header[pm->now - pm->page].title + 2); + setapath(buf, "deleted"); + setadir(buf, buf); + append_record(buf, &backup, sizeof(backup)); + } else { /* Ptt ·l·´ªº¶µ¥Ø */ getdata(b_lines - 1, 1, "±z½T©wn§R°£¦¹·l·´ªº¶µ¥Ø¶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return; - if(delete_record(buf, FHSZ, pm->now + 1) == -1) + if (delete_record(buf, FHSZ, pm->now + 1) == -1) return; } pm->num--; } -static void a_newtitle(menu_t *pm) { - char buf[PATHLEN]; - fileheader_t item; +static void +a_newtitle(menu_t * pm) +{ + char buf[PATHLEN]; + fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); - strcpy(buf,item.title + 3); - if(getdata_buf(b_lines - 1, 1, "·s¼ÐÃD¡G", buf, 60, DOECHO)) { + strcpy(buf, item.title + 3); + if (getdata_buf(b_lines - 1, 1, "·s¼ÐÃD¡G", buf, 60, DOECHO)) { strcpy(item.title + 3, buf); setadir(buf, pm->path); substitute_record(buf, &item, FHSZ, pm->now + 1); } } -static void a_hideitem(menu_t *pm) { - fileheader_t *item=&pm->header[pm->now - pm->page]; - char buf[PATHLEN]; - if(item->filemode&FILE_BM) - { - item->filemode &= ~FILE_BM; - item->filemode &= ~FILE_HIDE; - } - else if(item->filemode&FILE_HIDE) - item->filemode |= FILE_BM; - else item->filemode |= FILE_HIDE; +static void +a_hideitem(menu_t * pm) +{ + fileheader_t *item = &pm->header[pm->now - pm->page]; + char buf[PATHLEN]; + if (item->filemode & FILE_BM) { + item->filemode &= ~FILE_BM; + item->filemode &= ~FILE_HIDE; + } else if (item->filemode & FILE_HIDE) + item->filemode |= FILE_BM; + else + item->filemode |= FILE_HIDE; setadir(buf, pm->path); substitute_record(buf, item, FHSZ, pm->now + 1); } -static void a_editsign(menu_t *pm) { - char buf[PATHLEN]; - fileheader_t item; +static void +a_editsign(menu_t * pm) +{ + char buf[PATHLEN]; + fileheader_t item; memcpy(&item, &pm->header[pm->now - pm->page], FHSZ); sprintf(buf, "%c%c", item.title[0], item.title[1]); - if(getdata_buf(b_lines - 1, 1, "²Å¸¹", buf, 5, DOECHO)) { + if (getdata_buf(b_lines - 1, 1, "²Å¸¹", buf, 5, DOECHO)) { item.title[0] = buf[0] ? buf[0] : ' '; item.title[1] = buf[1] ? buf[1] : ' '; item.title[2] = buf[2] ? buf[2] : ' '; @@ -1154,40 +1205,42 @@ static void a_editsign(menu_t *pm) { } } -static void a_showname(menu_t *pm) { - char buf[PATHLEN]; - int len; - int i; - int sym; +static void +a_showname(menu_t * pm) +{ + char buf[PATHLEN]; + int len; + int i; + int sym; move(b_lines - 1, 1); sprintf(buf, "%s/%s", pm->path, pm->header[pm->now - pm->page].filename); - if(dashl(buf)) { + if (dashl(buf)) { prints("¦¹ symbolic link ¦WºÙ¬° %s\n", pm->header[pm->now - pm->page].filename); - if((len = readlink(buf, buf, PATHLEN-1)) >= 0) { + if ((len = readlink(buf, buf, PATHLEN - 1)) >= 0) { buf[len] = '\0'; - for(i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); - if(!BBSHOME[i] && buf[i] == '/') { - if(HAS_PERM(PERM_BBSADM)) + for (i = 0; BBSHOME[i] && buf[i] == BBSHOME[i]; i++); + if (!BBSHOME[i] && buf[i] == '/') { + if (HAS_PERM(PERM_BBSADM)) sym = 1; else { sym = 0; - for(i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; - i++); - if(!BBSHOME "/man"[i] && buf[i] == '/') + for (i++; BBSHOME "/man"[i] && buf[i] == BBSHOME "/man"[i]; + i++); + if (!BBSHOME "/man"[i] && buf[i] == '/') sym = 1; } - if(sym) { + if (sym) { pressanykey(); move(b_lines - 1, 1); - prints("¦¹ symbolic link «ü¦V %s\n", &buf[i+1]); + prints("¦¹ symbolic link «ü¦V %s\n", &buf[i + 1]); } } } - } else if(dashf(buf)) + } else if (dashf(buf)) prints("¦¹¤å³¹¦WºÙ¬° %s", pm->header[pm->now - pm->page].filename); - else if(dashd(buf)) + else if (dashd(buf)) prints("¦¹¥Ø¿ý¦WºÙ¬° %s", pm->header[pm->now - pm->page].filename); else outs("¦¹¶µ¥Ø¤w·l·´, «Øij±N¨ä§R°£¡I"); @@ -1195,9 +1248,11 @@ static void a_showname(menu_t *pm) { } #if 0 -static char *a_title; +static char *a_title; -static void atitle() { +static void +atitle() +{ showtitle("ºëµØ¤å³¹", a_title); outs("[¡ö]Â÷¶} [¡÷]¾\\Ū [^P]µoªí¤å³¹ [b]³Æ§Ñ¿ý [d]§R°£ [q]ºëµØ°Ï " "[TAB]¤åºK [h]elp\n\033[7m ½s¸¹ ¤é ´Á §@ ªÌ " @@ -1205,81 +1260,81 @@ static void atitle() { } #endif -static int isvisible_man(menu_t *me) +static int +isvisible_man(menu_t * me) { - fileheader_t *fhdr = &me->header[me->now-me->page]; - if( me->level<MANAGER && ((fhdr->filemode & FILE_BM) || - ((fhdr->filemode & FILE_HIDE) && - hbflcheck(currbid, currutmp->uid)))) - return 0; - return 1; + fileheader_t *fhdr = &me->header[me->now - me->page]; + if (me->level < MANAGER && ((fhdr->filemode & FILE_BM) || + ((fhdr->filemode & FILE_HIDE) && + hbflcheck(currbid, currutmp->uid)))) + return 0; + return 1; } -int a_menu(char *maintitle, char *path, int lastlevel) { - static char Fexit; - menu_t me; - char fname[PATHLEN]; - int ch, returnvalue = FULLUPDATE; - +int +a_menu(char *maintitle, char *path, int lastlevel) +{ + static char Fexit; + menu_t me; + char fname[PATHLEN]; + int ch, returnvalue = FULLUPDATE; + trans_buffer[0] = 0; - + Fexit = 0; - me.header = (fileheader_t *)calloc(p_lines, FHSZ); + me.header = (fileheader_t *) calloc(p_lines, FHSZ); me.path = path; strcpy(me.mtitle, maintitle); setadir(fname, me.path); me.num = get_num_records(fname, FHSZ); - + /* ºëµØ°Ï-tree ¤¤³¡¥÷µ²ºcÄÝ©ó cuser ==> BM */ - - if(!(me.level = lastlevel)) { - char *ptr; - - if((ptr = strrchr(me.mtitle, '['))) + + if (!(me.level = lastlevel)) { + char *ptr; + + if ((ptr = strrchr(me.mtitle, '['))) me.level = is_BM(ptr + 1); } - me.page = 9999; me.now = 0; - for(;;) { - if(me.now >= me.num) + for (;;) { + if (me.now >= me.num) me.now = me.num - 1; - if(me.now < 0) + if (me.now < 0) me.now = 0; - if(me.now < me.page || me.now >= me.page + p_lines) { + if (me.now < me.page || me.now >= me.page + p_lines) { me.page = me.now - ((me.page == 10000 && me.now > p_lines / 2) ? (p_lines / 2) : (me.now % p_lines)); a_showmenu(&me); } - ch = cursor_key(2 + me.now - me.page, 0); - - if(ch == 'q' || ch == 'Q' || ch == KEY_LEFT) + + if (ch == 'q' || ch == 'Q' || ch == KEY_LEFT) break; - - if(ch >= '1' && ch <= '9') { - if((ch = search_num(ch, me.num)) != -1) + + if (ch >= '1' && ch <= '9') { + if ((ch = search_num(ch, me.num)) != -1) me.now = ch; me.page = 10000; continue; } - - switch(ch) { + switch (ch) { case KEY_UP: case 'k': - if(--me.now < 0) + if (--me.now < 0) me.now = me.num - 1; break; - + case KEY_DOWN: case 'j': - if(++me.now >= me.num) + if (++me.now >= me.num) me.now = 0; break; case KEY_PGUP: case Ctrl('B'): - if(me.now >= p_lines) + if (me.now >= p_lines) me.now -= p_lines; else if (me.now > 0) me.now = 0; @@ -1290,9 +1345,9 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case ' ': case KEY_PGDN: case Ctrl('F'): - if(me.now < me.num - p_lines) + if (me.now < me.num - p_lines) me.now += p_lines; - else if(me.now < me.num - 1) + else if (me.now < me.num - 1) me.now = me.num - 1; else me.now = 0; @@ -1307,7 +1362,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = 9999; break; case '$': - me.now = me.num -1; + me.now = me.num - 1; break; case 'h': a_showhelp(me.level); @@ -1330,98 +1385,100 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case 'e': case 'E': - sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); - if(dashf(fname) && me.level >= MANAGER) { + sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + if (dashf(fname) && me.level >= MANAGER) { *quote_file = 0; - if(vedit(fname, NA, NULL) != -1) { - char fpath[200]; - fileheader_t fhdr; + if (vedit(fname, NA, NULL) != -1) { + char fpath[200]; + fileheader_t fhdr; strcpy(fpath, path); stampfile(fpath, &fhdr); unlink(fpath); Rename(fname, fpath); - strcpy(me.header[me.now-me.page].filename, fhdr.filename); - strcpy(me.header[me.now-me.page].owner, cuser.userid); + strcpy(me.header[me.now - me.page].filename, fhdr.filename); + strcpy(me.header[me.now - me.page].owner, cuser.userid); setadir(fpath, path); - substitute_record(fpath, me.header+me.now-me.page, - sizeof(fhdr), me.now + 1); + substitute_record(fpath, me.header + me.now - me.page, + sizeof(fhdr), me.now + 1); } me.page = 9999; } break; case 'c': - if(me.now < me.num) { - if(!isvisible_man(&me)) break; + if (me.now < me.num) { + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, - me.header[me.now-me.page].filename); - a_copyitem(fname, me.header[me.now-me.page].title, 0, 1); + me.header[me.now - me.page].filename); + a_copyitem(fname, me.header[me.now - me.page].title, 0, 1); me.page = 9999; break; } - case '\n': case '\r': case KEY_RIGHT: case 'r': - if(me.now < me.num) { - fileheader_t *fhdr = &me.header[me.now-me.page]; - if(!isvisible_man(&me)) break; + if (me.now < me.num) { + fileheader_t *fhdr = &me.header[me.now - me.page]; + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, fhdr->filename); - if(*fhdr->filename == 'H' && fhdr->filename[1] == '.') { - item_t item; + if (*fhdr->filename == 'H' && fhdr->filename[1] == '.') { + item_t item; strcpy(item.X.G.server, fhdr->filename + 2); strcpy(item.X.G.path, "1/"); item.X.G.port = 70; gem(fhdr->title, &item, (ch == 'R') ? 1 : 0); } else if (dashf(fname)) { - int more_result; + int more_result; - while((more_result = more(fname, YEA))) { + while ((more_result = more(fname, YEA))) { /* Ptt ½d¥»ºëÆF plugin */ - if(currstat == EDITEXP || currstat == OSONG) { - char ans[4]; + if (currstat == EDITEXP || currstat == OSONG) { + char ans[4]; move(22, 0); clrtoeol(); - getdata(22, 1, - currstat == EDITEXP ? - "n§â½d¨Ò Plugin ¨ì¤å³¹¶Ü?[y/N]": + getdata(22, 1, + currstat == EDITEXP ? + "n§â½d¨Ò Plugin ¨ì¤å³¹¶Ü?[y/N]" : "½T©wnÂI³oººq¶Ü?[y/N]", ans, sizeof(ans), LCECHO); - if(ans[0]=='y') { - strcpy(trans_buffer,fname); + if (ans[0] == 'y') { + strcpy(trans_buffer, fname); Fexit = 1; - if(currstat == OSONG){ - log_file(FN_USSONG,fhdr->title); + if (currstat == OSONG) { + log_file(FN_USSONG, fhdr->title); } free(me.header); return FULLUPDATE; } } - if(more_result == 1) { - if(--me.now < 0) { + if (more_result == 1) { + if (--me.now < 0) { me.now = 0; break; } - } else if(more_result == 3) { - if(++me.now >= me.num) { + } else if (more_result == 3) { + if (++me.now >= me.num) { me.now = me.num - 1; break; } } else break; - if(!isvisible_man(&me)) break; + if (!isvisible_man(&me)) + break; sprintf(fname, "%s/%s", path, - me.header[me.now-me.page].filename); - if(!dashf(fname)) + me.header[me.now - me.page].filename); + if (!dashf(fname)) break; } - } else if(dashd(fname)) { - a_menu(me.header[me.now-me.page].title, fname, me.level); + } else if (dashd(fname)) { + a_menu(me.header[me.now - me.page].title, fname, me.level); /* Ptt ±j¤O¸õ¥Xrecursive */ - if(Fexit) { + if (Fexit) { free(me.header); return FULLUPDATE; } @@ -1432,10 +1489,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) { case 'F': case 'U': - sprintf(fname, "%s/%s", path, me.header[me.now-me.page].filename); - if(me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { - a_forward(path, &me.header[me.now-me.page], ch /*== 'U'*/); - /*By CharlieL*/ + sprintf(fname, "%s/%s", path, me.header[me.now - me.page].filename); + if (me.now < me.num && HAS_PERM(PERM_BASIC) && dashf(fname)) { + a_forward(path, &me.header[me.now - me.page], ch /* == 'U' */ ); + /* By CharlieL */ } else outmsg("µLªkÂà±H¦¹¶µ¥Ø"); @@ -1445,10 +1502,10 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; } - if(me.level >= MANAGER) { - int page0 = me.page; + if (me.level >= MANAGER) { + int page0 = me.page; - switch(ch) { + switch (ch) { case 'n': a_newitem(&me, ADDITEM); me.page = 9999; @@ -1462,7 +1519,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = 9999; break; case 'p': - a_pasteitem(&me,1); + a_pasteitem(&me, 1); me.page = 9999; break; case 'f': @@ -1471,7 +1528,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; case Ctrl('P'): a_pastetagpost(&me, -1); - returnvalue = DIRCHANGED; + returnvalue = DIRCHANGED; me.page = 9999; break; case Ctrl('A'): @@ -1487,16 +1544,16 @@ int a_menu(char *maintitle, char *path, int lastlevel) { me.page = page0; break; } - - if(me.num) - switch(ch) { + + if (me.num) + switch (ch) { case 'm': a_moveitem(&me); me.page = 9999; break; case 'D': - /* Ptt me.page = -1;*/ + /* Ptt me.page = -1; */ a_delrange(&me); me.page = 9999; break; @@ -1504,7 +1561,7 @@ int a_menu(char *maintitle, char *path, int lastlevel) { a_delete(&me); me.page = 9999; break; - case 'H': + case 'H': a_hideitem(&me); me.page = 9999; break; @@ -1514,9 +1571,8 @@ int a_menu(char *maintitle, char *path, int lastlevel) { break; } } - - if(me.level == SYSOP) { - switch(ch) { + if (me.level == SYSOP) { + switch (ch) { case 'l': a_newitem(&me, ADDLINK); me.page = 9999; @@ -1532,9 +1588,11 @@ int a_menu(char *maintitle, char *path, int lastlevel) { return returnvalue; } -static char *mytitle = BBSNAME "§G§iÄæ"; +static char *mytitle = BBSNAME "§G§iÄæ"; -int Announce() { +int +Announce() +{ setutmpmode(ANNOUNCE); a_menu(mytitle, "man", ((HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_ANNOUNCE)) ? SYSOP : diff --git a/mbbsd/args.c b/mbbsd/args.c index 9f937723..60e1de32 100644 --- a/mbbsd/args.c +++ b/mbbsd/args.c @@ -1,58 +1,68 @@ -/* $Id: args.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: args.c,v 1.3 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #ifdef HAVE_SETPROCTITLE -void initsetproctitle(int argc, char **argv, char **envp) { +void +initsetproctitle(int argc, char **argv, char **envp) +{ } #else -char **Argv = NULL; /* pointer to argument vector */ -char *LastArgv = NULL; /* end of argv */ -extern char **environ; +char **Argv = NULL; /* pointer to argument vector */ +char *LastArgv = NULL;/* end of argv */ +extern char **environ; -void initsetproctitle(int argc, char **argv, char **envp) { - register int i; - - /* Move the environment so setproctitle can use the space at - the top of memory. */ - for(i = 0; envp[i]; i++); +void +initsetproctitle(int argc, char **argv, char **envp) +{ + register int i; + + /* + * Move the environment so setproctitle can use the space at the top of + * memory. + */ + for (i = 0; envp[i]; i++); environ = malloc(sizeof(char *) * (i + 1)); - for(i = 0; envp[i]; i++) + for (i = 0; envp[i]; i++) environ[i] = strdup(envp[i]); environ[i] = NULL; - + /* Save start and extent of argv for setproctitle. */ Argv = argv; - if(i > 0) + if (i > 0) LastArgv = envp[i - 1] + strlen(envp[i - 1]); else LastArgv = argv[argc - 1] + strlen(argv[argc - 1]); } -static void do_setproctitle(const char *cmdline) { - char buf[256], *p; - int i; - +static void +do_setproctitle(const char *cmdline) +{ + char buf[256], *p; + int i; + strncpy(buf, cmdline, 256); buf[255] = '\0'; i = strlen(buf); - if(i > LastArgv - Argv[0] - 2) { + if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; } strcpy(Argv[0], buf); p = &Argv[0][i]; - while(p < LastArgv) - *p++='\0'; + while (p < LastArgv) + *p++ = '\0'; Argv[1] = NULL; } -void setproctitle(const char* format, ...) { - char buf[256]; - va_list args; +void +setproctitle(const char *format,...) +{ + char buf[256]; + va_list args; va_start(args, format); - vsprintf(buf, format,args); + vsprintf(buf, format, args); do_setproctitle(buf); va_end(args); } diff --git a/mbbsd/bbcall.c b/mbbsd/bbcall.c index 29b39abc..2c369be4 100644 --- a/mbbsd/bbcall.c +++ b/mbbsd/bbcall.c @@ -1,4 +1,4 @@ -/* $Id: bbcall.c,v 1.4 2002/06/26 18:05:49 kcwu Exp $ */ +/* $Id: bbcall.c,v 1.5 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #define SERVER_0941 "www.chips.com.tw" @@ -21,100 +21,106 @@ #define REFER_0947 "http://web1.hoyard.com.tw/freeway/freewayi.html" #define REFER_0945 "http://203.73.181.254/call.HTM" -static void pager_msg_encode(char *field, char *buf) { - char *cc = field; - unsigned char *p; - - for(p = (unsigned char *)buf; *p; p++) { - if((*p >= '0' && *p <= '9') || - (*p >= 'A' && *p <= 'Z') || - (*p >= 'a' && *p <= 'z') || - *p == ' ') - *cc++ = *p == ' ' ? '+' : (char)*p; - else { - sprintf(cc, "%%%02X", (int)*p); - cc += 3; - } +static void +pager_msg_encode(char *field, char *buf) +{ + char *cc = field; + unsigned char *p; + + for (p = (unsigned char *)buf; *p; p++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'A' && *p <= 'Z') || + (*p >= 'a' && *p <= 'z') || + *p == ' ') + *cc++ = *p == ' ' ? '+' : (char)*p; + else { + sprintf(cc, "%%%02X", (int)*p); + cc += 3; + } } *cc = 0; } -static void Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, - int *Minute) { - char ans[5]; +static void +Gettime(int flag, int *Year, int *Month, int *Day, int *Hour, + int *Minute) +{ + char ans[5]; do { - getdata(10, 0, "¦~[20-]:", ans, 3, LCECHO); - *Year = atoi(ans); - } while(*Year < 00 || *Year > 02); + getdata(10, 0, "¦~[20-]:", ans, 3, LCECHO); + *Year = atoi(ans); + } while (*Year < 00 || *Year > 02); do { - getdata(10, 15, "¤ë[1-12]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Month = atoi(ans)) > 12 || *Month < 1); + getdata(10, 15, "¤ë[1-12]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Month = atoi(ans)) > 12 || *Month < 1); do { - getdata(10,30, "¤é[1-31]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Day = atoi(ans)) > 31 || *Day < 1); + getdata(10, 30, "¤é[1-31]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Day = atoi(ans)) > 31 || *Day < 1); do { - getdata(10,45, "®É[0-23]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Hour = atoi(ans)) > 23 || *Hour < 0); + getdata(10, 45, "®É[0-23]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Hour = atoi(ans)) > 23 || *Hour < 0); do { - getdata(10,60, "¤À[0-59]:", ans, 3, LCECHO); - } while(!IsSNum(ans) || (*Minute=atoi(ans))>59 || *Minute<0); - if(flag == 1) - *Year-=11; + getdata(10, 60, "¤À[0-59]:", ans, 3, LCECHO); + } while (!IsSNum(ans) || (*Minute = atoi(ans)) > 59 || *Minute < 0); + if (flag == 1) + *Year -= 11; } #define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static int Connect(char *s, char *server) { - FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); - int sockfd; - char result[2048]; +static int +Connect(char *s, char *server) +{ + FILE *fp = fopen(BBSHOME "/log/bbcall.log", "a"); + int sockfd; + char result[2048]; struct sockaddr_in serv_addr; struct hostent *hp; sockfd = socket(AF_INET, SOCK_STREAM, 0); - if(sockfd < 0) - return 0; + if (sockfd < 0) + return 0; memset((char *)&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - if((hp = gethostbyname(server)) == NULL) - return 0; + if ((hp = gethostbyname(server)) == NULL) + return 0; memcpy(&serv_addr.sin_addr, hp->h_addr, hp->h_length); - if(!strcmp(server, SERVER_0941)) - serv_addr.sin_port = htons(9100); + if (!strcmp(server, SERVER_0941)) + serv_addr.sin_port = htons(9100); else - serv_addr.sin_port = htons(80); + serv_addr.sin_port = htons(80); - if(connect(sockfd, (struct sockaddr *) &serv_addr, sizeof serv_addr)) { - hpressanykey("µLªk»P¦øªA¾¹¨ú±o³sµ²¡A¶Ç©I¥¢±Ñ"); - return 0; + if (connect(sockfd, (struct sockaddr *) & serv_addr, sizeof serv_addr)) { + hpressanykey("µLªk»P¦øªA¾¹¨ú±o³sµ²¡A¶Ç©I¥¢±Ñ"); + return 0; } else { - mprints(20, 0, "\033[1;33m¦øªA¾¹¤w¸g³s±µ¤W¡A½Ðµy«á" - ".....................\033[m"); - refresh(); + mprints(20, 0, "\033[1;33m¦øªA¾¹¤w¸g³s±µ¤W¡A½Ðµy«á" + ".....................\033[m"); + refresh(); } write(sockfd, s, strlen(s)); shutdown(sockfd, 1); - while(read(sockfd, result, sizeof(result)) > 0) { - fprintf(fp, "%s\n", result); - fflush(fp); - if(strstr(result, "¥¿½T") || - strstr(result,"µ¥«Ý") || - strstr(result,"¦A«×") || - strstr(result,"§¹ ¦¨ ¦^ À³") || - strstr(result, "¹w¬ù¤¤") || - strstr(result,"¶Ç°e¤¤")) { - close(sockfd); - hpressanykey("¶¶§Q°e¥X¶Ç©I"); - return 0; - } - memset(result, 0, sizeof(result)); + while (read(sockfd, result, sizeof(result)) > 0) { + fprintf(fp, "%s\n", result); + fflush(fp); + if (strstr(result, "¥¿½T") || + strstr(result, "µ¥«Ý") || + strstr(result, "¦A«×") || + strstr(result, "§¹ ¦¨ ¦^ À³") || + strstr(result, "¹w¬ù¤¤") || + strstr(result, "¶Ç°e¤¤")) { + close(sockfd); + hpressanykey("¶¶§Q°e¥X¶Ç©I"); + return 0; + } + memset(result, 0, sizeof(result)); } fclose(fp); close(sockfd); @@ -255,3 +261,4 @@ int main_bbcall() { } return 0; } + diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index cc5fd86a..f3eaf143 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1,246 +1,263 @@ -/* $Id: bbs.c,v 1.62 2002/06/29 14:55:34 ptt Exp $ */ +/* $Id: bbs.c,v 1.63 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -static void mail_by_link(char* owner, char* title, char* path) { - char genbuf[200]; - fileheader_t mymail; - - sprintf(genbuf,BBSHOME"/home/%c/%s", cuser.userid[0], cuser.userid); +static void +mail_by_link(char *owner, char *title, char *path) +{ + char genbuf[200]; + fileheader_t mymail; + + sprintf(genbuf, BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); stampfile(genbuf, &mymail); strcpy(mymail.owner, owner); - sprintf(mymail.title, title); + sprintf(mymail.title, title); unlink(genbuf); Link(path, genbuf); - sprintf(genbuf,BBSHOME"/home/%c/%s/.DIR",cuser.userid[0],cuser.userid); - - append_record(genbuf, &mymail, sizeof(mymail)); + sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", cuser.userid[0], cuser.userid); + + append_record(genbuf, &mymail, sizeof(mymail)); } -void anticrosspost() { - char buf[200]; - +void +anticrosspost() +{ + char buf[200]; + sprintf(buf, "\033[1;33;46m%s \033[37;45mcross post ¤å³¹ \033[37m %s\033[m", cuser.userid, ctime(&now)); log_file("etc/illegal_money", buf); - - post_violatelaw(cuser.userid, "Ptt¨t²Îĵ¹î", "Cross-post", "»@³æ³B¥÷"); + + post_violatelaw(cuser.userid, "Ptt¨t²Îĵ¹î", "Cross-post", "»@³æ³B¥÷"); cuser.userlevel |= PERM_VIOLATELAW; - cuser.vl_count ++; + cuser.vl_count++; mail_by_link("Pttĵ¹î³¡¶¤", "Cross-Post»@³æ", BBSHOME "/etc/crosspost.txt"); passwd_update(usernum, &cuser); exit(0); } -/* Heat CharlieL*/ -int save_violatelaw() { - char buf[128], ok[3]; - - setutmpmode(VIOLATELAW); +/* Heat CharlieL */ +int +save_violatelaw() +{ + char buf[128], ok[3]; + + setutmpmode(VIOLATELAW); clear(); stand_title("ú»@³æ¤¤¤ß"); - if(!(cuser.userlevel & PERM_VIOLATELAW)) { + if (!(cuser.userlevel & PERM_VIOLATELAW)) { mprints(22, 0, "\033[1;31m§AµL²á°Ú? §A¤S¨S¦³³Q¶}»@³æ~~\033[m"); pressanykey(); return 0; } - reload_money(); - if(cuser.money < (int)cuser.vl_count*1000) { + if (cuser.money < (int)cuser.vl_count * 1000) { sprintf(buf, "\033[1;31m³o¬O§A²Ä %d ¦¸¹H¤Ï¥»¯¸ªk³W" "¥²¶·Ãº¥X %d $Ptt ,§A¥u¦³ %d ¤¸, ¿ú¤£°÷°Õ!!\033[m", - (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); + (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); mprints(22, 0, buf); pressanykey(); return 0; } - - move(5,0); + move(5, 0); prints("\033[1;37m§Aª¾¹D¶Ü? ¦]¬°§Aªº¹Hªk " "¤w¸g³y¦¨«Ü¦h¤Hªº¤£«K\033[m\n"); prints("\033[1;37m§A¬O§_½T©w¥H«á¤£·|¦A¥Ç¤F¡H\033[m\n"); - - if(!getdata(10,0,"½T©w¶Ü¡H[y/n]:", ok, sizeof(ok), LCECHO) || - ok[0] == 'n' || ok[0] == 'N') { - mprints(22,0,"\033[1;31mµ¥§A·Q³q¤F¦A¨Ó§a!! " + + if (!getdata(10, 0, "½T©w¶Ü¡H[y/n]:", ok, sizeof(ok), LCECHO) || + ok[0] == 'n' || ok[0] == 'N') { + mprints(22, 0, "\033[1;31mµ¥§A·Q³q¤F¦A¨Ó§a!! " "§Ú¬Û«H§A¤£·|ª¾¿ù¤£§ïªº~~~\033[m"); pressanykey(); return 0; } - sprintf(buf, "³o¬O§A²Ä %d ¦¸¹Hªk ¥²¶·Ãº¥X %d $Ptt", - cuser.vl_count, cuser.vl_count*1000); - mprints(11,0,buf); + cuser.vl_count, cuser.vl_count * 1000); + mprints(11, 0, buf); - if(!getdata(10, 0, "n¥I¿ú[y/n]:", ok, sizeof(ok), LCECHO) || - ok[0] == 'N' || ok[0] == 'n') { + if (!getdata(10, 0, "n¥I¿ú[y/n]:", ok, sizeof(ok), LCECHO) || + ok[0] == 'N' || ok[0] == 'n') { - mprints(22,0, "\033[1;31m ¶â ¦s°÷¿ú ¦A¨Ó§a!!!\033[m"); + mprints(22, 0, "\033[1;31m ¶â ¦s°÷¿ú ¦A¨Ó§a!!!\033[m"); pressanykey(); return 0; } - - demoney(-1000*cuser.vl_count); + demoney(-1000 * cuser.vl_count); cuser.userlevel &= (~PERM_VIOLATELAW); passwd_update(usernum, &cuser); return 0; } /* -void make_blist() { - CreateNameList(); - apply_boards(g_board_names); -} -*/ + * void make_blist() { CreateNameList(); apply_boards(g_board_names); } + */ -static time_t board_note_time; -static char *brd_title; +static time_t board_note_time; +static char *brd_title; -void set_board() { - boardheader_t *bp; +void +set_board() +{ + boardheader_t *bp; bp = getbcache(currbid); board_note_time = bp->bupdate; brd_title = bp->BM; - if(brd_title[0] <= ' ') + if (brd_title[0] <= ' ') brd_title = "¼x¨D¤¤"; sprintf(currBM, "ªO¥D¡G%s", brd_title); brd_title = ((bp->bvote != 2 && bp->bvote) ? "¥»¬ÝªO¶i¦æ§ë²¼¤¤" : bp->title + 7); - currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED ; - + currmode = (currmode & (MODE_DIRTY | MODE_MENU)) | MODE_STARTED; + if (HAS_PERM(PERM_ALLBOARD) || is_BM(bp->BM)) currmode = currmode | MODE_BOARD | MODE_POST; - else if(haspostperm(currboard)) - currmode |= MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; } -static void readtitle() { +static void +readtitle() +{ showtitle(currBM, brd_title); outs("[¡ö]Â÷¶} [¡÷]¾\\Ū [^P]µoªí¤å³¹ [b]³Æ§Ñ¿ý [d]§R°£ [z]ºëµØ°Ï " - "[TAB]¤åºK [h]elp\n\033[7m ½s¸¹ ¤é ´Á §@ ªÌ ¤å ³¹ ¼Ð ÃD" + "[TAB]¤åºK [h]elp\n\033[7m ½s¸¹ ¤é ´Á §@ ªÌ ¤å ³¹ ¼Ð ÃD" " \033[m"); } -static void readdoent(int num, fileheader_t *ent) +static void +readdoent(int num, fileheader_t * ent) { - int type,uid; - char *mark, *title, color, special=0, isonline=0; - userinfo_t *uentp; - if(ent->recommend>9 || ent->recommend <0 ) ent->recommend=0; //Ptt:¼È®É - type = brc_unread(ent->filename,brc_num,brc_list) ? '+' : ' '; - - if((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) + int type, uid; + char *mark, *title, color, special = 0, isonline = 0; + userinfo_t *uentp; + if (ent->recommend > 9 || ent->recommend < 0) + ent->recommend = 0; +//Ptt:¼È®É + type = brc_unread(ent->filename, brc_num, brc_list) ? '+' : ' '; + + if ((currmode & MODE_BOARD) && (ent->filemode & FILE_DIGEST)) type = (type == ' ') ? '*' : '#'; - else if(currmode & MODE_BOARD || HAS_PERM(PERM_LOGINOK)) { - if(ent->filemode & FILE_MARKED) + else if (currmode & MODE_BOARD || HAS_PERM(PERM_LOGINOK)) { + if (ent->filemode & FILE_MARKED) type = (type == ' ') ? 'm' : 'M'; - else if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) - type = 'D'; + else if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) + type = 'D'; else if (ent->filemode & FILE_SOLVED) type = 's'; } - title = subject(mark = ent->title); - if(title == mark) + if (title == mark) color = '1', mark = "¡¼"; else color = '3', mark = "R:"; - - if(title[47]) - strcpy(title + 44, " ¡K"); /* §â¦h¾lªº string ¬å±¼ */ - - if(!strncmp(title,"[¤½§i]",6)) special=1; - if(!strchr(ent->owner, '.') && (uid=searchuser(ent->owner)) && - (uentp = search_ulist(uid)) && isvisible(currutmp, uentp) ) - isonline=1; - - if(strncmp(currtitle, title, TTLEN)) - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " - "\033[1m%.*s\033[m%s\n", num, type, - ent->recommend?ent->recommend+'0':' ', - ent->date, - isonline, - ent->owner, mark, - special?6:0, title, special?title+6:title); + + if (title[47]) + strcpy(title + 44, " ¡K"); /* §â¦h¾lªº string ¬å±¼ */ + + if (!strncmp(title, "[¤½§i]", 6)) + special = 1; + if (!strchr(ent->owner, '.') && (uid = searchuser(ent->owner)) && + (uentp = search_ulist(uid)) && isvisible(currutmp, uentp)) + isonline = 1; + + if (strncmp(currtitle, title, TTLEN)) + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[m%s " + "\033[1m%.*s\033[m%s\n", num, type, + ent->recommend ? ent->recommend + '0' : ' ', + ent->date, + isonline, + ent->owner, mark, + special ? 6 : 0, title, special ? title + 6 : title); else - prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " - "%s\033[m\n", num, type, - ent->recommend?ent->recommend+'0':' ', + prints("%6d %c\033[1;32m%c\033[m%-6s\033[%dm%-13.12s\033[1;3%cm%s " + "%s\033[m\n", num, type, + ent->recommend ? ent->recommend + '0' : ' ', ent->date, - isonline, - ent->owner, color, mark, - title); + isonline, + ent->owner, color, mark, + title); } -int cmpfilename(fileheader_t *fhdr) { +int +cmpfilename(fileheader_t * fhdr) +{ return (!strcmp(fhdr->filename, currfile)); } -int cmpfmode(fileheader_t *fhdr) { +int +cmpfmode(fileheader_t * fhdr) +{ return (fhdr->filemode & currfmode); } -int cmpfowner(fileheader_t *fhdr) { +int +cmpfowner(fileheader_t * fhdr) +{ return !strcasecmp(fhdr->owner, currowner); } -int whereami(int ent, fileheader_t *fhdr, char *direct) { - boardheader_t *bh, *p[32], *root; - int i,j; +int +whereami(int ent, fileheader_t * fhdr, char *direct) +{ + boardheader_t *bh, *p[32], *root; + int i, j; - if(!currutmp->brc_id) return 0; + if (!currutmp->brc_id) + return 0; - move(1,0); + move(1, 0); clrtobot(); - bh=getbcache(currutmp->brc_id); - root=getbcache(1); - p[0]=bh; - for(i=0;i<31 && p[i]->parent!=root && p[i]->parent;i++) - p[i+1]=p[i]->parent; - j=i; - prints("§Ú¦bþ?\n%-40.40s %.13s\n", p[j]->title+7, p[j]->BM); - for(j--;j>=0;j--) - prints("%*s %-13.13s %-37.37s %.13s\n", (i-j)*2, "", - p[j]->brdname, p[j]->title, - p[j]->BM); + bh = getbcache(currutmp->brc_id); + root = getbcache(1); + p[0] = bh; + for (i = 0; i < 31 && p[i]->parent != root && p[i]->parent; i++) + p[i + 1] = p[i]->parent; + j = i; + prints("§Ú¦bþ?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM); + for (j--; j >= 0; j--) + prints("%*s %-13.13s %-37.37s %.13s\n", (i - j) * 2, "", + p[j]->brdname, p[j]->title, + p[j]->BM); pressanykey(); return FULLUPDATE; } -static int substitute_check(fileheader_t *fhdr) +static int +substitute_check(fileheader_t * fhdr) { - fileheader_t hdr; - char genbuf[100]; - int num=0; + fileheader_t hdr; + char genbuf[100]; + int num = 0; /* rocker.011018: ¦ê±µ¼Ò¦¡¥Îreference¼W¶i®Ä²v */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); - /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ - if (strcmp (hdr.filename, fhdr->filename)) - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ + if (strcmp(hdr.filename, fhdr->filename)) + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } return num; } -static int do_select(int ent, fileheader_t *fhdr, char *direct) { - char bname[20]; - char bpath[60]; - boardheader_t *bh; - struct stat st; - int i; +static int +do_select(int ent, fileheader_t * fhdr, char *direct) +{ + char bname[20]; + char bpath[60]; + boardheader_t *bh; + struct stat st; + int i; move(0, 0); clrtoeol(); @@ -249,21 +266,22 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(bname[0]=='\0' || !(i = getbnum(bname))) - return FULLUPDATE; + if (bname[0] == '\0' || !(i = getbnum(bname))) + return FULLUPDATE; bh = getbcache(i); - if(!Ben_Perm(bh)) return FULLUPDATE; + if (!Ben_Perm(bh)) + return FULLUPDATE; strcpy(bname, bh->brdname); - currbid=i; - + currbid = i; + setbpath(bpath, bname); - if((*bname == '\0') || (stat(bpath, &st) == -1)) { + if ((*bname == '\0') || (stat(bpath, &st) == -1)) { move(2, 0); clrtoeol(); outs(err_bid); return FULLUPDATE; } - setutmpbid(currbid); + setutmpbid(currbid); brc_initial(bname); set_board(); @@ -277,53 +295,56 @@ static int do_select(int ent, fileheader_t *fhdr, char *direct) { /* ----------------------------------------------------- */ /* §ï¨} innbbsd Âà¥X«H¥ó¡B³s½u¬å«H¤§³B²zµ{§Ç */ /* ----------------------------------------------------- */ -void outgo_post(fileheader_t *fh, char *board) { - FILE *foo; - - if((foo = fopen("innd/out.bntp", "a"))) { +void +outgo_post(fileheader_t * fh, char *board) +{ + FILE *foo; + + if ((foo = fopen("innd/out.bntp", "a"))) { fprintf(foo, "%s\t%s\t%s\t%s\t%s\n", board, fh->filename, cuser.userid, cuser.username, fh->title); fclose(foo); } } -static void cancelpost(fileheader_t *fh, int by_BM) { - FILE *fin, *fout; - char *ptr, *brd; - fileheader_t postfile; - char genbuf[200]; - char nick[STRLEN], fn1[STRLEN], fn2[STRLEN]; - +static void +cancelpost(fileheader_t * fh, int by_BM) +{ + FILE *fin, *fout; + char *ptr, *brd; + fileheader_t postfile; + char genbuf[200]; + char nick[STRLEN], fn1[STRLEN], fn2[STRLEN]; + setbfile(fn1, currboard, fh->filename); - if((fin = fopen(fn1, "r"))) { + if ((fin = fopen(fn1, "r"))) { brd = by_BM ? "deleted" : "junk"; setbpath(fn2, brd); stampfile(fn2, &postfile); memcpy(postfile.owner, fh->owner, IDLEN + TTLEN + 10); - nick[0] = '\0'; - while(fgets(genbuf, sizeof(genbuf), fin)) { - if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || - !strncmp(genbuf, str_author2, LEN_AUTHOR2)) { - if((ptr = strrchr(genbuf, ')'))) - *ptr = '\0'; - if((ptr = (char *)strchr(genbuf, '('))) - strcpy(nick, ptr + 1); - break; - } + nick[0] = '\0'; + while (fgets(genbuf, sizeof(genbuf), fin)) { + if (!strncmp(genbuf, str_author1, LEN_AUTHOR1) || + !strncmp(genbuf, str_author2, LEN_AUTHOR2)) { + if ((ptr = strrchr(genbuf, ')'))) + *ptr = '\0'; + if ((ptr = (char *)strchr(genbuf, '('))) + strcpy(nick, ptr + 1); + break; } + } - if((fout = fopen("innd/cancel.bntp", "a"))) { - fprintf(fout, "%s\t%s\t%s\t%s\t%s\n", currboard, fh->filename, - cuser.userid, nick, fh->title); - fclose(fout); - } - + if ((fout = fopen("innd/cancel.bntp", "a"))) { + fprintf(fout, "%s\t%s\t%s\t%s\t%s\n", currboard, fh->filename, + cuser.userid, nick, fh->title); + fclose(fout); + } fclose(fin); Rename(fn1, fn2); setbdir(genbuf, brd); - setbtotal(getbnum(brd)); + setbtotal(getbnum(brd)); append_record(genbuf, &postfile, sizeof(postfile)); } } @@ -331,28 +352,32 @@ static void cancelpost(fileheader_t *fh, int by_BM) { /* ----------------------------------------------------- */ /* µoªí¡B¦^À³¡B½s¿è¡BÂà¿ý¤å³¹ */ /* ----------------------------------------------------- */ -void do_reply_title(int row, char *title) { - char genbuf[200]; - char genbuf2[4]; +void +do_reply_title(int row, char *title) +{ + char genbuf[200]; + char genbuf2[4]; - if(strncasecmp(title, str_reply, 4)) + if (strncasecmp(title, str_reply, 4)) sprintf(save_title, "Re: %s", title); else strcpy(save_title, title); save_title[TTLEN - 1] = '\0'; sprintf(genbuf, "±Ä¥Îì¼ÐÃD¡m%.60s¡n¶Ü?[Y] ", save_title); getdata(row, 0, genbuf, genbuf2, 4, LCECHO); - if(genbuf2[0] == 'n' || genbuf2[0] == 'N') + if (genbuf2[0] == 'n' || genbuf2[0] == 'N') getdata(++row, 0, "¼ÐÃD¡G", save_title, TTLEN, DOECHO); } -static void do_unanonymous_post(char* fpath) { - fileheader_t mhdr; - char title[128]; - char genbuf[200]; +static void +do_unanonymous_post(char *fpath) +{ + fileheader_t mhdr; + char title[128]; + char genbuf[200]; setbpath(genbuf, "UnAnonymous"); - if(dashd(genbuf)) { + if (dashd(genbuf)) { stampfile(genbuf, &mhdr); unlink(genbuf); Link(fpath, genbuf); @@ -365,77 +390,77 @@ static void do_unanonymous_post(char* fpath) { } #ifdef NO_WATER_POST -static time_t last_post_time = 0; -static time_t water_counts = 0; +static time_t last_post_time = 0; +static time_t water_counts = 0; #endif -static int do_general() { - fileheader_t postfile; - char fpath[80], buf[80]; - int aborted, defanony, ifuseanony; - char genbuf[200],*owner, - *ctype[]={"°ÝÃD","«Øij","°Q½×","¤ß±o","¶¢²á","¤½§i","±¡³ø"}; - boardheader_t *bp; - int islocal; - +static int +do_general() +{ + fileheader_t postfile; + char fpath[80], buf[80]; + int aborted, defanony, ifuseanony; + char genbuf[200], *owner, *ctype[] = {"°ÝÃD", "«Øij", "°Q½×", "¤ß±o", "¶¢²á", "¤½§i", "±¡³ø"}; + boardheader_t *bp; + int islocal; + ifuseanony = 0; bp = getbcache(currbid); - + clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("¹ï¤£°_¡A±z¥Ø«eµLªk¦b¦¹µoªí¤å³¹¡I"); pressanykey(); return FULLUPDATE; } - #ifdef NO_WATER_POST /* ¤T¤ÀÄÁ¤º³Ì¦hµoªí¤½g¤å³¹ */ - if(currutmp->lastact - last_post_time < 60 * 3) { - if(water_counts >= 5) { + if (currutmp->lastact - last_post_time < 60 * 3) { + if (water_counts >= 5) { move(5, 10); - outs("¹ï¤£°_¡A±zªº¤å³¹¤Ó¤ôÅo¡A«Ý·|¦Apost§a¡I¤p¯µ³Z:¥i¥Î'X'±ÀÂˤ峹"); + outs("¹ï¤£°_¡A±zªº¤å³¹¤Ó¤ôÅo¡A«Ý·|¦Apost§a¡I¤p¯µ³Z:¥i¥Î'X'±ÀÂˤ峹"); pressanykey(); return FULLUPDATE; - } + } } else { last_post_time = currutmp->lastact; water_counts = 0; } #endif - - setbfile(genbuf, currboard, FN_POST_NOTE ); - - if(more(genbuf,NA) == -1) - more("etc/"FN_POST_NOTE , NA); - - move(19,0); + + setbfile(genbuf, currboard, FN_POST_NOTE); + + if (more(genbuf, NA) == -1) + more("etc/" FN_POST_NOTE, NA); + + move(19, 0); prints("µoªí¤å³¹©ó¡i\033[33m %s\033[m ¡j \033[32m%s\033[m ¬ÝªO\n\n", currboard, bp->title + 7); - - if(quote_file[0]) + + if (quote_file[0]) do_reply_title(20, currtitle); else { - getdata(21, 0, - "ºØÃþ¡G1.°ÝÃD 2.«Øij 3.°Q½× 4.¤ß±o 5.¶¢²á 6.¤½§i 7.±¡³ø (1-7©Î¤£¿ï)", - save_title,3,LCECHO); - local_article = save_title[0]-'1'; - if(local_article>=0 && local_article<=6) - sprintf(save_title,"[%s] ",ctype[local_article]); - else - save_title[0]='\0'; + getdata(21, 0, + "ºØÃþ¡G1.°ÝÃD 2.«Øij 3.°Q½× 4.¤ß±o 5.¶¢²á 6.¤½§i 7.±¡³ø (1-7©Î¤£¿ï)", + save_title, 3, LCECHO); + local_article = save_title[0] - '1'; + if (local_article >= 0 && local_article <= 6) + sprintf(save_title, "[%s] ", ctype[local_article]); + else + save_title[0] = '\0'; getdata_buf(22, 0, "¼ÐÃD¡G", save_title, TTLEN, DOECHO); - strip_ansi(save_title,save_title,0); + strip_ansi(save_title, save_title, 0); } - if(save_title[0] == '\0') + if (save_title[0] == '\0') return FULLUPDATE; - + curredit &= ~EDIT_MAIL; curredit &= ~EDIT_ITEM; setutmpmode(POSTING); - + /* ¥¼¨ã³Æ Internet ÅvªÌ¡A¥u¯à¦b¯¸¤ºµoªí¤å³¹ */ - if(HAS_PERM(PERM_INTERNET)) + if (HAS_PERM(PERM_INTERNET)) local_article = 0; else local_article = 1; @@ -443,26 +468,26 @@ static int do_general() { /* build filename */ setbpath(fpath, currboard); stampfile(fpath, &postfile); - + aborted = vedit(fpath, YEA, &islocal); - if(aborted == -1) { + if (aborted == -1) { unlink(fpath); pressanykey(); return FULLUPDATE; } - water_counts++; /* po¦¨¥\ */ + water_counts++; /* po¦¨¥\ */ /* set owner to Anonymous , for Anonymous board */ #ifdef HAVE_ANONYMOUS /* Ptt and Jaky */ - defanony=currbrdattr & BRD_DEFAULTANONYMOUS; - if((currbrdattr & BRD_ANONYMOUS) && - ((strcmp(real_name,"r") && defanony) || (real_name[0] && !defanony)) + defanony = currbrdattr & BRD_DEFAULTANONYMOUS; + if ((currbrdattr & BRD_ANONYMOUS) && + ((strcmp(real_name, "r") && defanony) || (real_name[0] && !defanony)) ) { - strcat(real_name,"."); + strcat(real_name, "."); owner = real_name; - ifuseanony=1; + ifuseanony = 1; } else owner = cuser.userid; #else @@ -473,68 +498,68 @@ static int do_general() { postfile.money = aborted; strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); - if(islocal) /* local save */ + if (islocal) /* local save */ postfile.filemode = FILE_LOCAL; - + setbdir(buf, currboard); - if(append_record(buf, &postfile, sizeof(postfile)) != -1) { + if (append_record(buf, &postfile, sizeof(postfile)) != -1) { setbtotal(currbid); - if(currmode & MODE_SELECT) - append_record(currdirect,&postfile,sizeof(postfile)); - if(!islocal && !(bp->brdattr & BRD_NOTRAN)) + if (currmode & MODE_SELECT) + append_record(currdirect, &postfile, sizeof(postfile)); + if (!islocal && !(bp->brdattr & BRD_NOTRAN)) outgo_post(&postfile, currboard); brc_addlist(postfile.filename); - if(!(currbrdattr & BRD_HIDE) && - (!bp->level || (currbrdattr & BRD_POSTMASK))) { + if (!(currbrdattr & BRD_HIDE) && + (!bp->level || (currbrdattr & BRD_POSTMASK))) { setbpath(genbuf, ALLPOST); stampfile(genbuf, &postfile); unlink(genbuf); /* jochang: boards may spread across many disk */ - /* link doesn't work across device, - Link doesn't work if we have same-time-across-device posts, - we try symlink now */ + /* + * link doesn't work across device, Link doesn't work if we have + * same-time-across-device posts, we try symlink now + */ { - /* we need absolute path for symlink */ - char abspath[256]=BBSHOME"/"; - strcat(abspath,fpath); - symlink(abspath,genbuf); + /* we need absolute path for symlink */ + char abspath[256] = BBSHOME "/"; + strcat(abspath, fpath); + symlink(abspath, genbuf); } strcpy(postfile.owner, owner); strcpy(postfile.title, save_title); postfile.filemode = FILE_LOCAL; setbdir(genbuf, ALLPOST); - if(append_record(genbuf, &postfile, sizeof(postfile)) != -1) { + if (append_record(genbuf, &postfile, sizeof(postfile)) != -1) { setbtotal(getbnum(ALLPOST)); } } - outs("¶¶§Q¶K¥X§G§i¡A"); - + #ifdef MAX_POST_MONEY aborted = (aborted > MAX_POST_MONEY) ? MAX_POST_MONEY : aborted; #endif - if(strcmp(currboard, "Test") && !ifuseanony) { + if (strcmp(currboard, "Test") && !ifuseanony) { prints("³o¬O±zªº²Ä %d ½g¤å³¹¡C ½Z¹S %d »È¡C", - ++cuser.numposts, aborted ); + ++cuser.numposts, aborted); demoney(aborted); - passwd_update(usernum, &cuser); /* post ¼Æ */ + passwd_update(usernum, &cuser); /* post ¼Æ */ } else outs("´ú¸Õ«H¥ó¤£¦C¤J¬ö¿ý¡A·q½Ð¥]²[¡C"); - + /* ¦^À³¨ìì§@ªÌ«H½c */ - - if(curredit & EDIT_BOTH) { - char *str, *msg = "¦^À³¦Ü§@ªÌ«H½c"; - if((str = strchr(quote_user, '.'))) { - if( + if (curredit & EDIT_BOTH) { + char *str, *msg = "¦^À³¦Ü§@ªÌ«H½c"; + + if ((str = strchr(quote_user, '.'))) { + if ( #ifndef USE_BSMTP bbs_sendmail(fpath, save_title, str + 1) #else - bsmtp(fpath, save_title, str + 1 ,0) + bsmtp(fpath, save_title, str + 1, 0) #endif < 0) msg = "§@ªÌµLªk¦¬«H"; @@ -546,38 +571,42 @@ static int do_general() { strcpy(postfile.owner, cuser.userid); strcpy(postfile.title, save_title); - postfile.filemode = FILE_BOTH;/* both-reply flag */ + postfile.filemode = FILE_BOTH; /* both-reply flag */ sethomedir(genbuf, quote_user); - if(append_record(genbuf, &postfile, sizeof(postfile)) == -1) + if (append_record(genbuf, &postfile, sizeof(postfile)) == -1) msg = err_uid; } outs(msg); curredit ^= EDIT_BOTH; } - if(currbrdattr & BRD_ANONYMOUS) + if (currbrdattr & BRD_ANONYMOUS) do_unanonymous_post(fpath); } pressanykey(); return FULLUPDATE; } -int do_post() { - boardheader_t *bp; +int +do_post() +{ + boardheader_t *bp; bp = getbcache(currbid); - if(bp->brdattr & BRD_VOTEBOARD) - return do_voteboard(); - else if(!(bp->brdattr & BRD_GROUPBOARD)) - return do_general(); + if (bp->brdattr & BRD_VOTEBOARD) + return do_voteboard(); + else if (!(bp->brdattr & BRD_GROUPBOARD)) + return do_general(); touchdircache(currbid); return 0; } -static void do_generalboardreply(fileheader_t *fhdr){ - char genbuf[200]; +static void +do_generalboardreply(fileheader_t * fhdr) +{ + char genbuf[200]; getdata(b_lines - 1, 0, "¡¶ ¦^À³¦Ü (F)¬ÝªO (M)§@ªÌ«H½c (B)¤GªÌ¬Ò¬O (Q)¨ú®ø¡H[F] ", genbuf, 3, LCECHO); - switch(genbuf[0]) { + switch (genbuf[0]) { case 'm': mail_reply(0, fhdr, 0); case 'q': @@ -593,14 +622,16 @@ static void do_generalboardreply(fileheader_t *fhdr){ *quote_file = 0; } -int getindex(char *fpath, char *fname, int size) { - int fd, now=0; - fileheader_t fhdr; - - if((fd = open(fpath, O_RDONLY, 0)) != -1) { - while((read(fd, &fhdr, size) == size)) { +int +getindex(char *fpath, char *fname, int size) +{ + int fd, now = 0; + fileheader_t fhdr; + + if ((fd = open(fpath, O_RDONLY, 0)) != -1) { + while ((read(fd, &fhdr, size) == size)) { now++; - if(!strcmp(fhdr.filename,fname)) { + if (!strcmp(fhdr.filename, fname)) { close(fd); return now; } @@ -610,42 +641,49 @@ int getindex(char *fpath, char *fname, int size) { return 0; } -int invalid_brdname(char *brd) { - register char ch; - +int +invalid_brdname(char *brd) +{ + register char ch; + ch = *brd++; - if(not_alnum(ch)) + if (not_alnum(ch)) return 1; - while((ch = *brd++)) { - if(not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') + while ((ch = *brd++)) { + if (not_alnum(ch) && ch != '_' && ch != '-' && ch != '.') return 1; } return 0; } -static int b_call_in(int ent, fileheader_t *fhdr, char *direct) +static int +b_call_in(int ent, fileheader_t * fhdr, char *direct) { - userinfo_t *u = search_ulist(searchuser(fhdr->owner)); - if( u ){ - int fri_stat; + userinfo_t *u = search_ulist(searchuser(fhdr->owner)); + if (u) { + int fri_stat; fri_stat = friend_stat(currutmp, u); - if( isvisible_stat(currutmp, u, fri_stat) && call_in(u, fri_stat) ) - return FULLUPDATE; + if (isvisible_stat(currutmp, u, fri_stat) && call_in(u, fri_stat)) + return FULLUPDATE; } return DONOTHING; } -static void do_reply(fileheader_t *fhdr) { - boardheader_t *bp; +static void +do_reply(fileheader_t * fhdr) +{ + boardheader_t *bp; bp = getbcache(currbid); if (bp->brdattr & BRD_VOTEBOARD) - do_voteboardreply(fhdr); + do_voteboardreply(fhdr); else - do_generalboardreply(fhdr); + do_generalboardreply(fhdr); } -static int reply_post(int ent, fileheader_t *fhdr, char *direct) { - if(!(currmode & MODE_POST)) +static int +reply_post(int ent, fileheader_t * fhdr, char *direct) +{ + if (!(currmode & MODE_POST)) return DONOTHING; setdirpath(quote_file, direct, fhdr->filename); @@ -654,28 +692,30 @@ static int reply_post(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int edit_post(int ent, fileheader_t *fhdr, char *direct) { - char fpath[80], fpath0[80]; - char genbuf[200]; - fileheader_t postfile; - boardheader_t *bp; +static int +edit_post(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[80], fpath0[80]; + char genbuf[200]; + fileheader_t postfile; + boardheader_t *bp; bp = getbcache(currbid); - if ( strcmp(bp->brdname, "Security" ) == 0 ) + if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; if (!HAS_PERM(PERM_SYSOP) && (bp->brdattr & BRD_VOTEBOARD)) return DONOTHING; - if ((!HAS_PERM(PERM_SYSOP)) && - strcmp(fhdr->owner, cuser.userid)) + if ((!HAS_PERM(PERM_SYSOP)) && + strcmp(fhdr->owner, cuser.userid)) return DONOTHING; - setutmpmode(REEDIT); + setutmpmode(REEDIT); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; strcpy(save_title, fhdr->title); -/* rocker.011018: ³o¸Ì¬O¤£¬O¸ÓÀˬd¤@¤Uקï¤å³¹«áªºmoney©M즳ªº¤ñ¸û? */ - if(vedit(genbuf, 0, NULL) != -1) { + /* rocker.011018: ³o¸Ì¬O¤£¬O¸ÓÀˬd¤@¤Uקï¤å³¹«áªºmoney©M즳ªº¤ñ¸û? */ + if (vedit(genbuf, 0, NULL) != -1) { setbpath(fpath, currboard); stampfile(fpath, &postfile); unlink(fpath); @@ -683,45 +723,44 @@ static int edit_post(int ent, fileheader_t *fhdr, char *direct) { Rename(fpath0, fpath); -/* rocker.011018: fix ¦ê±µ¼Ò¦¡§ï¤å³¹«á¤å³¹´N¤£¨£ªºbug */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(fpath0, currboard); - get_record(fpath0, &hdr, sizeof (hdr), num); - - /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ - if (!strcmp (hdr.filename, fhdr->filename)) - { - strcpy(hdr.filename, postfile.filename); - strcpy(hdr.title, save_title); - substitute_record(fpath0, &hdr, sizeof(hdr), num); - } - } + /* rocker.011018: fix ¦ê±µ¼Ò¦¡§ï¤å³¹«á¤å³¹´N¤£¨£ªºbug */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(fpath0, currboard); + get_record(fpath0, &hdr, sizeof(hdr), num); + /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ + if (!strcmp(hdr.filename, fhdr->filename)) { + strcpy(hdr.filename, postfile.filename); + strcpy(hdr.title, save_title); + substitute_record(fpath0, &hdr, sizeof(hdr), num); + } + } strcpy(fhdr->filename, postfile.filename); strcpy(fhdr->title, save_title); brc_addlist(postfile.filename); substitute_record(direct, fhdr, sizeof(*fhdr), ent); -/* rocker.011018: ¶¶«K§ó·s¤@¤Ucache */ - touchdircache(currbid); + /* rocker.011018: ¶¶«K§ó·s¤@¤Ucache */ + touchdircache(currbid); } return FULLUPDATE; } #define UPDATE_USEREC (currmode |= MODE_DIRTY) -static int cross_post(int ent, fileheader_t *fhdr, char *direct) { - char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; - fileheader_t xfile; - FILE *xptr; - int author = 0; - char genbuf[200]; - char genbuf2[4]; - boardheader_t *bp; +static int +cross_post(int ent, fileheader_t * fhdr, char *direct) +{ + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + boardheader_t *bp; move(2, 0); clrtoeol(); move(3, 0); @@ -735,13 +774,13 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*xboard == '\0' || !haspostperm(xboard)) + if (*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; - - if((ent = str_checksum(fhdr->title)) != 0 && - ent == postrecord.checksum[0]) { + + if ((ent = str_checksum(fhdr->title)) != 0 && + ent == postrecord.checksum[0]) { /* Àˬd cross post ¦¸¼Æ */ - if(postrecord.times++ > MAX_CROSSNUM) + if (postrecord.times++ > MAX_CROSSNUM) anticrosspost(); } else { postrecord.times = 0; @@ -749,1196 +788,1177 @@ static int cross_post(int ent, fileheader_t *fhdr, char *direct) { } ent = 1; - if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + if (HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { getdata(2, 0, "(1)ì¤åÂà¸ü (2)ÂÂÂà¿ý®æ¦¡¡H[1] ", genbuf, 3, DOECHO); - if(genbuf[0] != '2') { + if (genbuf[0] != '2') { ent = 0; getdata(2, 0, "«O¯dì§@ªÌ¦WºÙ¶Ü?[Y] ", inputbuf, 3, DOECHO); - if (inputbuf[0] != 'n' && inputbuf[0] != 'N') author = 1; + if (inputbuf[0] != 'n' && inputbuf[0] != 'N') + author = 1; } } - - if(ent) + if (ent) sprintf(xtitle, "[Âà¿ý]%.66s", fhdr->title); else strcpy(xtitle, fhdr->title); sprintf(genbuf, "±Ä¥Îì¼ÐÃD¡m%.60s¡n¶Ü?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, 4, LCECHO); - if(genbuf2[0] == 'n' || genbuf2[0] == 'N') { - if(getdata_str(2, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO,xtitle)) + if (genbuf2[0] == 'n' || genbuf2[0] == 'N') { + if (getdata_str(2, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO, xtitle)) strcpy(xtitle, genbuf); } - getdata(2, 0, "(S)¦sÀÉ (L)¯¸¤º (Q)¨ú®ø¡H[Q] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'l' || genbuf[0] == 's') { - int currmode0 = currmode; + if (genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; currmode = 0; setbpath(xfpath, xboard); stampfile(xfpath, &xfile); - if(author) + if (author) strcpy(xfile.owner, fhdr->owner); else strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); - if(genbuf[0] == 'l') { + if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; - } - + } setbfile(fname, currboard, fhdr->filename); -// if(ent) { - xptr = fopen(xfpath, "w"); - - strcpy(save_title, xfile.title); - strcpy(xfpath, currboard); - strcpy(currboard, xboard); - write_header(xptr); - strcpy(currboard, xfpath); - - fprintf(xptr, "¡° [¥»¤åÂà¿ý¦Û %s ¬ÝªO]\n\n", currboard); - - b_suckinfile(xptr, fname); - addsignature(xptr,0); - fclose(xptr); -/* Cross fs¦³°ÝÃD - } else { - unlink(xfpath); - link(fname, xfpath); - } -*/ - setbdir(fname, xboard); - append_record(fname, &xfile, sizeof(xfile)); - bp = getbcache(getbnum(xboard)); - if(!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) - outgo_post(&xfile, xboard); - setbtotal(getbnum(xboard)); - cuser.numposts++; - UPDATE_USEREC; - outs("¤å³¹Âà¿ý§¹¦¨"); - pressanykey(); - currmode = currmode0; - } - return FULLUPDATE; -} - -static int read_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - int more_result; - - if(fhdr->owner[0] == '-') - return DONOTHING; - - setdirpath(genbuf, direct, fhdr->filename); - - if((more_result = more(genbuf, YEA)) == -1) - return DONOTHING; - - brc_addlist(fhdr->filename); - strncpy(currtitle, subject(fhdr->title), TTLEN); - strncpy(currowner, subject(fhdr->owner), IDLEN + 2); - - switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return FULLUPDATE; - case 7: - case 8: - if((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); - do_reply(fhdr); - *quote_file = 0; + //if (ent) { + xptr = fopen(xfpath, "w"); + + strcpy(save_title, xfile.title); + strcpy(xfpath, currboard); + strcpy(currboard, xboard); + write_header(xptr); + strcpy(currboard, xfpath); + + fprintf(xptr, "¡° [¥»¤åÂà¿ý¦Û %s ¬ÝªO]\n\n", currboard); + + b_suckinfile(xptr, fname); + addsignature(xptr, 0); + fclose(xptr); + /* + * Cross fs¦³°ÝÃD } else { unlink(xfpath); link(fname, xfpath); } + */ + setbdir(fname, xboard); + append_record(fname, &xfile, sizeof(xfile)); + bp = getbcache(getbnum(xboard)); + if (!xfile.filemode && !(bp->brdattr && BRD_NOTRAN)) + outgo_post(&xfile, xboard); + setbtotal(getbnum(xboard)); + cuser.numposts++; + UPDATE_USEREC; + outs("¤å³¹Âà¿ý§¹¦¨"); + pressanykey(); + currmode = currmode0; } return FULLUPDATE; - case 9: - return 'A'; - case 10: - return 'a'; - case 11: - return '/'; - case 12: - return '?'; } + static int read_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + int more_result; + + if (fhdr->owner[0] == '-') + return DONOTHING; + + setdirpath(genbuf, direct, fhdr->filename); + + if ((more_result = more(genbuf, YEA)) == -1) + return DONOTHING; + + brc_addlist(fhdr->filename); + strncpy(currtitle, subject(fhdr->title), TTLEN); + strncpy(currowner, subject(fhdr->owner), IDLEN + 2); + + switch (more_result) { + case 1: + return READ_PREV; + case 2: + return RELATE_PREV; + case 3: + return READ_NEXT; + case 4: + return RELATE_NEXT; + case 5: + return RELATE_FIRST; + case 6: + return FULLUPDATE; + case 7: + case 8: + if ((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } + return FULLUPDATE; + case 9: + return 'A'; + case 10: + return 'a'; + case 11: + return '/'; + case 12: + return '?'; + } - outmsg("\033[34;46m ¾\\Ū¤å³¹ \033[31;47m (R/Y)\033[30m¦^«H \033[31m" - "(=[]<>)\033[30m¬ÛÃö¥DÃD \033[31m(¡ô¡õ)\033[30m¤W¤U«Ê \033[31m(¡ö)" - "\033[30mÂ÷¶} \033[m"); + outmsg("\033[34;46m ¾\\Ū¤å³¹ \033[31;47m (R/Y)\033[30m¦^«H \033[31m" + "(=[]<>)\033[30m¬ÛÃö¥DÃD \033[31m(¡ô¡õ)\033[30m¤W¤U«Ê \033[31m(¡ö)" + "\033[30mÂ÷¶} \033[m"); - switch(egetch()) { - case 'q': - case 'Q': - case KEY_LEFT: - break; + switch (egetch()) { + case 'q': + case 'Q': + case KEY_LEFT: + break; - case ' ': - case KEY_RIGHT: - case KEY_DOWN: - case KEY_PGDN: - case 'n': - case Ctrl('N'): - return READ_NEXT; + case ' ': + case KEY_RIGHT: + case KEY_DOWN: + case KEY_PGDN: + case 'n': + case Ctrl('N'): + return READ_NEXT; - case KEY_UP: - case 'p': - case Ctrl('P'): - case KEY_PGUP: - return READ_PREV; + case KEY_UP: + case 'p': + case Ctrl('P'): + case KEY_PGUP: + return READ_PREV; - case '=': - return RELATE_FIRST; + case '=': + return RELATE_FIRST; - case ']': - case 't': - return RELATE_NEXT; + case ']': + case 't': + return RELATE_NEXT; - case '[': - return RELATE_PREV; + case '[': + return RELATE_PREV; - case '.': - case '>': - return THREAD_NEXT; + case '.': + case '>': + return THREAD_NEXT; - case ',': - case '<': - return THREAD_PREV; + case ',': + case '<': + return THREAD_PREV; - case Ctrl('C'): - cal(); - return FULLUPDATE; - break; + case Ctrl('C'): + cal(); + return FULLUPDATE; + break; - case Ctrl('I'): - t_idle(); - return FULLUPDATE; - case 'y': - case 'r': - case 'R': - case 'Y': - if((currmode & MODE_POST)) { - strcpy(quote_file, genbuf); - do_reply(fhdr); - *quote_file = 0; + case Ctrl('I'): + t_idle(); + return FULLUPDATE; + case 'y': + case 'r': + case 'R': + case 'Y': + if ((currmode & MODE_POST)) { + strcpy(quote_file, genbuf); + do_reply(fhdr); + *quote_file = 0; + } } + return FULLUPDATE; } - return FULLUPDATE; -} -/* ----------------------------------------------------- */ -/* ±Ä¶°ºëµØ°Ï */ -/* ----------------------------------------------------- */ -static int b_man() { - char buf[64]; - - setapath(buf, currboard); - if( (currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP) ){ - char genbuf[128]; - int fd; - sprintf(genbuf, "%s/.rebuild", buf); - if( (fd = open(genbuf, O_CREAT, 0640)) > 0 ) - close(fd); + /* ----------------------------------------------------- */ + /* ±Ä¶°ºëµØ°Ï */ + /* ----------------------------------------------------- */ + static int b_man() { + char buf[64]; + + setapath(buf, currboard); + if ((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) { + char genbuf[128]; + int fd; + sprintf(genbuf, "%s/.rebuild", buf); + if ((fd = open(genbuf, O_CREAT, 0640)) > 0) + close(fd); + } + return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : + (currmode & MODE_BOARD ? 1 : 0)); } - return a_menu(currboard, buf, HAS_PERM(PERM_ALLBOARD) ? 2 : - (currmode & MODE_BOARD ? 1 : 0)); -} #ifndef NO_GAMBLE -void stop_gamble() -{ - boardheader_t *bp = getbcache(currbid); - char fn_ticket[128], fn_ticket_end[128]; - if(!bp->endgamble || bp->endgamble>now) return; - - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); - - rename(fn_ticket, fn_ticket_end); - if(bp->endgamble) - { - bp->endgamble= 0; - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - } -} -static int join_gamble(int ent, fileheader_t *fhdr, char *direct) { - if(!HAS_PERM(PERM_LOGINOK)) return DONOTHING; - stop_gamble(); - ticket(currbid); - return FULLUPDATE; -} -static int hold_gamble(int ent, fileheader_t *fhdr, char *direct) { - char fn_ticket[128],fn_ticket_end[128],genbuf[128], - msg[256]="",yn[10]=""; - boardheader_t *bp = getbcache(currbid); - int i; - FILE *fp=NULL; - - if(!(currmode & MODE_BOARD)) return 0; - setbfile(fn_ticket, currboard, FN_TICKET); - setbfile(fn_ticket_end, currboard, FN_TICKET_END); - setbfile(genbuf, currboard, FN_TICKET_LOCK); - if(dashf(fn_ticket)) - { - getdata(b_lines - 1, 0, "¤w¸g¦³Á|¿ì½ä½L, " - "¬O§_n [°±¤î¤Uª`]?(N/y)¡G", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - rename(fn_ticket, fn_ticket_end); - if(bp->endgamble) - { - bp->endgamble= 0; - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - - } - return FULLUPDATE; - } - - if(dashf(fn_ticket_end)) - { - getdata(b_lines - 1, 0, "¤w¸g¦³Á|¿ì½ä½L, " - "¬O§_n [¶}¼ú/¨ú®ø]?(N/y)¡G", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - openticket(currbid); - return FULLUPDATE; + void stop_gamble() { + boardheader_t *bp = getbcache(currbid); + char fn_ticket[128], fn_ticket_end[128]; + if (!bp->endgamble || bp->endgamble > now) + return; + + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { + bp->endgamble = 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } } - else if(dashf(genbuf)) - { - move(b_lines-1,0); - prints(" ¥Ø«e¨t²Î¥¿¦b³B²z¶}¼ú¨Æ©y, ½Ðµ²ªG¥XÄl«á¦AÁ|¿ì......."); - pressanykey(); - return FULLUPDATE; + static int join_gamble(int ent, fileheader_t * fhdr, char *direct){ + if (!HAS_PERM(PERM_LOGINOK)) + return DONOTHING; + stop_gamble(); + ticket(currbid); + return FULLUPDATE; } - getdata(b_lines - 2, 0, "nÁ|¿ì½ä½L (N/y):", yn, 3, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - getdata(b_lines - 1, 0, "½ä¤°»ò? ½Ð¿é¤J¥DÃD (¿é¤J«á½s¿è¤º®e):", - msg, 20, DOECHO); - if(msg[0]==0 || - vedit(fn_ticket_end, NA, NULL)<0) - return FULLUPDATE; - - clear(); - showtitle("Á|¿ì½ä½L",BBSNAME); - setbfile(genbuf, currboard, FN_TICKET_ITEMS); - -// sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); - - if(!(fp=fopen(genbuf,"w"))) return FULLUPDATE; - do - { - getdata(2, 0, "¿é¤J±m²¼»ù®æ (»ù®æ:10-10000):",yn,6, LCECHO); - i=atoi(yn); - } while( i<10 || i>10000); - fprintf(fp,"%d\n",i); - if(!getdata(3,0,"³]©w¦Û°Ê«Ê½L®É¶¡?(Y/n)",yn,3,LCECHO) || yn[0]!='n') - { - bp->endgamble= gettime(4, now); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + static int hold_gamble(int ent, fileheader_t * fhdr, char *direct){ + char fn_ticket[128], fn_ticket_end[128], genbuf[128], msg[256] = "", + yn[10] = ""; + boardheader_t *bp = getbcache(currbid); + int i; + FILE *fp = NULL; + + if (!(currmode & MODE_BOARD)) + return 0; + setbfile(fn_ticket, currboard, FN_TICKET); + setbfile(fn_ticket_end, currboard, FN_TICKET_END); + setbfile(genbuf, currboard, FN_TICKET_LOCK); + if (dashf(fn_ticket)) { + getdata(b_lines - 1, 0, "¤w¸g¦³Á|¿ì½ä½L, " + "¬O§_n [°±¤î¤Uª`]?(N/y)¡G", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + rename(fn_ticket, fn_ticket_end); + if (bp->endgamble) { + bp->endgamble = 0; + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + + } + return FULLUPDATE; + } + if (dashf(fn_ticket_end)) { + getdata(b_lines - 1, 0, "¤w¸g¦³Á|¿ì½ä½L, " + "¬O§_n [¶}¼ú/¨ú®ø]?(N/y)¡G", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + openticket(currbid); + return FULLUPDATE; + } else if (dashf(genbuf)) { + move(b_lines - 1, 0); + prints(" ¥Ø«e¨t²Î¥¿¦b³B²z¶}¼ú¨Æ©y, ½Ðµ²ªG¥XÄl«á¦AÁ|¿ì......."); + pressanykey(); + return FULLUPDATE; + } + getdata(b_lines - 2, 0, "nÁ|¿ì½ä½L (N/y):", yn, 3, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + getdata(b_lines - 1, 0, "½ä¤°»ò? ½Ð¿é¤J¥DÃD (¿é¤J«á½s¿è¤º®e):", + msg, 20, DOECHO); + if (msg[0] == 0 || + vedit(fn_ticket_end, NA, NULL) < 0) + return FULLUPDATE; + + clear(); + showtitle("Á|¿ì½ä½L", BBSNAME); + setbfile(genbuf, currboard, FN_TICKET_ITEMS); + + //sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + + if (!(fp = fopen(genbuf, "w"))) + return FULLUPDATE; + do { + getdata(2, 0, "¿é¤J±m²¼»ù®æ (»ù®æ:10-10000):", yn, 6, LCECHO); + i = atoi(yn); + } while (i < 10 || i > 10000); + fprintf(fp, "%d\n", i); + if (!getdata(3, 0, "³]©w¦Û°Ê«Ê½L®É¶¡?(Y/n)", yn, 3, LCECHO) || yn[0] != 'n') { + bp->endgamble = gettime(4, now); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + } + move(6, 0); + sprintf(genbuf, "½Ð¨ì %s ªO «ö'f'°Ñ»P½ä³Õ!\n\n¤@±i %d Ptt¹ô, ³o¬O%sªº½ä³Õ\n%s%s", + currboard, + i, i < 100 ? "¤p½ä¦¡" : i < 500 ? "¥¥Á¯Å" : + i < 1000 ? "¶Q±Ú¯Å" : i < 5000 ? "´I»¨¯Å" : "¶É®a¿º²£", + bp->endgamble ? "½ä½Lµ²§ô®É¶¡: " : "", + bp->endgamble ? Cdate(&bp->endgamble) : "" + ); + strcat(msg, genbuf); + prints("½Ð¨Ì¦¸¿é¤J±m²¼¦WºÙ, »Ý´£¨Ñ2~8¶µ. (¥¼º¡¤K¶µ, ¿é¤Jª½±µ«öenter)\n"); + for (i = 0; i < 8; i++) { + sprintf(yn, " %d)", i + 1); + getdata(7 + i, 0, yn, genbuf, 9, DOECHO); + if (!genbuf[0] && i > 1) + break; + fprintf(fp, "%s\n", genbuf); + } + fclose(fp); + move(8 + i, 0); + prints("½ä½L³]©w§¹¦¨"); + sprintf(genbuf, "[¤½§i] %s ªO ¶}©l½ä³Õ!", currboard); + post_msg(currboard, genbuf, msg, cuser.userid); + post_msg("Record", genbuf + 7, msg, "[°¨¸ô±´¤l]"); + /* Tim ±±¨îCS, ¥H§K¥¿¦bª±ªºuser§â¸ê®Æ¤w¸g¼g¶i¨Ó */ + rename(fn_ticket_end, fn_ticket); + //³] © w § ¹¤~§âÀɦW § ï¹L ¨ Ó + + return FULLUPDATE; } - move(6,0); -sprintf(genbuf,"½Ð¨ì %s ªO «ö'f'°Ñ»P½ä³Õ!\n\n¤@±i %d Ptt¹ô, ³o¬O%sªº½ä³Õ\n%s%s", - currboard, - i, i<100 ? "¤p½ä¦¡" : i<500 ? "¥¥Á¯Å": - i<1000 ?"¶Q±Ú¯Å" : i<5000 ?"´I»¨¯Å" : "¶É®a¿º²£", - bp->endgamble?"½ä½Lµ²§ô®É¶¡: ":"", - bp->endgamble?Cdate(&bp->endgamble):"" - ); - strcat(msg, genbuf); - prints("½Ð¨Ì¦¸¿é¤J±m²¼¦WºÙ, »Ý´£¨Ñ2~8¶µ. (¥¼º¡¤K¶µ, ¿é¤Jª½±µ«öenter)\n"); - for(i=0; i<8; i++) - { - sprintf(yn, " %d)",i+1); - getdata(7+i, 0, yn, genbuf, 9, DOECHO); - if(!genbuf[0] && i>1) - break; - fprintf(fp,"%s\n",genbuf); - } - fclose(fp); - move(8+i,0); - prints("½ä½L³]©w§¹¦¨"); - sprintf(genbuf,"[¤½§i] %s ªO ¶}©l½ä³Õ!", currboard); - post_msg(currboard, genbuf, msg, cuser.userid); - post_msg("Record", genbuf+7, msg, "[°¨¸ô±´¤l]"); - /* Tim ±±¨îCS, ¥H§K¥¿¦bª±ªºuser§â¸ê®Æ¤w¸g¼g¶i¨Ó */ - rename(fn_ticket_end, fn_ticket); // ³]©w§¹¤~§âÀɦW§ï¹L¨Ó - - return FULLUPDATE; -} #endif -static int cite_post(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN + 1]; - - setbfile(fpath, currboard, fhdr->filename); - strcpy(title, "¡º "); - strncpy(title+3, fhdr->title, TTLEN-3); - title[TTLEN] = '\0'; - a_copyitem(fpath, title, 0, 1); - b_man(); - return FULLUPDATE; -} + static int cite_post(int ent, fileheader_t * fhdr, char *direct){ + char fpath[256]; + char title[TTLEN + 1]; + + setbfile(fpath, currboard, fhdr->filename); + strcpy(title, "¡º "); + strncpy(title + 3, fhdr->title, TTLEN - 3); + title[TTLEN] = '\0'; + a_copyitem(fpath, title, 0, 1); + b_man(); + return FULLUPDATE; + } + + int edit_title(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + fileheader_t tmpfhdr = *fhdr; + int dirty = 0; -int edit_title(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - fileheader_t tmpfhdr = *fhdr; - int dirty = 0; + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + if (getdata(b_lines - 1, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO)) { + strcpy(tmpfhdr.title, genbuf); + dirty++; + } + } + if (HAS_PERM(PERM_SYSOP)) { + if (getdata(b_lines - 1, 0, "§@ªÌ¡G", genbuf, IDLEN + 2, DOECHO)) { + strcpy(tmpfhdr.owner, genbuf); + dirty++; + } + if (getdata(b_lines - 1, 0, "¤é´Á¡G", genbuf, 6, DOECHO)) { + sprintf(tmpfhdr.date, "%.5s", genbuf); + dirty++; + } + } + if (currmode & MODE_BOARD || !strcmp(cuser.userid, fhdr->owner)) { + getdata(b_lines - 1, 0, "½T©w(Y/N)?[n] ", genbuf, 3, DOECHO); + if ((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { + *fhdr = tmpfhdr; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + /* rocker.011018: ³o¸ÌÀ³¸Ó§ï¦¨¥Îreferenceªº¤è¦¡¨ú±oì¨ÓªºÀÉ®× */ + substitute_check(fhdr); + touchdircache(currbid); + } + return FULLUPDATE; + } + return DONOTHING; + } - if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { - if(getdata(b_lines - 1, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO)) { - strcpy(tmpfhdr.title, genbuf); - dirty++; - } + static int solve_post(int ent, fileheader_t * fhdr, char *direct){ + if (HAS_PERM(PERM_SYSOP)) { + fhdr->filemode ^= FILE_SOLVED; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + return PART_REDRAW; + } + return DONOTHING; } - if(HAS_PERM(PERM_SYSOP)) { - if(getdata(b_lines - 1, 0, "§@ªÌ¡G", genbuf, IDLEN + 2, DOECHO)) { - strcpy(tmpfhdr.owner, genbuf); - dirty++; - } - - if(getdata(b_lines - 1, 0, "¤é´Á¡G", genbuf, 6, DOECHO)) { - sprintf(tmpfhdr.date, "%.5s", genbuf); - dirty++; - } + static int recommend_cancel(int ent, fileheader_t * fhdr, char *direct){ + char yn[5]; + if (!(currmode & MODE_BOARD)) + return DONOTHING; + getdata(b_lines - 1, 0, "½T©wn±ÀÂËÂk¹s(Y/N)?[n] ", yn, 5, LCECHO); + if (yn[0] != 'y') + return FULLUPDATE; + fhdr->recommend = 0; + + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_check(fhdr); + touchdircache(currbid); + return FULLUPDATE; } + static int recommend(int ent, fileheader_t * fhdr, char *direct){ + struct tm *ptime = localtime(&now); + char buf[200], path[200], yn[5]; + boardheader_t *bp; + bp = getbcache(currbid); + + if (!(currmode & MODE_POST) || !strcmp(fhdr->owner, cuser.userid) || + bp->brdattr & BRD_VOTEBOARD) { + move(b_lines - 1, 0); + prints("±z¦]Åv¤£¨¬µLªk±ÀÂË ©Î ¤£¯à±ÀÂ˦ۤvªº¤å³¹!"); + pressanykey(); + return FULLUPDATE; + } + if (fhdr->recommend > 9 || fhdr->recommend < 0) + //¼È®É©Êªºcode ì¨Ó¦³È¨ú®ø + fhdr->recommend = 0; + + if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && + now - xuser.recommend < 60) { + move(b_lines - 1, 0); + prints("Â÷¤W¦¸±ÀÂˮɶ¡¤ÓªñÅo, ½Ð¦hªáÂI®É¶¡¥J²Ó¾\\Ū¤å³¹!"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(b_lines - 2, 0, "±ÀÂË»y:", path, 40, DOECHO) || + !getdata(b_lines - 1, 0, "½T©wn±ÀÂË, ½Ð¥J²Ó¦Ò¼{(Y/N)?[n] ", yn, 5, LCECHO) + || yn[0] != 'y') + return FULLUPDATE; - if(currmode & MODE_BOARD || !strcmp(cuser.userid,fhdr->owner)) { - getdata(b_lines-1, 0, "½T©w(Y/N)?[n] ", genbuf, 3, DOECHO); - if((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { - *fhdr = tmpfhdr; + sprintf(buf, + "\033[1;31m¡÷ \033[33m%s\033[m\033[33m:%s\033[m%*s±ÀÂ˦Û:%s %02d/%02d\n", + cuser.userid, path, + 45 - strlen(cuser.userid) - strlen(path), " ", fromhost, + ptime->tm_mon + 1, ptime->tm_mday); + setdirpath(path, direct, fhdr->filename); + log_file(path, buf); + if (fhdr->recommend < 9) { + fhdr->recommend++; + cuser.recommend = now; + passwd_update(usernum, &cuser); substitute_record(direct, fhdr, sizeof(*fhdr), ent); -/* rocker.011018: ³o¸ÌÀ³¸Ó§ï¦¨¥Îreferenceªº¤è¦¡¨ú±oì¨ÓªºÀÉ®× */ - substitute_check(fhdr); - touchdircache(currbid); + substitute_check(fhdr); + touchdircache(currbid); } return FULLUPDATE; } - return DONOTHING; -} + static int mark_post(int ent, fileheader_t * fhdr, char *direct){ + + if (!(currmode & MODE_BOARD)) + return DONOTHING; -static int solve_post(int ent, fileheader_t * fhdr, char *direct){ - if (HAS_PERM(PERM_SYSOP)) { - fhdr->filemode ^= FILE_SOLVED; + fhdr->filemode ^= FILE_MARKED; substitute_record(direct, fhdr, sizeof(*fhdr), ent); - touchdircache(currbid); + substitute_check(fhdr); + touchdircache(currbid); return PART_REDRAW; } - return DONOTHING; -} - -static int recommend_cancel(int ent, fileheader_t *fhdr, char *direct) { - char yn[5]; - if (!(currmode & MODE_BOARD)) return DONOTHING; - getdata(b_lines-1, 0, "½T©wn±ÀÂËÂk¹s(Y/N)?[n] ", yn, 5, LCECHO); - if(yn[0]!='y') return FULLUPDATE; - fhdr->recommend=0; - - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - return FULLUPDATE; -} -static int recommend(int ent, fileheader_t *fhdr, char *direct) { - struct tm *ptime=localtime(&now); - char buf[200],path[200], yn[5]; - boardheader_t *bp; - bp = getbcache(currbid); - - if(!(currmode & MODE_POST) || !strcmp(fhdr->owner,cuser.userid) || - bp->brdattr & BRD_VOTEBOARD) - { - move(b_lines-1,0); - prints("±z¦]Åv¤£¨¬µLªk±ÀÂË ©Î ¤£¯à±ÀÂ˦ۤvªº¤å³¹!"); - pressanykey(); - return FULLUPDATE; - } - if(fhdr->recommend>9 || fhdr->recommend<0 )// ¼È®É©Êªºcode ì¨Ó¦³È¨ú®ø - fhdr->recommend=0; - - if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - xuser.recommend < 60 ) - { - move(b_lines-1,0); - prints("Â÷¤W¦¸±ÀÂˮɶ¡¤ÓªñÅo, ½Ð¦hªáÂI®É¶¡¥J²Ó¾\\Ū¤å³¹!"); - pressanykey(); - return FULLUPDATE; - } - - if(!getdata(b_lines-2, 0, "±ÀÂË»y:",path,40,DOECHO) || - !getdata(b_lines-1, 0, "½T©wn±ÀÂË, ½Ð¥J²Ó¦Ò¼{(Y/N)?[n] ", yn, 5,LCECHO) - || yn[0]!='y') return FULLUPDATE; - - sprintf(buf, - "\033[1;31m¡÷ \033[33m%s\033[m\033[33m:%s\033[m%*s±ÀÂ˦Û:%s %02d/%02d\n", - cuser.userid, path, - 45-strlen(cuser.userid)-strlen(path), " ",fromhost, - ptime->tm_mon+1,ptime->tm_mday) ; - setdirpath(path, direct, fhdr->filename); - log_file(path, buf); - if(fhdr->recommend<9) - { - fhdr->recommend++; - cuser.recommend=now; - passwd_update(usernum, &cuser); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - } - return FULLUPDATE; -} -static int mark_post(int ent, fileheader_t *fhdr, char *direct) { - if(!(currmode & MODE_BOARD)) return DONOTHING; + int del_range(int ent, fileheader_t * fhdr, char *direct){ + char num1[8], num2[8]; + int inum1, inum2; + boardheader_t *bp; + bp = getbcache(currbid); - fhdr->filemode ^= FILE_MARKED; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); - touchdircache(currbid); - return PART_REDRAW; -} - -int del_range(int ent, fileheader_t *fhdr, char *direct) { - char num1[8], num2[8]; - int inum1, inum2; - boardheader_t *bp; - bp = getbcache(currbid); - -/* rocker.011018: ¦ê±µ¼Ò¦¡¤UÁÙ¬O¤£¤¹³\§R°£¤ñ¸û¦n */ - if(currmode & MODE_SELECT) { + /* rocker.011018: ¦ê±µ¼Ò¦¡¤UÁÙ¬O¤£¤¹³\§R°£¤ñ¸û¦n */ + if (currmode & MODE_SELECT) { outmsg("½Ð¥ý¦^¨ì¥¿±`¼Ò¦¡«á¦A¶i¦æ§R°£..."); refresh(); - /*safe_sleep(1);*/ - return FULLUPDATE; - } - if ( strcmp( bp->brdname, "Security") == 0 ) - return DONOTHING; - if((currstat != READING) || (currmode & MODE_BOARD)) { - getdata(1, 0, "[³]©w§R°£½d³ò] °_ÂI¡G", num1, 5, DOECHO); - inum1 = atoi(num1); - if(inum1 <= 0) { - outmsg("°_ÂI¦³»~"); - refresh(); - /*safe_sleep(1);*/ - return FULLUPDATE; - } - getdata(1, 28, "²×ÂI¡G", num2, 5, DOECHO); - inum2 = atoi(num2); - if(inum2 < inum1) { - outmsg("²×ÂI¦³»~"); - refresh(); - /*safe_sleep(1);*/ + /* safe_sleep(1); */ return FULLUPDATE; } - getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); - if(*num1 == 'y') { - outmsg("³B²z¤¤,½Ðµy«á..."); - refresh(); - if(currmode & MODE_SELECT) { - int fd,size = sizeof(fileheader_t); - char genbuf[100]; - fileheader_t rsfh; - int i = inum1,now; - if(currstat == RMAIL) - sethomedir(genbuf, cuser.userid); - else - setbdir(genbuf,currboard); - if((fd = (open(direct, O_RDONLY, 0))) != -1) { - if(lseek(fd, (off_t)(size * (inum1 - 1)), SEEK_SET) != - -1) { - while(read(fd,&rsfh,size) == size) { - if(i > inum2) - break; - now = getindex(genbuf, rsfh.filename, size); - strcpy(currfile, rsfh.filename); - delete_file(genbuf, sizeof(fileheader_t), now, - cmpfilename); - i++; + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((currstat != READING) || (currmode & MODE_BOARD)) { + getdata(1, 0, "[³]©w§R°£½d³ò] °_ÂI¡G", num1, 5, DOECHO); + inum1 = atoi(num1); + if (inum1 <= 0) { + outmsg("°_ÂI¦³»~"); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + getdata(1, 28, "²×ÂI¡G", num2, 5, DOECHO); + inum2 = atoi(num2); + if (inum2 < inum1) { + outmsg("²×ÂI¦³»~"); + refresh(); + /* safe_sleep(1); */ + return FULLUPDATE; + } + getdata(1, 48, msg_sure_ny, num1, 3, LCECHO); + if (*num1 == 'y') { + outmsg("³B²z¤¤,½Ðµy«á..."); + refresh(); + if (currmode & MODE_SELECT) { + int fd, size = sizeof(fileheader_t); + char genbuf[100]; + fileheader_t rsfh; + int i = inum1, now; + if (currstat == RMAIL) + sethomedir(genbuf, cuser.userid); + else + setbdir(genbuf, currboard); + if ((fd = (open(direct, O_RDONLY, 0))) != -1) { + if (lseek(fd, (off_t) (size * (inum1 - 1)), SEEK_SET) != + -1) { + while (read(fd, &rsfh, size) == size) { + if (i > inum2) + break; + now = getindex(genbuf, rsfh.filename, size); + strcpy(currfile, rsfh.filename); + delete_file(genbuf, sizeof(fileheader_t), now, + cmpfilename); + i++; + } } + close(fd); } - close(fd); } - } - - delete_range(direct, inum1, inum2); - fixkeep(direct, inum1); - - if(currmode & MODE_BOARD) - setbtotal(currbid); - - return DIRCHANGED; - } - return FULLUPDATE; - } - return DONOTHING; -} + delete_range(direct, inum1, inum2); + fixkeep(direct, inum1); -static int del_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[100]; - int not_owned; - boardheader_t *bp; - - bp = getbcache(currbid); - if ( strcmp(bp->brdname, "Security") == 0 ) - return DONOTHING; - if((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || - (fhdr->owner[0] == '-')) - return DONOTHING; + if (currmode & MODE_BOARD) + setbtotal(currbid); - not_owned = strcmp(fhdr->owner, cuser.userid); - if((!(currmode & MODE_BOARD) && not_owned) || - ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || - !strcmp(cuser.userid, STR_GUEST)) + return DIRCHANGED; + } + return FULLUPDATE; + } return DONOTHING; + } - getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if(genbuf[0] == 'y' || genbuf[0] == 'Y') { - strcpy(currfile, fhdr->filename); - - setbfile(genbuf,currboard,fhdr->filename); - if(!delete_file (direct, sizeof(fileheader_t), ent, cmpfilename)) { - - if(currmode & MODE_SELECT) - { - /* rocker.011018: §Q¥Îreference´î§Cloading */ - fileheader_t hdr; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ - if (strcmp (hdr.filename, fhdr->filename)) - { - num=getindex(genbuf,fhdr->filename,sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof (hdr), num); + static int del_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[100]; + int not_owned; + boardheader_t *bp; + + bp = getbcache(currbid); + if (strcmp(bp->brdname, "Security") == 0) + return DONOTHING; + if ((fhdr->filemode & FILE_MARKED) || (fhdr->filemode & FILE_DIGEST) || + (fhdr->owner[0] == '-')) + return DONOTHING; + + not_owned = strcmp(fhdr->owner, cuser.userid); + if ((!(currmode & MODE_BOARD) && not_owned) || + ((bp->brdattr & BRD_VOTEBOARD) && !HAS_PERM(PERM_SYSOP)) || + !strcmp(cuser.userid, STR_GUEST)) + return DONOTHING; + + getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); + if (genbuf[0] == 'y' || genbuf[0] == 'Y') { + strcpy(currfile, fhdr->filename); + + setbfile(genbuf, currboard, fhdr->filename); + if (!delete_file(direct, sizeof(fileheader_t), ent, cmpfilename)) { + + if (currmode & MODE_SELECT) { + /* rocker.011018: §Q¥Îreference´î§Cloading */ + fileheader_t hdr; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); + } + /* rocker.011018: ³o¸ÌnÁÙì³Q¯}Ãaªºmoney */ + fhdr->money = hdr.money; + delete_file(genbuf, sizeof(fileheader_t), num, cmpfilename); } + cancelpost(fhdr, not_owned); - /* rocker.011018: ³o¸ÌnÁÙì³Q¯}Ãaªºmoney */ - fhdr->money = hdr.money; - delete_file (genbuf, sizeof(fileheader_t), num, cmpfilename); - } - - cancelpost(fhdr, not_owned); - - setbtotal(currbid); - if (fhdr->money < 0) - fhdr->money = 0; - if (not_owned && strcmp(currboard, "Test")){ - deumoney(searchuser(fhdr->owner), -fhdr->money); - } - if(!not_owned && strcmp(currboard, "Test")) { - if(cuser.numposts) - cuser.numposts--; - move(b_lines - 1, 0); - clrtoeol(); - demoney(-fhdr->money); - passwd_update(usernum, &cuser); /* post ¼Æ */ - prints("%s¡A±zªº¤å³¹´î¬° %d ½g¡A¤ä¥I²M¼ä¶O %d »È", msg_del_ok, - cuser.numposts,fhdr->money); - refresh(); - pressanykey(); + setbtotal(currbid); + if (fhdr->money < 0) + fhdr->money = 0; + if (not_owned && strcmp(currboard, "Test")) { + deumoney(searchuser(fhdr->owner), -fhdr->money); + } + if (!not_owned && strcmp(currboard, "Test")) { + if (cuser.numposts) + cuser.numposts--; + move(b_lines - 1, 0); + clrtoeol(); + demoney(-fhdr->money); + passwd_update(usernum, &cuser); /* post ¼Æ */ + prints("%s¡A±zªº¤å³¹´î¬° %d ½g¡A¤ä¥I²M¼ä¶O %d »È", msg_del_ok, + cuser.numposts, fhdr->money); + refresh(); + pressanykey(); + } + return DIRCHANGED; } - return DIRCHANGED; } + return FULLUPDATE; } - return FULLUPDATE; -} - -static int view_postmoney(int ent, fileheader_t *fhdr, char *direct) { - move(b_lines - 1, 0); - clrtoeol(); - prints("³o¤@½g¤å³¹È %d »È", fhdr->money); - refresh(); - pressanykey(); - return FULLUPDATE; -} -#ifdef OUTJOBSPOOL -/* ¬ÝªO³Æ¥÷ */ -static int tar_addqueue(int ent, fileheader_t *fhdr, char *direct) { - char email[60], qfn[80], ans[2]; - FILE *fp; - char bakboard, bakman; - clear(); - showtitle("¬ÝªO³Æ¥÷", BBSNAME); - move(2, 0); - if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) ) { - move(5, 10); - outs("©pn¬OªO¥D©Î¬O¯¸ªø¤~¯àÂæÂæ°Ú -.-\"\""); - pressanykey(); - return FULLUPDATE; + static int view_postmoney(int ent, fileheader_t * fhdr, char *direct){ + move(b_lines - 1, 0); + clrtoeol(); + prints("³o¤@½g¤å³¹È %d »È", fhdr->money); + refresh(); + pressanykey(); + return FULLUPDATE; } - sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); - if( access(qfn, 0) == 0 ){ - outs("¤w¸g±Æ©w¦æµ{, µy«á·|¶i¦æ³Æ¥÷"); - pressanykey(); - return FULLUPDATE; - } - if( !getdata(4, 0, "½Ð¿é¤J¥Øªº«H½c¡G", email, sizeof(email), DOECHO) ) - return FULLUPDATE; - - /* check email -.-"" */ - if( strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL ){ - move(6, 0); - outs("±z«ü©wªº«H½c¤£¥¿½T! "); - pressanykey(); - return FULLUPDATE; - } +#ifdef OUTJOBSPOOL + /* ¬ÝªO³Æ¥÷ */ + static int tar_addqueue(int ent, fileheader_t * fhdr, char *direct){ + char email[60], qfn[80], ans[2]; + FILE *fp; + char bakboard, bakman; + clear(); + showtitle("¬ÝªO³Æ¥÷", BBSNAME); + move(2, 0); + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP))) { + move(5, 10); + outs("©pn¬OªO¥D©Î¬O¯¸ªø¤~¯àÂæÂæ°Ú -.-\"\""); + pressanykey(); + return FULLUPDATE; + } + sprintf(qfn, BBSHOME "/jobspool/tarqueue.%s", currboard); + if (access(qfn, 0) == 0) { + outs("¤w¸g±Æ©w¦æµ{, µy«á·|¶i¦æ³Æ¥÷"); + pressanykey(); + return FULLUPDATE; + } + if (!getdata(4, 0, "½Ð¿é¤J¥Øªº«H½c¡G", email, sizeof(email), DOECHO)) + return FULLUPDATE; - getdata(6, 0, "n³Æ¥÷¬ÝªO¤º®e¶Ü(Y/N)?[Y]", ans, sizeof(ans), LCECHO); - bakboard = (ans[0] == 'n' || ans[0] =='N') ? 0 : 1; - getdata(7, 0, "n³Æ¥÷ºëµØ°Ï¤º®e¶Ü(Y/N)?[N]", ans, sizeof(ans), LCECHO); - bakman = (ans[0] == 'y' || ans[0] =='Y') ? 1 : 0; - if( !bakboard && !bakman ){ - move(8, 0); - outs("¥i¬O§ÚÌ¥u¯à³Æ¥÷¬ÝªO©ÎºëµØ°ÏªºC ^^\"\"\""); - pressanykey(); - return FULLUPDATE; + /* check email -.-"" */ + if (strstr(email, "@") == NULL || strstr(email, ".bbs@") != NULL) { + move(6, 0); + outs("±z«ü©wªº«H½c¤£¥¿½T! "); + pressanykey(); + return FULLUPDATE; + } + getdata(6, 0, "n³Æ¥÷¬ÝªO¤º®e¶Ü(Y/N)?[Y]", ans, sizeof(ans), LCECHO); + bakboard = (ans[0] == 'n' || ans[0] == 'N') ? 0 : 1; + getdata(7, 0, "n³Æ¥÷ºëµØ°Ï¤º®e¶Ü(Y/N)?[N]", ans, sizeof(ans), LCECHO); + bakman = (ans[0] == 'y' || ans[0] == 'Y') ? 1 : 0; + if (!bakboard && !bakman) { + move(8, 0); + outs("¥i¬O§ÚÌ¥u¯à³Æ¥÷¬ÝªO©ÎºëµØ°ÏªºC ^^\"\"\""); + pressanykey(); + return FULLUPDATE; + } + fp = fopen(qfn, "w"); + fprintf(fp, "%s\n", cuser.userid); + fprintf(fp, "%s\n", email); + fprintf(fp, "%d,%d\n", bakboard, bakman); + fclose(fp); + + move(10, 0); + outs("¨t²Î¤w¸g±N±zªº³Æ¥÷±Æ¤J¦æµ{, \n"); + outs("µy«á±N·|¦b¨t²Ît²ü¸û§Cªº®ÉÔ±N¸ê®Æ±Hµ¹±z~ :) "); + pressanykey(); + return FULLUPDATE; } +#endif - fp = fopen(qfn, "w"); - fprintf(fp, "%s\n", cuser.userid); - fprintf(fp, "%s\n", email); - fprintf(fp, "%d,%d\n", bakboard, bakman); - fclose(fp); + static int sequent_ent; + static int continue_flag; - move(10, 0); - outs("¨t²Î¤w¸g±N±zªº³Æ¥÷±Æ¤J¦æµ{, \n"); - outs("µy«á±N·|¦b¨t²Ît²ü¸û§Cªº®ÉÔ±N¸ê®Æ±Hµ¹±z~ :) "); - pressanykey(); - return FULLUPDATE; -} -#endif + /* ----------------------------------------------------- */ + /* ¨Ì§ÇŪ·s¤å³¹ */ + /* ----------------------------------------------------- */ + static int sequent_messages(fileheader_t * fptr) { + static int idc; + char genbuf[200]; -static int sequent_ent; -static int continue_flag; + if (fptr == NULL) + return (idc = 0); -/* ----------------------------------------------------- */ -/* ¨Ì§ÇŪ·s¤å³¹ */ -/* ----------------------------------------------------- */ -static int sequent_messages(fileheader_t *fptr) { - static int idc; - char genbuf[200]; + if (++idc < sequent_ent) + return 0; - if(fptr == NULL) - return (idc = 0); + if (!brc_unread(fptr->filename, brc_num, brc_list)) + return 0; - if(++idc < sequent_ent) - return 0; + if (continue_flag) + genbuf[0] = 'y'; + else { + prints("Ū¨ú¤å³¹©ó¡G[%s] §@ªÌ¡G[%s]\n¼ÐÃD¡G[%s]", + currboard, fptr->owner, fptr->title); + getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); + } - if(!brc_unread(fptr->filename,brc_num,brc_list)) - return 0; + if (genbuf[0] != 'y' && genbuf[0]) { + clear(); + return (genbuf[0] == 'q' ? QUIT : 0); + } + setbfile(genbuf, currboard, fptr->filename); + brc_addlist(fptr->filename); + + if (more(genbuf, YEA) == 0) + outmsg("\033[31;47m \033[31m(R)\033[30m¦^«H \033[31m(¡õ,n)" + "\033[30m¤U¤@«Ê \033[31m(¡ö,q)\033[30mÂ÷¶} \033[m"); + continue_flag = 0; + + switch (egetch()) { + case KEY_LEFT: + case 'e': + case 'q': + case 'Q': + break; + + case 'y': + case 'r': + case 'Y': + case 'R': + if (currmode & MODE_POST) { + strcpy(quote_file, genbuf); + do_reply(fptr); + *quote_file = 0; + } + break; - if(continue_flag) - genbuf[0] = 'y'; - else { - prints("Ū¨ú¤å³¹©ó¡G[%s] §@ªÌ¡G[%s]\n¼ÐÃD¡G[%s]", - currboard, fptr->owner, fptr->title); - getdata(3, 0, "(Y/N/Quit) [Y]: ", genbuf, 3, LCECHO); - } + case ' ': + case KEY_DOWN: + case '\n': + case 'n': + continue_flag = 1; + } - if(genbuf[0] != 'y' && genbuf[0]) { clear(); - return (genbuf[0] == 'q' ? QUIT : 0); + return 0; } - setbfile(genbuf, currboard, fptr->filename); - brc_addlist(fptr->filename); + static int sequential_read(int ent, fileheader_t * fhdr, char *direct){ + char buf[40]; - if(more(genbuf, YEA) == 0) - outmsg("\033[31;47m \033[31m(R)\033[30m¦^«H \033[31m(¡õ,n)" - "\033[30m¤U¤@«Ê \033[31m(¡ö,q)\033[30mÂ÷¶} \033[m"); - continue_flag = 0; + clear(); + sequent_messages((fileheader_t *) NULL); + sequent_ent = ent; + continue_flag = 0; + setbdir(buf, currboard); + apply_record(buf, sequent_messages, sizeof(fileheader_t)); + return FULLUPDATE; + } - switch(egetch()) { - case KEY_LEFT: - case 'e': - case 'q': - case 'Q': - break; - - case 'y': - case 'r': - case 'Y': - case 'R': - if(currmode & MODE_POST) { - strcpy(quote_file, genbuf); - do_reply(fptr); - *quote_file = 0; + /* ----------------------------------------------------- */ + /* ¬ÝªO³Æ§Ñ¿ý¡B¤åºK¡BºëµØ°Ï */ + /* ----------------------------------------------------- */ + int b_note_edit_bname(int bid){ + char buf[64]; + int aborted; + boardheader_t *fh = getbcache(bid); + setbfile(buf, fh->brdname, fn_notes); + aborted = vedit(buf, NA, NULL); + if (aborted == -1) { + clear(); + outs(msg_cancel); + pressanykey(); + } else { + if (!getdata(2, 0, "³]©w¦³®Ä´Á¤Ñ¡H(n/Y)", buf, 3, LCECHO) + || buf[0] != 'n') + fh->bupdate = gettime(3, fh->bupdate ? fh->bupdate : now); + else + fh->bupdate = 0; + substitute_record(fn_board, fh, sizeof(boardheader_t), bid); } - break; - - case ' ': - case KEY_DOWN: - case '\n': - case 'n': - continue_flag = 1; + return 0; } - clear(); - return 0; -} - -static int sequential_read(int ent, fileheader_t *fhdr, char *direct) { - char buf[40]; - - clear(); - sequent_messages((fileheader_t *) NULL); - sequent_ent = ent; - continue_flag = 0; - setbdir(buf, currboard); - apply_record(buf, sequent_messages, sizeof(fileheader_t)); - return FULLUPDATE; -} - -/* ----------------------------------------------------- */ -/* ¬ÝªO³Æ§Ñ¿ý¡B¤åºK¡BºëµØ°Ï */ -/* ----------------------------------------------------- */ -int b_note_edit_bname(int bid) { - char buf[64]; - int aborted; - boardheader_t *fh=getbcache(bid); - setbfile(buf, fh->brdname, fn_notes); - aborted = vedit(buf, NA, NULL); - if(aborted == -1) { - clear(); - outs(msg_cancel); - pressanykey(); - } else { - if(!getdata(2, 0, "³]©w¦³®Ä´Á¤Ñ¡H(n/Y)", buf, 3, LCECHO) - || buf[0]!='n') - fh->bupdate = gettime(3, fh->bupdate?fh->bupdate:now); - else - fh->bupdate = 0; - substitute_record(fn_board, fh, sizeof(boardheader_t), bid); + static int b_notes_edit() { + if (currmode & MODE_BOARD) { + b_note_edit_bname(currbid); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_notes_edit() { - if(currmode & MODE_BOARD) { - b_note_edit_bname(currbid); - return FULLUPDATE; + static int b_water_edit() { + if (currmode & MODE_BOARD) { + friend_edit(BOARD_WATER); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_water_edit() { - if(currmode & MODE_BOARD) { - friend_edit(BOARD_WATER); - return FULLUPDATE; + static int visable_list_edit() { + if (currmode & MODE_BOARD) { + friend_edit(BOARD_VISABLE); + hbflreload(currbid); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int visable_list_edit() { - if(currmode & MODE_BOARD) { - friend_edit(BOARD_VISABLE); - hbflreload(currbid); - return FULLUPDATE; - } - return 0; -} + static int b_post_note() { + char buf[200], yn[3]; -static int b_post_note() { - char buf[200], yn[3]; - - if(currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_POST_NOTE ); - if(more(buf,NA) == -1) more("etc/"FN_POST_NOTE , NA); - getdata(b_lines - 2, 0, "¬O§_n¥Î¦Ûqpostª`·N¨Æ¶µ?", yn, sizeof(yn), LCECHO); - if(yn[0] == 'y') - vedit(buf, NA, NULL); - else - unlink(buf); - return FULLUPDATE; + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_POST_NOTE); + if (more(buf, NA) == -1) + more("etc/" FN_POST_NOTE, NA); + getdata(b_lines - 2, 0, "¬O§_n¥Î¦Ûqpostª`·N¨Æ¶µ?", yn, sizeof(yn), LCECHO); + if (yn[0] == 'y') + vedit(buf, NA, NULL); + else + unlink(buf); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int b_application() { - char buf[200]; + static int b_application() { + char buf[200]; - if(currmode & MODE_BOARD) { - setbfile(buf, currboard, FN_APPLICATION); - vedit(buf, NA, NULL); - return FULLUPDATE; + if (currmode & MODE_BOARD) { + setbfile(buf, currboard, FN_APPLICATION); + vedit(buf, NA, NULL); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int can_vote_edit() { - if(currmode & MODE_BOARD) { - friend_edit(FRIEND_CANVOTE); - return FULLUPDATE; + static int can_vote_edit() { + if (currmode & MODE_BOARD) { + friend_edit(FRIEND_CANVOTE); + return FULLUPDATE; + } + return 0; } - return 0; -} -static int bh_title_edit() { - boardheader_t *bp; + static int bh_title_edit() { + boardheader_t *bp; + + if (currmode & MODE_BOARD) { + char genbuf[BTLEN]; + + bp = getbcache(currbid); + move(1, 0); + clrtoeol(); + getdata_str(1, 0, "½Ð¿é¤J¬ÝªO·s¤¤¤å±Ôz:", genbuf, + BTLEN - 16, DOECHO, bp->title + 7); + + if (!genbuf[0]) + return 0; + strip_ansi(genbuf, genbuf, 0); + strcpy(bp->title + 7, genbuf); + substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); + log_usies("SetBoard", currboard); + return FULLUPDATE; + } + return 0; + } - if(currmode & MODE_BOARD) { - char genbuf[BTLEN]; + static int b_notes() { + char buf[64]; - bp = getbcache(currbid); - move(1,0); - clrtoeol(); - getdata_str(1,0,"½Ð¿é¤J¬ÝªO·s¤¤¤å±Ôz:", genbuf, - BTLEN - 16, DOECHO, bp->title + 7); - - if(!genbuf[0]) - return 0; - strip_ansi( genbuf,genbuf,0); - strcpy(bp->title + 7,genbuf); - substitute_record(fn_board, bp, sizeof(boardheader_t), currbid); - log_usies("SetBoard", currboard); + setbfile(buf, currboard, fn_notes); + if (more(buf, NA) == -1) { + clear(); + move(4, 20); + outs("¥»¬ÝªO©|µL¡u³Æ§Ñ¿ý¡v¡C"); + } + pressanykey(); return FULLUPDATE; } - return 0; -} -static int b_notes() { - char buf[64]; - - setbfile(buf, currboard, fn_notes); - if(more(buf, NA) == -1) { - clear(); - move(4, 20); - outs("¥»¬ÝªO©|µL¡u³Æ§Ñ¿ý¡v¡C"); + int board_select() { + char fpath[80]; + char genbuf[100]; + + currmode &= ~MODE_SELECT; + sprintf(fpath, "SR.%s", cuser.userid); + setbfile(genbuf, currboard, fpath); + unlink(genbuf); + if (currstat == RMAIL) + sethomedir(currdirect, cuser.userid); + else + setbdir(currdirect, currboard); + return NEWDIRECT; } - pressanykey(); - return FULLUPDATE; -} -int board_select() { - char fpath[80]; - char genbuf[100]; + int board_digest() { + if (currmode & MODE_SELECT) + board_select(); + currmode ^= MODE_DIGEST; + if (currmode & MODE_DIGEST) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; - currmode &= ~MODE_SELECT; - sprintf(fpath, "SR.%s", cuser.userid); - setbfile(genbuf, currboard, fpath); - unlink(genbuf); - if(currstat == RMAIL) - sethomedir(currdirect, cuser.userid); - else setbdir(currdirect, currboard); - return NEWDIRECT; -} - -int board_digest() { - if(currmode & MODE_SELECT) - board_select(); - currmode ^= MODE_DIGEST; - if(currmode & MODE_DIGEST) - currmode &= ~MODE_POST; - else if (haspostperm(currboard)) - currmode |= MODE_POST; - - setbdir(currdirect, currboard); - return NEWDIRECT; -} + return NEWDIRECT; + } -int board_etc() { - if(!HAS_PERM(PERM_SYSOP)) - return DONOTHING; - currmode ^= MODE_ETC; - if(currmode & MODE_ETC) - currmode &= ~MODE_POST; - else if(haspostperm(currboard)) - currmode |= MODE_POST; - - setbdir(currdirect, currboard); - return NEWDIRECT; -} + int board_etc() { + if (!HAS_PERM(PERM_SYSOP)) + return DONOTHING; + currmode ^= MODE_ETC; + if (currmode & MODE_ETC) + currmode &= ~MODE_POST; + else if (haspostperm(currboard)) + currmode |= MODE_POST; -static int good_post(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; - char genbuf2[200]; - int delta = 0; + setbdir(currdirect, currboard); + return NEWDIRECT; + } - if((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) - return DONOTHING; + static int good_post(int ent, fileheader_t * fhdr, char *direct){ + char genbuf[200]; + char genbuf2[200]; + int delta = 0; + + if ((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) + return DONOTHING; + + if (fhdr->filemode & FILE_DIGEST) { + fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), -1000); + if (!(currmode & MODE_SELECT)) + fhdr->money -= 1000; + else + delta = -1000; + } + } else { + fileheader_t digest; + char *ptr, buf[64]; + + memcpy(&digest, fhdr, sizeof(digest)); + digest.filename[0] = 'G'; + strcpy(buf, direct); + ptr = strrchr(buf, '/') + 1; + ptr[0] = '\0'; + sprintf(genbuf, "%s%s", buf, digest.filename); + + if (dashf(genbuf)) + unlink(genbuf); - if(fhdr->filemode & FILE_DIGEST) { - fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); - if(!strcmp(currboard,"Note") || !strcmp(currboard,"PttBug") || - !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner),-1000); - if(!(currmode & MODE_SELECT)) - fhdr->money -= 1000; - else - delta = -1000; + digest.filemode = 0; + sprintf(genbuf2, "%s%s", buf, fhdr->filename); + Link(genbuf2, genbuf); + strcpy(ptr, fn_mandex); + append_record(buf, &digest, sizeof(digest)); + + fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; + if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || + !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { + deumoney(searchuser(fhdr->owner), 1000); + if (!(currmode & MODE_SELECT)) + fhdr->money += 1000; + else + delta = 1000; + } } - } else { - fileheader_t digest; - char *ptr, buf[64]; - - memcpy(&digest, fhdr, sizeof(digest)); - digest.filename[0] = 'G'; - strcpy(buf, direct); - ptr = strrchr(buf, '/') + 1; - ptr[0] = '\0'; - sprintf(genbuf, "%s%s", buf, digest.filename); - - if(dashf(genbuf)) unlink (genbuf); - - digest.filemode = 0; - sprintf(genbuf2, "%s%s", buf, fhdr->filename); - Link(genbuf2, genbuf); - strcpy(ptr, fn_mandex); - append_record(buf, &digest, sizeof(digest)); - - fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; - if(!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || - !strcmp(currboard,"Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), 1000); - if(!(currmode & MODE_SELECT)) fhdr->money += 1000; - else delta = 1000; + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + touchdircache(currbid); + /* rocker.011018: ¦ê±µ¼Ò¦¡¥Îreference¼W¶i®Ä²v */ + if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { + fileheader_t hdr; + char genbuf[100]; + int num; + + num = fhdr->money & ~FHR_REFERENCE; + setbdir(genbuf, currboard); + get_record(genbuf, &hdr, sizeof(hdr), num); + + /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ + if (strcmp(hdr.filename, fhdr->filename)) { + num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); + get_record(genbuf, &hdr, sizeof(hdr), num); + } + fhdr->money = hdr.money + delta; + + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); } + return PART_REDRAW; } - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - touchdircache(currbid); -/* rocker.011018: ¦ê±µ¼Ò¦¡¥Îreference¼W¶i®Ä²v */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) - { - fileheader_t hdr; - char genbuf[100]; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof (hdr), num); - - /* ¦A³o¸Ìncheck¤@¤Uì¨Óªºdir¸Ì±¬O¤£¬O¦³³Q¤H°Ê¹L... */ - if (strcmp (hdr.filename, fhdr->filename)) - { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof (hdr), num); - } - fhdr->money = hdr.money + delta; - - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } - return PART_REDRAW; -} -/* help for board reading */ -static char *board_help[] = { - "\0¥þ¥\\¯à¬ÝªO¾Þ§@»¡©ú", - "\01°ò¥»©R¥O", - "(p)(¡ô) ¤W²¾¤@½g¤å³¹ (^P) µoªí¤å³¹", - "(n)(¡õ) ¤U²¾¤@½g¤å³¹ (d) §R°£¤å³¹", - "(P)(PgUp) ¤W²¾¤@¶ (S) ¦ê³s¬ÛÃö¤å³¹", - "(N)(PgDn) ¤U²¾¤@¶ (##) ¸õ¨ì ## ¸¹¤å³¹", - "(r)(¡÷) ¾\\Ū¦¹½g¤å³¹ ($) ¸õ¨ì³Ì«á¤@½g¤å³¹", - "\01¶i¶¥©R¥O", - "(tab)/z ¤åºK¼Ò¦¡/ºëµØ°Ï (a/A)(^Q)§ä´M§@ªÌ/§@ªÌ¸ê®Æ", - "(b/f) ®iŪ³Æ§Ñ¿ý/°Ñ»P½ä½L (?)(/) §ä´M¼ÐÃD", - "(V/R) §ë²¼/¬d¸ß§ë²¼µ²ªG (^W)(X) §Ú¦bþ¸Ì/±ÀÂˤ峹", - "(x)(w) Âà¿ý¤å³¹/¥á¤ô²y (=)/([]<>-+) §ä´Mº½g¤å³¹/¥DÃD¦¡¾\\Ū", + /* help for board reading */ + static char *board_help[] = { + "\0¥þ¥\\¯à¬ÝªO¾Þ§@»¡©ú", + "\01°ò¥»©R¥O", + "(p)(¡ô) ¤W²¾¤@½g¤å³¹ (^P) µoªí¤å³¹", + "(n)(¡õ) ¤U²¾¤@½g¤å³¹ (d) §R°£¤å³¹", + "(P)(PgUp) ¤W²¾¤@¶ (S) ¦ê³s¬ÛÃö¤å³¹", + "(N)(PgDn) ¤U²¾¤@¶ (##) ¸õ¨ì ## ¸¹¤å³¹", + "(r)(¡÷) ¾\\Ū¦¹½g¤å³¹ ($) ¸õ¨ì³Ì«á¤@½g¤å³¹", + "\01¶i¶¥©R¥O", + "(tab)/z ¤åºK¼Ò¦¡/ºëµØ°Ï (a/A)(^Q)§ä´M§@ªÌ/§@ªÌ¸ê®Æ", + "(b/f) ®iŪ³Æ§Ñ¿ý/°Ñ»P½ä½L (?)(/) §ä´M¼ÐÃD", + "(V/R) §ë²¼/¬d¸ß§ë²¼µ²ªG (^W)(X) §Ú¦bþ¸Ì/±ÀÂˤ峹", + "(x)(w) Âà¿ý¤å³¹/¥á¤ô²y (=)/([]<>-+) §ä´Mº½g¤å³¹/¥DÃD¦¡¾\\Ū", #ifdef INTERNET_EMAIL - "(F) ¤å³¹±H¦^Internet¶l½c (U) ±N¤å³¹ uuencode «á±H¦^¶l½c", + "(F) ¤å³¹±H¦^Internet¶l½c (U) ±N¤å³¹ uuencode «á±H¦^¶l½c", #endif - "(E) «½s¤å³¹ (^H) ¦C¥X©Ò¦³ªº New Post(s)", - "\01ªO¥D©R¥O", - "(G) Á|¿ì½ä½L/°±¤î¤Uª`/¶}¼ú(W/K/v) ½s¿è³Æ§Ñ¿ý/¤ô±í¦W³æ/¥i¬Ý¨£¦W³æ", - "(M/o) Á|¦æ§ë²¼/½s¨p§ë²¼¦W³æ (m/c/g) «O¯d¤å³¹/¿ï¿ýºëµØ/¤åºK", - "(D) §R°£¤@¬q½d³òªº¤å³¹ (T/B) «½s¤å³¹¼ÐÃD/«½s¬ÝªO¼ÐÃD", - "(i) ½s¿è¥Ó½Ð¤J·|ªí®æ (t/^D) ¼Ð°O¤å³¹/¬å°£¼Ð°Oªº¤å³¹", - "(O) ½s¿èPostª`·N¨Æ¶µ (H)/(Y) ¬ÝªOÁôÂÃ/²{¨ ¨ú®ø±ÀÂˤ峹", - NULL -}; - -static int b_help() { - show_help(board_help); - return FULLUPDATE; -} + "(E) «½s¤å³¹ (^H) ¦C¥X©Ò¦³ªº New Post(s)", + "\01ªO¥D©R¥O", + "(G) Á|¿ì½ä½L/°±¤î¤Uª`/¶}¼ú(W/K/v) ½s¿è³Æ§Ñ¿ý/¤ô±í¦W³æ/¥i¬Ý¨£¦W³æ", + "(M/o) Á|¦æ§ë²¼/½s¨p§ë²¼¦W³æ (m/c/g) «O¯d¤å³¹/¿ï¿ýºëµØ/¤åºK", + "(D) §R°£¤@¬q½d³òªº¤å³¹ (T/B) «½s¤å³¹¼ÐÃD/«½s¬ÝªO¼ÐÃD", + "(i) ½s¿è¥Ó½Ð¤J·|ªí®æ (t/^D) ¼Ð°O¤å³¹/¬å°£¼Ð°Oªº¤å³¹", + "(O) ½s¿èPostª`·N¨Æ¶µ (H)/(Y) ¬ÝªOÁôÂÃ/²{¨ ¨ú®ø±ÀÂˤ峹", + NULL + }; + + static int b_help() { + show_help(board_help); + return FULLUPDATE; + } -/* ----------------------------------------------------- */ -/* ªO¥D³]©wÁô§Î/ ¸ÑÁô§Î */ -/* ----------------------------------------------------- */ -char board_hidden_status; + /* ----------------------------------------------------- */ + /* ªO¥D³]©wÁô§Î/ ¸ÑÁô§Î */ + /* ----------------------------------------------------- */ + char board_hidden_status; #ifdef BMCHS -static int change_hidden(int ent, fileheader_t *fhdr, char *direct) -{ - boardheader_t bh; - int bid; - char ans[4]; - - if( !((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || - currboard[0] == 0 || - (bid = getbnum(currboard)) < 0 || - get_record(fn_board, &bh, sizeof(bh), bid) == -1 ) - return DONOTHING; - - if( ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)) ){ - getdata(1, 0, "¥Ø«eªO¦bÁô§Îª¬ºA, n¸ÑÁô§Î¹À(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - getdata(2, 0, "¦A½T»{¤@¦¸, ¯uªºn§âªOªO¤½¶}¹À @____@(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - if( bh.brdattr & BRD_HIDE ) bh.brdattr -= BRD_HIDE; - if( bh.brdattr & BRD_POSTMASK ) bh.brdattr -= BRD_POSTMASK; - log_usies("OpenBoard", bh.brdname); - outs("§g¤ß¤µ¶Ç²³¤H¡AµL³B¤£»D©¶ºq¡C\n"); - board_hidden_status = 0; - hbflreload(bid); - } - else{ - getdata(1, 0, "¥Ø«eªO¦b²{§Îª¬ºA, nÁô§Î¹À(Y/N)?[N]", - ans, sizeof(ans), LCECHO); - if( ans[0] != 'y' && ans[0] != 'Y' ) - return FULLUPDATE; - bh.brdattr |= BRD_HIDE; - bh.brdattr |= BRD_POSTMASK; - log_usies("CloseBoard", bh.brdname); - outs("§g¤ß¤µ¤w±»§í¡A±©¬ßµ½¦Û¬Ã«¡C\n"); - board_hidden_status = 1; + static int change_hidden(int ent, fileheader_t * fhdr, char *direct){ + boardheader_t bh; + int bid; + char ans[4]; + + if (!((currmode & MODE_BOARD) || HAS_PERM(PERM_SYSOP)) || + currboard[0] == 0 || + (bid = getbnum(currboard)) < 0 || + get_record(fn_board, &bh, sizeof(bh), bid) == -1) + return DONOTHING; + + if (((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK))) { + getdata(1, 0, "¥Ø«eªO¦bÁô§Îª¬ºA, n¸ÑÁô§Î¹À(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + getdata(2, 0, "¦A½T»{¤@¦¸, ¯uªºn§âªOªO¤½¶}¹À @____@(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + if (bh.brdattr & BRD_HIDE) + bh.brdattr -= BRD_HIDE; + if (bh.brdattr & BRD_POSTMASK) + bh.brdattr -= BRD_POSTMASK; + log_usies("OpenBoard", bh.brdname); + outs("§g¤ß¤µ¶Ç²³¤H¡AµL³B¤£»D©¶ºq¡C\n"); + board_hidden_status = 0; + hbflreload(bid); + } else { + getdata(1, 0, "¥Ø«eªO¦b²{§Îª¬ºA, nÁô§Î¹À(Y/N)?[N]", + ans, sizeof(ans), LCECHO); + if (ans[0] != 'y' && ans[0] != 'Y') + return FULLUPDATE; + bh.brdattr |= BRD_HIDE; + bh.brdattr |= BRD_POSTMASK; + log_usies("CloseBoard", bh.brdname); + outs("§g¤ß¤µ¤w±»§í¡A±©¬ßµ½¦Û¬Ã«¡C\n"); + board_hidden_status = 1; + } + setup_man(&bh); + substitute_record(fn_board, &bh, sizeof(bh), bid); + reset_board(bid); + log_usies("SetBoard", bh.brdname); + pressanykey(); + return FULLUPDATE; } - setup_man(&bh); - substitute_record(fn_board, &bh, sizeof(bh), bid); - reset_board(bid); - log_usies("SetBoard", bh.brdname); - pressanykey(); - return FULLUPDATE; -} #endif -/* ----------------------------------------------------- */ -/* ¬ÝªO¥\¯àªí */ -/* ----------------------------------------------------- */ -struct onekey_t read_comms[] = { - {KEY_TAB, board_digest}, - {'C', board_etc}, - {'b', b_notes}, - {'c', cite_post}, - {'r', read_post}, - {'z', b_man}, - {'D', del_range}, - {'S', sequential_read}, - {'E', edit_post}, - {'T', edit_title}, - {'s', do_select}, - {'R', b_results}, - {'V', b_vote}, - {'M', b_vote_maintain}, - {'B', bh_title_edit}, - {'W', b_notes_edit}, - {'O', b_post_note}, - {'K', b_water_edit}, - {'w', b_call_in}, - {'v', visable_list_edit}, - {'i', b_application}, - {'o', can_vote_edit}, - {'x', cross_post}, - {'X', recommend}, - {'Y', recommend_cancel}, - {'h', b_help}, + /* ----------------------------------------------------- */ + /* ¬ÝªO¥\¯àªí */ + /* ----------------------------------------------------- */ + struct onekey_t read_comms[] = { + {KEY_TAB, board_digest}, + {'C', board_etc}, + {'b', b_notes}, + {'c', cite_post}, + {'r', read_post}, + {'z', b_man}, + {'D', del_range}, + {'S', sequential_read}, + {'E', edit_post}, + {'T', edit_title}, + {'s', do_select}, + {'R', b_results}, + {'V', b_vote}, + {'M', b_vote_maintain}, + {'B', bh_title_edit}, + {'W', b_notes_edit}, + {'O', b_post_note}, + {'K', b_water_edit}, + {'w', b_call_in}, + {'v', visable_list_edit}, + {'i', b_application}, + {'o', can_vote_edit}, + {'x', cross_post}, + {'X', recommend}, + {'Y', recommend_cancel}, + {'h', b_help}, #ifndef NO_GAMBLE - {'f', join_gamble}, - {'G', hold_gamble}, + {'f', join_gamble}, + {'G', hold_gamble}, #endif - {'g', good_post}, - {'y', reply_post}, - {'d', del_post}, - {'m', mark_post}, - {'L', solve_post}, - {Ctrl('P'), do_post}, - {Ctrl('W'), whereami}, - {'Q', view_postmoney}, + {'g', good_post}, + {'y', reply_post}, + {'d', del_post}, + {'m', mark_post}, + {'L', solve_post}, + {Ctrl('P'), do_post}, + {Ctrl('W'), whereami}, + {'Q', view_postmoney}, #ifdef OUTJOBSPOOL - {'u', tar_addqueue}, + {'u', tar_addqueue}, #endif #ifdef BMCHS - {'H', change_hidden}, + {'H', change_hidden}, #endif - {'\0', NULL} -}; + {'\0', NULL} + }; -int Read() { - int mode0 = currutmp->mode; - int stat0 = currstat, tmpbid=currutmp->brc_id; - char buf[40]; + int Read() { + int mode0 = currutmp->mode; + int stat0 = currstat, tmpbid = currutmp->brc_id; + char buf[40]; #ifdef LOG_BOARD - time_t usetime = now; -#endif + time_t usetime = now; +#endif - setutmpmode(READING); - set_board(); + setutmpmode(READING); + set_board(); - if(board_visit_time < board_note_time) { - setbfile(buf, currboard, fn_notes); - more(buf, NA); - pressanykey(); - } - setutmpbid(currbid); - setbdir(buf, currboard); - curredit &= ~EDIT_MAIL; - i_read(READING, buf, readtitle, readdoent, read_comms, - currbid); + if (board_visit_time < board_note_time) { + setbfile(buf, currboard, fn_notes); + more(buf, NA); + pressanykey(); + } + setutmpbid(currbid); + setbdir(buf, currboard); + curredit &= ~EDIT_MAIL; + i_read(READING, buf, readtitle, readdoent, read_comms, + currbid); #ifdef LOG_BOARD - log_board(currboard, now - usetime); + log_board(currboard, now - usetime); #endif - brc_update(); - setutmpbid(tmpbid); - currutmp->mode = mode0; - currstat = stat0; - return 0; -} + brc_update(); + setutmpbid(tmpbid); + currutmp->mode = mode0; + currstat = stat0; + return 0; + } -void ReadSelect() { - int mode0 = currutmp->mode; - int stat0 = currstat; - char genbuf[200]; - - currstat = XMODE; - if(do_select(0, 0, genbuf) == NEWDIRECT) - Read(); - setutmpbid(0); - currutmp->mode = mode0; - currstat = stat0; -} + void ReadSelect() { + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[200]; + + currstat = XMODE; + if (do_select(0, 0, genbuf) == NEWDIRECT) + Read(); + setutmpbid(0); + currutmp->mode = mode0; + currstat = stat0; + } -#ifdef LOG_BOARD -static void log_board(char *mode, time_t usetime) { - char buf[ 256 ]; +#ifdef LOG_BOARD + static void log_board(char *mode, time_t usetime){ + char buf[256]; - if(usetime > 30) { - sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", - mode, usetime ,cuser.userid ,ctime(&now)); - log_file(FN_USEBOARD,buf); + if (usetime > 30) { + sprintf(buf, "USE %-20.20s Stay: %5ld (%s) %s", + mode, usetime, cuser.userid, ctime(&now)); + log_file(FN_USEBOARD, buf); + } } -} #endif -int Select() { - char genbuf[200]; + int Select() { + char genbuf[200]; - setutmpmode(SELECT); - do_select(0, NULL, genbuf); - return 0; -} + setutmpmode(SELECT); + do_select(0, NULL, genbuf); + return 0; + } #ifdef HAVEMOBILE -void mobile_message(char *mobile, char *message) -{ + void mobile_message(char *mobile, char *message){ - bsmtp(char *fpath, char *title, char *rcpt, int method); -} + bsmtp(char *fpath, char *title, char *rcpt, int method); + } #endif diff --git a/mbbsd/board.c b/mbbsd/board.c index d85a45ae..4626adb5 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1,13 +1,15 @@ -/* $Id: board.c,v 1.39 2002/06/26 09:49:37 ptt Exp $ */ +/* $Id: board.c,v 1.40 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" -#define BRC_STRLEN 15 /* Length of board name */ +#define BRC_STRLEN 15 /* Length of board name */ #define BRC_MAXSIZE 24576 #define BRC_ITEMSIZE (BRC_STRLEN + 1 + BRC_MAXNUM * sizeof( int )) #define BRC_MAXNUM 80 -static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { - int num; - char *tmp; +static char * +brc_getrecord(char *ptr, char *name, int *pnum, int *list) +{ + int num; + char *tmp; strncpy(name, ptr, BRC_STRLEN); ptr += BRC_STRLEN; @@ -20,14 +22,16 @@ static char *brc_getrecord(char *ptr, char *name, int *pnum, int *list) { return tmp; } -static time_t brc_expire_time; +static time_t brc_expire_time; -static char *brc_putrecord(char *ptr, char *name, int num, int *list) { - if(num > 0 && list[0] > brc_expire_time) { +static char * +brc_putrecord(char *ptr, char *name, int num, int *list) +{ + if (num > 0 && list[0] > brc_expire_time) { if (num > BRC_MAXNUM) num = BRC_MAXNUM; - while(num > 1 && list[num - 1] < brc_expire_time) + while (num > 1 && list[num - 1] < brc_expire_time) num--; strncpy(ptr, name, BRC_STRLEN); @@ -39,26 +43,28 @@ static char *brc_putrecord(char *ptr, char *name, int num, int *list) { return ptr; } -static int brc_changed = 0; -static char brc_buf[BRC_MAXSIZE]; -static char brc_name[BRC_STRLEN]; -static char *fn_boardrc = ".boardrc"; -static int brc_size; +static int brc_changed = 0; +static char brc_buf[BRC_MAXSIZE]; +static char brc_name[BRC_STRLEN]; +static char *fn_boardrc = ".boardrc"; +static int brc_size; -void brc_update() { - if(brc_changed && cuser.userlevel) { - char dirfile[STRLEN], *ptr; - char tmp_buf[BRC_MAXSIZE - BRC_ITEMSIZE], *tmp; - char tmp_name[BRC_STRLEN]; - int tmp_list[BRC_MAXNUM], tmp_num; - int fd, tmp_size; +void +brc_update() +{ + if (brc_changed && cuser.userlevel) { + char dirfile[STRLEN], *ptr; + char tmp_buf[BRC_MAXSIZE - BRC_ITEMSIZE], *tmp; + char tmp_name[BRC_STRLEN]; + int tmp_list[BRC_MAXNUM], tmp_num; + int fd, tmp_size; ptr = brc_buf; - if(brc_num > 0) + if (brc_num > 0) ptr = brc_putrecord(ptr, brc_name, brc_num, brc_list); setuserfile(dirfile, fn_boardrc); - if((fd = open(dirfile, O_RDONLY)) != -1) { + if ((fd = open(dirfile, O_RDONLY)) != -1) { tmp_size = read(fd, tmp_buf, sizeof(tmp_buf)); close(fd); } else { @@ -66,14 +72,14 @@ void brc_update() { } tmp = tmp_buf; - while(tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { + while (tmp < &tmp_buf[tmp_size] && (*tmp >= ' ' && *tmp <= 'z')) { tmp = brc_getrecord(tmp, tmp_name, &tmp_num, tmp_list); - if(strncmp(tmp_name, currboard, BRC_STRLEN)) + if (strncmp(tmp_name, currboard, BRC_STRLEN)) ptr = brc_putrecord(ptr, tmp_name, tmp_num, tmp_list); } brc_size = (int)(ptr - brc_buf); - if((fd = open(dirfile, O_WRONLY | O_CREAT, 0644)) != -1) { + if ((fd = open(dirfile, O_WRONLY | O_CREAT, 0644)) != -1) { ftruncate(fd, 0); write(fd, brc_buf, brc_size); close(fd); @@ -82,13 +88,15 @@ void brc_update() { } } -static void read_brc_buf() { - char dirfile[STRLEN]; - int fd; +static void +read_brc_buf() +{ + char dirfile[STRLEN]; + int fd; - if(brc_buf[0] == '\0') { + if (brc_buf[0] == '\0') { setuserfile(dirfile, fn_boardrc); - if((fd = open(dirfile, O_RDONLY)) != -1) { + if ((fd = open(dirfile, O_RDONLY)) != -1) { brc_size = read(fd, brc_buf, sizeof(brc_buf)); close(fd); } else { @@ -97,9 +105,11 @@ static void read_brc_buf() { } } -int brc_initial(char *boardname) { - char *ptr; - if(strcmp(currboard, boardname) == 0) { +int +brc_initial(char *boardname) +{ + char *ptr; + if (strcmp(currboard, boardname) == 0) { return brc_num; } brc_update(); @@ -109,7 +119,7 @@ int brc_initial(char *boardname) { read_brc_buf(); ptr = brc_buf; - while(ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { + while (ptr < &brc_buf[brc_size] && (*ptr >= ' ' && *ptr <= 'z')) { ptr = brc_getrecord(ptr, brc_name, &brc_num, brc_list); if (strncmp(brc_name, currboard, BRC_STRLEN) == 0) return brc_num; @@ -119,73 +129,79 @@ int brc_initial(char *boardname) { return 0; } -void brc_addlist(char *fname) { - int ftime, n, i; +void +brc_addlist(char *fname) +{ + int ftime, n, i; - if(!cuser.userlevel) + if (!cuser.userlevel) return; ftime = atoi(&fname[2]); - if(ftime <= brc_expire_time - /* || fname[0] != 'M' || fname[1] != '.' */ ) { + if (ftime <= brc_expire_time + /* || fname[0] != 'M' || fname[1] != '.' */ ) { return; } - if(brc_num <= 0) { + if (brc_num <= 0) { brc_list[brc_num++] = ftime; brc_changed = 1; return; } - if((brc_num == 1) && (ftime < brc_list[0])) + if ((brc_num == 1) && (ftime < brc_list[0])) return; - for(n = 0; n < brc_num; n++) { - if(ftime == brc_list[n]) { + for (n = 0; n < brc_num; n++) { + if (ftime == brc_list[n]) { return; - } else if(ftime > brc_list[n]) { - if(brc_num < BRC_MAXNUM) + } else if (ftime > brc_list[n]) { + if (brc_num < BRC_MAXNUM) brc_num++; - for(i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); + for (i = brc_num - 1; --i >= n; brc_list[i + 1] = brc_list[i]); brc_list[n] = ftime; brc_changed = 1; return; } } - if(brc_num < BRC_MAXNUM) { + if (brc_num < BRC_MAXNUM) { brc_list[brc_num++] = ftime; brc_changed = 1; } } -static int brc_unread_time(time_t ftime, int bnum, int *blist) { - int n; +static int +brc_unread_time(time_t ftime, int bnum, int *blist) +{ + int n; - if(ftime <= brc_expire_time ) + if (ftime <= brc_expire_time) return 0; - if(brc_num <= 0) + if (brc_num <= 0) return 1; - for(n = 0; n < bnum; n++) { - if(ftime > blist[n]) + for (n = 0; n < bnum; n++) { + if (ftime > blist[n]) return 1; - else if(ftime == blist[n]) + else if (ftime == blist[n]) return 0; } return 0; } -int brc_unread(char *fname, int bnum, int *blist) { - int ftime, n; +int +brc_unread(char *fname, int bnum, int *blist) +{ + int ftime, n; ftime = atoi(&fname[2]); - if(ftime <= brc_expire_time ) + if (ftime <= brc_expire_time) return 0; - if(brc_num <= 0) + if (brc_num <= 0) return 1; - for(n = 0; n < bnum; n++) { - if(ftime > blist[n]) + for (n = 0; n < bnum; n++) { + if (ftime > blist[n]) return 1; - else if(ftime == blist[n]) + else if (ftime == blist[n]) return 0; } return 0; @@ -197,96 +213,102 @@ int brc_unread(char *fname, int bnum, int *blist) { #define BRD_TAG 8 typedef struct { - int bid, *total; - time_t *lastposttime; - boardheader_t *bh; - unsigned int myattr; -} boardstat_t; + int bid, *total; + time_t *lastposttime; + boardheader_t *bh; + unsigned int myattr; +} boardstat_t; -static int *zapbuf=NULL,*favbuf; -static boardstat_t *nbrd=NULL; +static int *zapbuf = NULL, *favbuf; +static boardstat_t *nbrd = NULL; #define STR_BBSRC ".bbsrc" #define STR_FAV ".fav" -void init_brdbuf() { - register int n, size; - char fname[60]; +void +init_brdbuf() +{ + register int n, size; + char fname[60]; /* MAXBOARDS ==> ¦Ü¦h¬Ý±o¨£ 32 Ó·sªO */ n = numboards + 32; size = n * sizeof(int); - zapbuf = (int *) malloc(size); - favbuf = (int *) malloc(size + sizeof(int)); + zapbuf = (int *)malloc(size); + favbuf = (int *)malloc(size + sizeof(int)); - favbuf[0] = 0x5c4d3e; /* for check memory */ + favbuf[0] = 0x5c4d3e; /* for check memory */ ++favbuf; - memset(favbuf,0,size); + memset(favbuf, 0, size); - while(n) + while (n) zapbuf[--n] = login_start_time; setuserfile(fname, STR_BBSRC); - if((n = open(fname, O_RDONLY, 0600)) != -1) { + if ((n = open(fname, O_RDONLY, 0600)) != -1) { read(n, zapbuf, size); close(n); } setuserfile(fname, STR_FAV); - if((n = open(fname, O_RDONLY, 0600)) != -1) { + if ((n = open(fname, O_RDONLY, 0600)) != -1) { read(n, favbuf, size); close(n); } + for (n = 0; n < numboards; n++) + favbuf[n] &= ~BRD_TAG; - for(n = 0; n < numboards; n++) - favbuf[n] &= ~BRD_TAG; - brc_expire_time = login_start_time - 365 * 86400; } -void save_brdbuf() { - int fd, size; - char fname[60]; +void +save_brdbuf() +{ + int fd, size; + char fname[60]; - if(!zapbuf) return; + if (!zapbuf) + return; setuserfile(fname, STR_BBSRC); - if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); write(fd, zapbuf, size); close(fd); } - if( favbuf[-1] != 0x5c4d3e ){ - FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); + if (favbuf[-1] != 0x5c4d3e) { + FILE *fp = fopen(BBSHOME "/log/memorybad", "a"); fprintf(fp, "%s %s %d\n", cuser.userid, Cdatelite(&now), favbuf[-1]); fclose(fp); return; } setuserfile(fname, STR_FAV); - if((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { + if ((fd = open(fname, O_WRONLY | O_CREAT, 0600)) != -1) { size = numboards * sizeof(int); write(fd, favbuf, size); close(fd); } } -int Ben_Perm(boardheader_t *bptr) { - register int level,brdattr; - register char *ptr; +int +Ben_Perm(boardheader_t * bptr) +{ + register int level, brdattr; + register char *ptr; level = bptr->level; brdattr = bptr->brdattr; - if(HAS_PERM(PERM_SYSOP)) + if (HAS_PERM(PERM_SYSOP)) return 1; ptr = bptr->BM; - if(is_BM(ptr)) + if (is_BM(ptr)) return 1; /* ¯¦±K¬ÝªO¡G®Ö¹ïº®uªO¥Dªº¦n¤Í¦W³æ */ - if(brdattr & BRD_HIDE) { /* ÁôÂà */ - if( hbflcheck((int)(bptr-bcache) + 1, currutmp->uid) ){ - if(brdattr & BRD_POSTMASK) + if (brdattr & BRD_HIDE) { /* ÁôÂà */ + if (hbflcheck((int)(bptr - bcache) + 1, currutmp->uid)) { + if (brdattr & BRD_POSTMASK) return 0; else return 2; @@ -294,18 +316,20 @@ int Ben_Perm(boardheader_t *bptr) { return 1; } /* ¨î¾\ŪÅv */ - if(level && !(brdattr & BRD_POSTMASK) && !HAS_PERM(level)) + if (level && !(brdattr & BRD_POSTMASK) && !HAS_PERM(level)) return 0; return 1; } #if 0 -static int have_author(char* brdname) { - char dirname[100]; +static int +have_author(char *brdname) +{ + char dirname[100]; sprintf(dirname, "¥¿¦b·j´M§@ªÌ[33m%s[m ¬ÝªO:[1;33m%s[0m.....", - currauthor,brdname); + currauthor, brdname); move(b_lines, 0); clrtoeol(); outs(dirname); @@ -318,28 +342,31 @@ static int have_author(char* brdname) { } #endif -static int check_newpost(boardstat_t *ptr) { /* Ptt §ï */ - int tbrc_list[BRC_MAXNUM], tbrc_num; - char bname[BRC_STRLEN]; - char *po; - time_t ftime; +static int +check_newpost(boardstat_t * ptr) +{ /* Ptt §ï */ + int tbrc_list[BRC_MAXNUM], tbrc_num; + char bname[BRC_STRLEN]; + char *po; + time_t ftime; ptr->myattr &= ~BRD_UNREAD; - if(ptr->bh->brdattr & BRD_GROUPBOARD) + if (ptr->bh->brdattr & BRD_GROUPBOARD) return 0; - if(*(ptr->total) == 0) - setbtotal(ptr->bid); - if(*(ptr->total) == 0) return 0; + if (*(ptr->total) == 0) + setbtotal(ptr->bid); + if (*(ptr->total) == 0) + return 0; ftime = *(ptr->lastposttime); read_brc_buf(); po = brc_buf; - while(po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { + while (po < &brc_buf[brc_size] && (*po >= ' ' && *po <= 'z')) { po = brc_getrecord(po, bname, &tbrc_num, tbrc_list); - if(strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { - if(brc_unread_time(ftime,tbrc_num,tbrc_list)) { + if (strncmp(bname, ptr->bh->brdname, BRC_STRLEN) == 0) { + if (brc_unread_time(ftime, tbrc_num, tbrc_list)) { ptr->myattr |= BRD_UNREAD; - } + } return 1; } } @@ -348,168 +375,180 @@ static int check_newpost(boardstat_t *ptr) { /* Ptt §ï */ return 1; } -static int brdnum; -static int yank_flag = 1; -static void load_uidofgid(const int gid, const int type){ - boardheader_t *bptr,*currbptr; - int n, childcount=0; - currbptr = &bcache[gid-1]; - for( n = 0 ; n < numboards ; ++n ){ - bptr = SHM->bsorted[type][n]; - if( bptr->brdname[0] == '\0' ) - continue; - if( bptr->gid == gid ){ - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=bptr; - else{ - currbptr->next[type]=bptr; - currbptr->parent=&bcache[gid-1]; - } - childcount++; - currbptr=bptr; - } - } - bcache[gid-1].childcount=childcount; - if(currbptr == &bcache[gid-1]) - currbptr->firstchild[type]=(boardheader_t *) ~0; - else - currbptr->next[type]=(boardheader_t *) ~0; +static int brdnum; +static int yank_flag = 1; +static void +load_uidofgid(const int gid, const int type) +{ + boardheader_t *bptr, *currbptr; + int n, childcount = 0; + currbptr = &bcache[gid - 1]; + for (n = 0; n < numboards; ++n) { + bptr = SHM->bsorted[type][n]; + if (bptr->brdname[0] == '\0') + continue; + if (bptr->gid == gid) { + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = bptr; + else { + currbptr->next[type] = bptr; + currbptr->parent = &bcache[gid - 1]; + } + childcount++; + currbptr = bptr; + } + } + bcache[gid - 1].childcount = childcount; + if (currbptr == &bcache[gid - 1]) + currbptr->firstchild[type] = (boardheader_t *) ~ 0; + else + currbptr->next[type] = (boardheader_t *) ~ 0; } -static boardstat_t * addnewbrdstat(int n, int state) +static boardstat_t * +addnewbrdstat(int n, int state) { - boardstat_t *ptr=&nbrd[brdnum++]; - boardheader_t *bptr = &bcache[n]; - ptr->total = &(SHM->total[n]); - ptr->lastposttime = &(SHM->lastposttime[n]); - ptr->bid = n+1; - ptr->myattr=0; - ptr->myattr=(favbuf[n]&~BRD_ZAP); - if(zapbuf[n] == 0) - ptr->myattr|=BRD_ZAP; - ptr->bh = bptr; - if((bptr->brdattr & BRD_HIDE) && state == 1) - bptr->brdattr |= BRD_POSTMASK; - check_newpost(ptr); - return ptr; + boardstat_t *ptr = &nbrd[brdnum++]; + boardheader_t *bptr = &bcache[n]; + ptr->total = &(SHM->total[n]); + ptr->lastposttime = &(SHM->lastposttime[n]); + ptr->bid = n + 1; + ptr->myattr = 0; + ptr->myattr = (favbuf[n] & ~BRD_ZAP); + if (zapbuf[n] == 0) + ptr->myattr |= BRD_ZAP; + ptr->bh = bptr; + if ((bptr->brdattr & BRD_HIDE) && state == 1) + bptr->brdattr |= BRD_POSTMASK; + check_newpost(ptr); + return ptr; } -static int cmpboardfriends(const void *brd, const void *tmp) +static int +cmpboardfriends(const void *brd, const void *tmp) { - return ((boardstat_t *)tmp)->bh->nuser - ((boardstat_t *)brd)->bh->nuser; + return ((boardstat_t *) tmp)->bh->nuser - ((boardstat_t *) brd)->bh->nuser; } -static void load_boards(char *key) { - boardheader_t *bptr = NULL; - int type=cuser.uflag & BRDSORT_FLAG?1:0; - register int i,n; - register int state ; - - if(class_bid>0) - { - bptr = &bcache[class_bid-1]; - if(bptr->firstchild[type]==NULL || bptr->childcount<=0) - load_uidofgid(class_bid,type); - } +static void +load_boards(char *key) +{ + boardheader_t *bptr = NULL; + int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; + register int i, n; + register int state; + + if (class_bid > 0) { + bptr = &bcache[class_bid - 1]; + if (bptr->firstchild[type] == NULL || bptr->childcount <= 0) + load_uidofgid(class_bid, type); + } brdnum = 0; - if(class_bid<=0){ - nbrd = (boardstat_t *)malloc(numboards * sizeof(boardstat_t)); - for(i=0 ; i < numboards; i++){ - if( (bptr = SHM->bsorted[type][i]) == NULL ) + if (class_bid <= 0) { + nbrd = (boardstat_t *) malloc(numboards * sizeof(boardstat_t)); + for (i = 0; i < numboards; i++) { + if ((bptr = SHM->bsorted[type][i]) == NULL) continue; n = (int)(bptr - bcache); - if( !bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || + if (!bptr->brdname[0] || bptr->brdattr & BRD_GROUPBOARD || !((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) || (yank_flag == 1 && !zapbuf[n]) || (key[0] && !strcasestr(bptr->title, key)) || - (class_bid == -1 && bptr->nuser < 5) ) + (class_bid == -1 && bptr->nuser < 5)) continue; addnewbrdstat(n, state); - if( class_bid == -1 ) + if (class_bid == -1) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); } - } - else{ - nbrd = (boardstat_t *)malloc(bptr->childcount * sizeof(boardstat_t)); - for(bptr=bptr->firstchild[type]; bptr!=(boardheader_t *)~0; - bptr=bptr->next[type]) { - n = (int)( bptr - bcache); - if(!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) - ||(yank_flag == 0 && !(favbuf[n] & BRD_FAV)) - ||(yank_flag == 1 && !zapbuf[n]) || - (key[0] && !strcasestr(bptr->title, key))) + } else { + nbrd = (boardstat_t *) malloc(bptr->childcount * sizeof(boardstat_t)); + for (bptr = bptr->firstchild[type]; bptr != (boardheader_t *) ~ 0; + bptr = bptr->next[type]) { + n = (int)(bptr - bcache); + if (!((state = Ben_Perm(bptr)) || (currmode & MODE_MENU)) + || (yank_flag == 0 && !(favbuf[n] & BRD_FAV)) + || (yank_flag == 1 && !zapbuf[n]) || + (key[0] && !strcasestr(bptr->title, key))) continue; addnewbrdstat(n, state); } } } -static int search_board() { - int num; - char genbuf[IDLEN + 2]; +static int +search_board() +{ + int num; + char genbuf[IDLEN + 2]; move(0, 0); clrtoeol(); CreateNameList(); - for(num = 0; num < brdnum; num++) + for (num = 0; num < brdnum; num++) AddNameList(nbrd[num].bh->brdname); namecomplete(MSG_SELECT_BOARD, genbuf); for (num = 0; num < brdnum; num++) - if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) - return num; - return -1; + if (!strcasecmp(nbrd[num].bh->brdname, genbuf)) + return num; + return -1; } -static int unread_position(char *dirfile, boardstat_t *ptr) { - fileheader_t fh; - char fname[FNLEN]; - register int num, fd, step, total; +static int +unread_position(char *dirfile, boardstat_t * ptr) +{ + fileheader_t fh; + char fname[FNLEN]; + register int num, fd, step, total; total = *(ptr->total); num = total + 1; - if((ptr->myattr&BRD_UNREAD) &&(fd = open(dirfile, O_RDWR)) > 0) { - if(!brc_initial(ptr->bh->brdname)) { + if ((ptr->myattr & BRD_UNREAD) && (fd = open(dirfile, O_RDWR)) > 0) { + if (!brc_initial(ptr->bh->brdname)) { num = 1; } else { num = total - 1; step = 4; - while(num > 0) { - lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); - if(read(fd, fname, FNLEN) <= 0 || - !brc_unread(fname,brc_num,brc_list)) + while (num > 0) { + lseek(fd, (off_t) (num * sizeof(fh)), SEEK_SET); + if (read(fd, fname, FNLEN) <= 0 || + !brc_unread(fname, brc_num, brc_list)) break; num -= step; - if(step < 32) + if (step < 32) step += step >> 1; } - if(num < 0) + if (num < 0) num = 0; - while(num < total) { - lseek(fd, (off_t)(num * sizeof(fh)), SEEK_SET); - if(read(fd, fname, FNLEN) <= 0 || - brc_unread(fname,brc_num,brc_list)) + while (num < total) { + lseek(fd, (off_t) (num * sizeof(fh)), SEEK_SET); + if (read(fd, fname, FNLEN) <= 0 || + brc_unread(fname, brc_num, brc_list)) break; num++; } } close(fd); } - if(num < 0) + if (num < 0) num = 0; return num; } -static void brdlist_foot() { +static void +brdlist_foot() +{ prints("\033[34;46m ¿ï¾Ü¬ÝªO \033[31;47m (c)\033[30m·s¤å³¹¼Ò¦¡ " "\033[31m(v/V)\033[30m¼Ð°O¤wŪ/¥¼Åª \033[31m(y)\033[30m¿z¿ï%s" " \033[31m(z)\033[30m¤Á´«¿ï¾Ü \033[m", - yank_flag==0 ? "³Ì·R" : yank_flag==1 ? "³¡¥÷" : "¥þ³¡"); + yank_flag == 0 ? "³Ì·R" : yank_flag == 1 ? "³¡¥÷" : "¥þ³¡"); } -static void show_brdlist(int head, int clsflag, int newflag) { - int myrow = 2; - if(class_bid == 1) { +static void +show_brdlist(int head, int clsflag, int newflag) +{ + int myrow = 2; + if (class_bid == 1) { currstat = CLASS; myrow = 6; showtitle("¤ÀÃþ¬ÝªO", BBSName); @@ -517,18 +556,18 @@ static void show_brdlist(int head, int clsflag, int newflag) { move(1, 0); prints( " " - "¢© ¢~¡X\033[33m¡´\n" - " ùá¡X \033[m " - "¢¨¢i\033[47m¡ó\033[40m¢i¢i¢©ùç\n"); + "¢© ¢~¡X\033[33m¡´\n" + " ùá¡X \033[m " + "¢¨¢i\033[47m¡ó\033[40m¢i¢i¢©ùç\n"); prints( - " \033[44m ¡s¡s¡s¡s¡s¡s¡s¡s " - "\033[33mùø\033[m\033[44m ¢©¢¨¢i¢i¢i¡¿¡¿¡¿ùø \033[m\n" - " \033[44m " - "\033[33m \033[m\033[44m ¢«¢ª¢i¢i¢i¡¶¡¶¡¶ ùø\033[m\n" + " \033[44m ¡s¡s¡s¡s¡s¡s¡s¡s " + "\033[33mùø\033[m\033[44m ¢©¢¨¢i¢i¢i¡¿¡¿¡¿ùø \033[m\n" + " \033[44m " + "\033[33m \033[m\033[44m ¢«¢ª¢i¢i¢i¡¶¡¶¡¶ ùø\033[m\n" " ¡s¡s¡s¡s¡s¡s¡s¡s \033[33m" - "¢x\033[m ¢ª¢i¢i¢i¢i¢« ùø\n" - " \033[33mùó" - "¡X¡X\033[m ¢« ¡X¡Ï\033[m"); + "¢x\033[m ¢ª¢i¢i¢i¢i¢« ùø\n" + " \033[33mùó" + "¡X¡X\033[m ¢« ¡X¡Ï\033[m"); } else if (clsflag) { showtitle("¬ÝªO¦Cªí", BBSName); prints("[¡ö]¥D¿ï³æ [¡÷]¾\\Ū [¡ô¡õ]¿ï¾Ü [y]¸ü¤J [S]±Æ§Ç [/]·j´M " @@ -539,63 +578,63 @@ static void show_brdlist(int head, int clsflag, int newflag) { move(b_lines, 0); brdlist_foot(); } - - if(brdnum > 0) { - boardstat_t *ptr; - static char *color[8]={"","\033[32m", - "\033[33m","\033[36m","\033[34m","\033[1m", - "\033[1;32m","\033[1;33m"}; - static char *unread[2]={"\33[37m \033[m","\033[1;31m£¾\033[m"}; - - while(++myrow < b_lines) { + if (brdnum > 0) { + boardstat_t *ptr; + static char *color[8] = {"", "\033[32m", + "\033[33m", "\033[36m", "\033[34m", "\033[1m", + "\033[1;32m", "\033[1;33m"}; + static char *unread[2] = {"\33[37m \033[m", "\033[1;31m£¾\033[m"}; + + while (++myrow < b_lines) { move(myrow, 0); clrtoeol(); - if(head < brdnum) { + if (head < brdnum) { ptr = &nbrd[head++]; - if(class_bid == 1) + if (class_bid == 1) prints(" "); - if(!newflag) { + if (!newflag) { prints("%5d%c%s", head, - !(ptr->bh->brdattr & BRD_HIDE) ? ' ': + !(ptr->bh->brdattr & BRD_HIDE) ? ' ' : (ptr->bh->brdattr & BRD_POSTMASK) ? ')' : '-', (ptr->myattr & BRD_TAG) ? "D " : (ptr->myattr & BRD_ZAP) ? "- " : (ptr->bh->brdattr & BRD_GROUPBOARD) ? " " : - unread[ptr->myattr&BRD_UNREAD]); - } else if(ptr->myattr&BRD_ZAP) { + unread[ptr->myattr & BRD_UNREAD]); + } else if (ptr->myattr & BRD_ZAP) { ptr->myattr &= ~BRD_UNREAD; prints(" ¡ß ¡ß"); } else { - if(newflag) { - if((ptr->bh->brdattr & BRD_GROUPBOARD)) - prints(" "); - else + if (newflag) { + if ((ptr->bh->brdattr & BRD_GROUPBOARD)) + prints(" "); + else prints("%6d%s", (int)(*(ptr->total)), - unread[ptr->myattr&BRD_UNREAD]); + unread[ptr->myattr & BRD_UNREAD]); } } - if(class_bid != 1) { - prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" - "%-34.34s", - (ptr->myattr & BRD_FAV)?"\033[1;36m":"", + if (class_bid != 1) { + prints("%s%-13s\033[m%s%5.5s\033[0;37m%2.2s\033[m" + "%-34.34s", + (ptr->myattr & BRD_FAV) ? "\033[1;36m" : "", ptr->bh->brdname, color[(unsigned int) - (ptr->bh->title[1] + ptr->bh->title[2] + - ptr->bh->title[3] + ptr->bh->title[0]) & 07], - ptr->bh->title, ptr->bh->title+5, ptr->bh->title+7); - - if (ptr->bh->brdattr & BRD_BAD) - prints(" X "); - else if(ptr->bh->nuser>=100) - prints("\033[1mHOT\033[m"); - else if(ptr->bh->nuser>50) - prints("\033[1;31m%2d\033[m ",ptr->bh->nuser); - else if(ptr->bh->nuser>10) - prints("\033[1;33m%2d\033[m ",ptr->bh->nuser); - else if(ptr->bh->nuser>0) - prints("%2d ",ptr->bh->nuser); - else prints(" %c ", ptr->bh->bvote? 'V':' '); - prints("%.13s", ptr->bh->BM); + (ptr->bh->title[1] + ptr->bh->title[2] + + ptr->bh->title[3] + ptr->bh->title[0]) & 07], + ptr->bh->title, ptr->bh->title + 5, ptr->bh->title + 7); + + if (ptr->bh->brdattr & BRD_BAD) + prints(" X "); + else if (ptr->bh->nuser >= 100) + prints("\033[1mHOT\033[m"); + else if (ptr->bh->nuser > 50) + prints("\033[1;31m%2d\033[m ", ptr->bh->nuser); + else if (ptr->bh->nuser > 10) + prints("\033[1;33m%2d\033[m ", ptr->bh->nuser); + else if (ptr->bh->nuser > 0) + prints("%2d ", ptr->bh->nuser); + else + prints(" %c ", ptr->bh->bvote ? 'V' : ' '); + prints("%.13s", ptr->bh->BM); refresh(); } else { prints("%-40.40s %.13s", ptr->bh->title + 7, ptr->bh->BM); @@ -606,7 +645,7 @@ static void show_brdlist(int head, int clsflag, int newflag) { } } -static char *choosebrdhelp[] = { +static char *choosebrdhelp[] = { "\0¬ÝªO¿ï³æ»²§U»¡©ú", "\01°ò¥»«ü¥O", "(p)(¡ô)/(n)(¡õ)¤W¤@ӬݪO / ¤U¤@ӬݪO", @@ -631,60 +670,66 @@ static char *choosebrdhelp[] = { }; -static void set_menu_BM(char *BM) { - if(HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { +static void +set_menu_BM(char *BM) +{ + if (HAS_PERM(PERM_ALLBOARD) || is_BM(BM)) { currmode |= MODE_MENU; cuser.userlevel |= PERM_SYSSUBOP; } } -static char *privateboard = +static char *privateboard = "\n\n\n\n ¹ï¤£°_ ¦¹ªO¥Ø«e¥uã¬ÝªO¦n¤Í¶i¤J ½Ð¥ý¦VªO¥D¥Ó½Ð¤J¹Ò³\\¥i"; -static void dozap(int num){ - boardstat_t *ptr; - ptr = &nbrd[num]; - ptr->myattr ^= BRD_ZAP; - if(ptr->bh->brdattr & BRD_NOZAP) ptr->myattr &= ~BRD_ZAP; - if(!(ptr->myattr & BRD_ZAP) ) check_newpost(ptr); - zapbuf[ptr->bid-1] = (ptr->myattr&BRD_ZAP?0:login_start_time); +static void +dozap(int num) +{ + boardstat_t *ptr; + ptr = &nbrd[num]; + ptr->myattr ^= BRD_ZAP; + if (ptr->bh->brdattr & BRD_NOZAP) + ptr->myattr &= ~BRD_ZAP; + if (!(ptr->myattr & BRD_ZAP)) + check_newpost(ptr); + zapbuf[ptr->bid - 1] = (ptr->myattr & BRD_ZAP ? 0 : login_start_time); } -static void choose_board(int newflag) { - static int num = 0; - boardstat_t *ptr; - int head = -1, ch = 0, currmodetmp, tmp,tmp1, bidtmp; - char keyword[13]=""; +static void +choose_board(int newflag) +{ + static int num = 0; + boardstat_t *ptr; + int head = -1, ch = 0, currmodetmp, tmp, tmp1, bidtmp; + char keyword[13] = ""; #if HAVE_SEARCH_ALL - char genbuf[200]; + char genbuf[200]; #endif - + setutmpmode(newflag ? READNEW : READBRD); brdnum = 0; - if(!cuser.userlevel) /* guest yank all boards */ + if (!cuser.userlevel) /* guest yank all boards */ yank_flag = 2; - + do { - if(brdnum <= 0) { + if (brdnum <= 0) { load_boards(keyword); - if(brdnum <= 0) { - if(keyword[0]!=0) - { - mprints(b_lines-1,0,"¨S¦³¥ô¦ó¬ÝªO¼ÐÃD¦³¦¹ÃöÁä¦r " - "(ªO¥DÀ³ª`·N¬ÝªO¼ÐÃD©R¦W)"); - pressanykey(); - keyword[0]=0; - brdnum = -1; - continue; - } - if(yank_flag<2) - { - brdnum = -1; - yank_flag++; - continue; - } - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { - if(m_newbrd(0) == -1) + if (brdnum <= 0) { + if (keyword[0] != 0) { + mprints(b_lines - 1, 0, "¨S¦³¥ô¦ó¬ÝªO¼ÐÃD¦³¦¹ÃöÁä¦r " + "(ªO¥DÀ³ª`·N¬ÝªO¼ÐÃD©R¦W)"); + pressanykey(); + keyword[0] = 0; + brdnum = -1; + continue; + } + if (yank_flag < 2) { + brdnum = -1; + yank_flag++; + continue; + } + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (m_newbrd(0) == -1) break; brdnum = -1; continue; @@ -693,51 +738,49 @@ static void choose_board(int newflag) { } head = -1; } - - if(num < 0) + if (num < 0) num = 0; - else if(num >= brdnum) + else if (num >= brdnum) num = brdnum - 1; - - if(head < 0) { - if(newflag) { + + if (head < 0) { + if (newflag) { tmp = num; - while(num < brdnum) { + while (num < brdnum) { ptr = &nbrd[num]; - if(ptr->myattr&BRD_UNREAD) + if (ptr->myattr & BRD_UNREAD) break; num++; } - if(num >= brdnum) + if (num >= brdnum) num = tmp; } head = (num / p_lines) * p_lines; show_brdlist(head, 1, newflag); - } else if(num < head || num >= head + p_lines) { + } else if (num < head || num >= head + p_lines) { head = (num / p_lines) * p_lines; show_brdlist(head, 0, newflag); } - if(class_bid == 1) + if (class_bid == 1) ch = cursor_key(7 + num - head, 10); else ch = cursor_key(3 + num - head, 0); - - switch(ch) { + + switch (ch) { case Ctrl('W'): - whereami(0,NULL,NULL); - head=-1; + whereami(0, NULL, NULL); + head = -1; break; case 'e': case KEY_LEFT: case EOF: ch = 'q'; case 'q': - if(keyword[0]) - { - keyword[0]=0; - brdnum=-1; - ch=' '; - } + if (keyword[0]) { + keyword[0] = 0; + brdnum = -1; + ch = ' '; + } break; case 'c': show_brdlist(head, 1, newflag ^= 1); @@ -746,7 +789,7 @@ static void choose_board(int newflag) { case 'P': case 'b': case Ctrl('B'): - if(num) { + if (num) { num -= p_lines; break; } @@ -758,7 +801,7 @@ static void choose_board(int newflag) { case KEY_PGDN: case 'N': case Ctrl('F'): - if(num == brdnum - 1) + if (num == brdnum - 1) num = 0; else num += p_lines; @@ -778,10 +821,10 @@ static void choose_board(int newflag) { num = brdnum - 1; break; case 't': - ptr = &nbrd[num]; - ptr->myattr ^= BRD_TAG; - favbuf[ptr->bid-1]=ptr->myattr; - head = 9999; + ptr = &nbrd[num]; + ptr->myattr ^= BRD_TAG; + favbuf[ptr->bid - 1] = ptr->myattr; + head = 9999; case KEY_DOWN: case 'n': case 'j': @@ -800,104 +843,98 @@ static void choose_board(int newflag) { case '7': case '8': case '9': - if((tmp = search_num(ch, brdnum)) >= 0) + if ((tmp = search_num(ch, brdnum)) >= 0) num = tmp; brdlist_foot(); break; - case 'F': - case 'f': - if(class_bid && HAS_PERM(PERM_SYSOP)) - { - bcache[class_bid-1].firstchild[cuser.uflag&BRDSORT_FLAG?1:0] - =NULL; - brdnum = -1; - } + case 'F': + case 'f': + if (class_bid && HAS_PERM(PERM_SYSOP)) { + bcache[class_bid - 1].firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] + = NULL; + brdnum = -1; + } break; case 'h': show_help(choosebrdhelp); show_brdlist(head, 1, newflag); break; case '/': - getdata_buf(b_lines-1,0,"½Ð¿é¤J¬ÝªO¤¤¤åÃöÁä¦r:", + getdata_buf(b_lines - 1, 0, "½Ð¿é¤J¬ÝªO¤¤¤åÃöÁä¦r:", keyword, sizeof(keyword), DOECHO); - brdnum=-1; + brdnum = -1; break; case 'S': cuser.uflag ^= BRDSORT_FLAG; brdnum = -1; break; case 'y': - if(class_bid==0) - yank_flag = (yank_flag+1)%3; - else - yank_flag = yank_flag%2+1; + if (class_bid == 0) + yank_flag = (yank_flag + 1) % 3; + else + yank_flag = yank_flag % 2 + 1; brdnum = -1; break; case Ctrl('D'): - for(tmp = 0; tmp < numboards; tmp++) - { - if(favbuf[tmp] & BRD_TAG) - { - favbuf[tmp] &= ~BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; - } - } - brdnum = -1; - break; + for (tmp = 0; tmp < numboards; tmp++) { + if (favbuf[tmp] & BRD_TAG) { + favbuf[tmp] &= ~BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; case Ctrl('A'): - for(tmp = 0; tmp < numboards; tmp++) - { - if(favbuf[tmp] & BRD_TAG) - { - favbuf[tmp] |= BRD_FAV; - favbuf[tmp] &= ~BRD_TAG; - } - } - brdnum = -1; - break; + for (tmp = 0; tmp < numboards; tmp++) { + if (favbuf[tmp] & BRD_TAG) { + favbuf[tmp] |= BRD_FAV; + favbuf[tmp] &= ~BRD_TAG; + } + } + brdnum = -1; + break; case Ctrl('T'): - for(tmp = 0; tmp < numboards; tmp++) - favbuf[tmp] &= ~BRD_TAG; - brdnum = -1; - break; - case Ctrl('P'): - if(class_bid!=0 && - (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - for(tmp = 0; tmp < numboards; tmp++) { - boardheader_t *bh=&bcache[tmp]; - if(!(favbuf[tmp]&BRD_TAG) || bh->gid==class_bid) - continue; - favbuf[tmp] &= ~BRD_TAG; - if(bh->gid != class_bid) - { - bh->gid = class_bid; - substitute_record(FN_BOARD, bh, - sizeof(boardheader_t), tmp+1); - reset_board(tmp+1); - log_usies("SetBoardGID", bh->brdname); - } - } - brdnum = -1; - } - break; + for (tmp = 0; tmp < numboards; tmp++) + favbuf[tmp] &= ~BRD_TAG; + brdnum = -1; + break; + case Ctrl('P'): + if (class_bid != 0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + for (tmp = 0; tmp < numboards; tmp++) { + boardheader_t *bh = &bcache[tmp]; + if (!(favbuf[tmp] & BRD_TAG) || bh->gid == class_bid) + continue; + favbuf[tmp] &= ~BRD_TAG; + if (bh->gid != class_bid) { + bh->gid = class_bid; + substitute_record(FN_BOARD, bh, + sizeof(boardheader_t), tmp + 1); + reset_board(tmp + 1); + log_usies("SetBoardGID", bh->brdname); + } + } + brdnum = -1; + } + break; case 'm': - if(HAS_PERM(PERM_BASIC)) { + if (HAS_PERM(PERM_BASIC)) { ptr = &nbrd[num]; - ptr->myattr ^= BRD_FAV; - favbuf[ptr->bid-1]=ptr->myattr; + ptr->myattr ^= BRD_FAV; + favbuf[ptr->bid - 1] = ptr->myattr; head = 9999; } break; case 'z': - if(HAS_PERM(PERM_BASIC)) { - dozap(num); + if (HAS_PERM(PERM_BASIC)) { + dozap(num); head = 9999; } break; - case 'Z': /* Ptt */ - if(HAS_PERM(PERM_BASIC)) { - for(tmp = 0; tmp < brdnum; tmp++) { - dozap(tmp); + case 'Z': /* Ptt */ + if (HAS_PERM(PERM_BASIC)) { + for (tmp = 0; tmp < brdnum; tmp++) { + dozap(tmp); } head = 9999; } @@ -906,51 +943,50 @@ static void choose_board(int newflag) { case 'V': ptr = &nbrd[num]; brc_initial(ptr->bh->brdname); - if(ch == 'v') { + if (ch == 'v') { ptr->myattr &= ~BRD_UNREAD; - zapbuf[ptr->bid-1] = brc_list[0]=now; - } else - { - zapbuf[ptr->bid-1] = brc_list[0] = 1; - ptr->myattr |= BRD_UNREAD; - } + zapbuf[ptr->bid - 1] = brc_list[0] = now; + } else { + zapbuf[ptr->bid - 1] = brc_list[0] = 1; + ptr->myattr |= BRD_UNREAD; + } brc_num = brc_changed = 1; brc_update(); show_brdlist(head, 0, newflag); break; case 's': - if((tmp = search_board()) == -1) { + if ((tmp = search_board()) == -1) { show_brdlist(head, 1, newflag); break; } num = tmp; case 'E': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { ptr = &nbrd[num]; - move(1,1); + move(1, 1); clrtobot(); m_mod_board(ptr->bh->brdname); brdnum = -1; } break; case 'R': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { m_newbrd(1); brdnum = -1; } break; case 'B': - if(HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { + if (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU)) { m_newbrd(0); brdnum = -1; } break; case 'W': - if(class_bid > 0 && - (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { - char buf[128]; - setbpath(buf, bcache[class_bid-1].brdname); - mkdir(buf, 0755) ; //Ptt:¶}¸s²Õ¥Ø¿ý + if (class_bid > 0 && + (HAS_PERM(PERM_SYSOP) || (currmode & MODE_MENU))) { + char buf[128]; + setbpath(buf, bcache[class_bid - 1].brdname); + mkdir(buf, 0755); /* Ptt:¶}¸s²Õ¥Ø¿ý */ b_note_edit_bname(class_bid); brdnum = -1; } @@ -959,92 +995,98 @@ static void choose_board(int newflag) { case '\n': case '\r': case 'r': - { - char buf[STRLEN]; - - ptr = &nbrd[num]; - - if(!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* «Dsub class */ - if(!(ptr->bh->brdattr & BRD_HIDE) || - (ptr->bh->brdattr & BRD_POSTMASK)) { - brc_initial(ptr->bh->brdname); - - if(newflag) { - setbdir(buf, currboard); - tmp = unread_position(buf, ptr); - head = tmp - t_lines / 2; - getkeep(buf, head > 1 ? head : 1, tmp + 1); + { + char buf[STRLEN]; + + ptr = &nbrd[num]; + + if (!(ptr->bh->brdattr & BRD_GROUPBOARD)) { /* «Dsub class */ + if (!(ptr->bh->brdattr & BRD_HIDE) || + (ptr->bh->brdattr & BRD_POSTMASK)) { + brc_initial(ptr->bh->brdname); + + if (newflag) { + setbdir(buf, currboard); + tmp = unread_position(buf, ptr); + head = tmp - t_lines / 2; + getkeep(buf, head > 1 ? head : 1, tmp + 1); + } + board_visit_time = zapbuf[ptr->bid - 1]; + if (!(ptr->myattr & BRD_ZAP)) + zapbuf[ptr->bid - 1] = now; + Read(); + check_newpost(ptr); + head = -1; + setutmpmode(newflag ? READNEW : READBRD); + } else { + setbfile(buf, ptr->bh->brdname, FN_APPLICATION); + if (more(buf, YEA) == -1) { + move(1, 0); + clrtobot(); + outs(privateboard); + pressanykey(); + } + head = -1; } - board_visit_time = zapbuf[ptr->bid-1]; - if(!(ptr->myattr&BRD_ZAP)) - zapbuf[ptr->bid-1]=now; - Read(); - check_newpost(ptr); - head = -1; - setutmpmode(newflag ? READNEW : READBRD); - } else { - setbfile(buf, ptr->bh->brdname, FN_APPLICATION); - if(more(buf,YEA)==-1) { - move(1,0); - clrtobot(); - outs(privateboard); - pressanykey(); + } else { /* sub class */ + move(12, 1); + bidtmp = class_bid; + currmodetmp = currmode; + tmp1 = num; + num = 0; + if (!(ptr->bh->brdattr & BRD_TOP)) + class_bid = ptr->bid; + else + class_bid = -1; /* ¼öªù¸s²Õ¥Î */ + + if (!(currmode & MODE_MENU)) /* ¦pªGÁÙ¨S¦³¤p²ÕªøÅv */ + set_menu_BM(ptr->bh->BM); + + if (now < ptr->bh->bupdate) { + setbfile(buf, ptr->bh->brdname, fn_notes); + if (more(buf, NA) != -1) + pressanykey(); } - head = -1; + tmp = currutmp->brc_id; + setutmpbid(ptr->bid); + free(nbrd); + choose_board(0); + currmode = currmodetmp; /* Â÷¶}ªOªO«á´N§âÅv®³±¼³á */ + num = tmp1; + class_bid = bidtmp; + setutmpbid(tmp); + brdnum = -1; } - } else { /* sub class */ - move(12,1); - bidtmp = class_bid; - currmodetmp =currmode; - tmp1=num; - num=0; - if(!(ptr->bh->brdattr & BRD_TOP)) - class_bid = ptr->bid; - else - class_bid = -1; /* ¼öªù¸s²Õ¥Î */ - - if (!(currmode & MODE_MENU))/*¦pªGÁÙ¨S¦³¤p²ÕªøÅv */ - set_menu_BM(ptr->bh->BM); - - if(now < ptr->bh->bupdate) { - setbfile(buf, ptr->bh->brdname, fn_notes); - if(more(buf, NA) != -1) - pressanykey(); - } - tmp=currutmp->brc_id; - setutmpbid(ptr->bid); - free(nbrd); - choose_board(0); - currmode = currmodetmp; /* Â÷¶}ªOªO«á´N§âÅv®³±¼³á */ - num=tmp1; - class_bid = bidtmp; - setutmpbid(tmp); - brdnum = -1; } } - } - } while(ch != 'q'); + } while (ch != 'q'); free(nbrd); } -int root_board() { +int +root_board() +{ class_bid = 1; yank_flag = 1; choose_board(0); return 0; } -int Boards() { +int +Boards() +{ class_bid = 0; - yank_flag = 0; + yank_flag = 0; choose_board(0); return 0; } -int New() { - int mode0 = currutmp->mode; - int stat0 = currstat; +int +New() +{ + int mode0 = currutmp->mode; + int stat0 = currstat; class_bid = 0; choose_board(1); @@ -1054,48 +1096,28 @@ int New() { } /* -int v_favorite(){ - char fname[256]; - char inbuf[2048]; - FILE* fp; - int nGroup; - char* strtmp; - - setuserfile(fname,str_favorite); - - if (!(fp=fopen(fname,"r"))) - return -1; - move(0,0); - clrtobot(); - fgets(inbuf,sizeof(inbuf),fp); - nGroup=atoi(inbuf); - - currutmp->nGroup=0; - currutmp->ninRoot=0; - - while(nGroup!=currutmp->nGroup+1){ - fgets(inbuf,sizeof(inbuf),fp); - prints("%s\n",strtmp=strtok(inbuf," \n")); - strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); - while((strtmp=strtok(NULL, " \n"))){ - prints(" %s %d\n",strtmp,getbnum(strtmp)); - } - currutmp->nGroup++; - } - prints("+++%d+++\n",currutmp->nGroup); - - fgets(inbuf,sizeof(inbuf),fp); - - for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ - if (strtmp[0]!='#') - prints("*** %s %d\n",strtmp, getbnum(strtmp)); - else - prints("*** %s %d\n",strtmp+1, -1); - currutmp->ninRoot++; - } - - fclose(fp); - pressanykey(); - return 0; -} -*/ + * int v_favorite(){ char fname[256]; char inbuf[2048]; FILE* fp; int nGroup; + * char* strtmp; + * + * setuserfile(fname,str_favorite); + * + * if (!(fp=fopen(fname,"r"))) return -1; move(0,0); clrtobot(); + * fgets(inbuf,sizeof(inbuf),fp); nGroup=atoi(inbuf); + * + * currutmp->nGroup=0; currutmp->ninRoot=0; + * + * while(nGroup!=currutmp->nGroup+1){ fgets(inbuf,sizeof(inbuf),fp); + * prints("%s\n",strtmp=strtok(inbuf," \n")); + * strcpy(currutmp->gfavorite[currutmp->nGroup++],strtmp); + * while((strtmp=strtok(NULL, " \n"))){ prints(" %s + * %d\n",strtmp,getbnum(strtmp)); } currutmp->nGroup++; } + * prints("+++%d+++\n",currutmp->nGroup); + * + * fgets(inbuf,sizeof(inbuf),fp); + * + * for(strtmp=strtok(inbuf, " \n");strtmp;strtmp=strtok(NULL, " \n")){ if + * (strtmp[0]!='#') prints("*** %s %d\n",strtmp, getbnum(strtmp)); else + * prints("*** %s %d\n",strtmp+1, -1); currutmp->ninRoot++; } + * + * fclose(fp); pressanykey(); return 0; } + */ diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 206b39e3..5f97c503 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -1,99 +1,115 @@ -/* $Id: cache.c,v 1.40 2002/07/04 19:46:16 in2 Exp $ */ +/* $Id: cache.c,v 1.41 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" #ifndef __FreeBSD__ union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short int *array; /* array for GETALL, SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short int *array; /* array for GETALL, SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -/* the reason for "safe_sleep" is that we may call sleep during - SIGALRM handler routine, while SIGALRM is blocked. - if we use the original sleep, we'll never wake up. */ -unsigned int safe_sleep(unsigned int seconds) { - /* jochang sleep¦³°ÝÃD®É¥Î*/ - sigset_t set,oldset; - +/* + * the reason for "safe_sleep" is that we may call sleep during SIGALRM + * handler routine, while SIGALRM is blocked. if we use the original sleep, + * we'll never wake up. + */ +unsigned int +safe_sleep(unsigned int seconds) +{ + /* jochang sleep¦³°ÝÃD®É¥Î */ + sigset_t set, oldset; + sigemptyset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); - if(sigismember(&oldset, SIGALRM)) { - unsigned long retv; + if (sigismember(&oldset, SIGALRM)) { + unsigned long retv; #if !defined(_BBS_UTIL_C_) log_usies("SAFE_SLEEP ", "avoid hang"); #endif sigemptyset(&set); - sigaddset(&set,SIGALRM); - sigprocmask(SIG_UNBLOCK,&set,NULL); - retv=sleep(seconds); - sigprocmask(SIG_BLOCK,&set,NULL); + sigaddset(&set, SIGALRM); + sigprocmask(SIG_UNBLOCK, &set, NULL); + retv = sleep(seconds); + sigprocmask(SIG_BLOCK, &set, NULL); return retv; } return sleep(seconds); } #if defined(_BBS_UTIL_C_) -static void setapath(char *buf, char *boardname) { +static void +setapath(char *buf, char *boardname) +{ sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } -static char *str_dotdir = ".DIR"; +static char *str_dotdir = ".DIR"; -static void setadir(char *buf, char *path) { +static void +setadir(char *buf, char *path) +{ sprintf(buf, "%s/%s", path, str_dotdir); } #endif -static void attach_err(int shmkey, char *name) { +static void +attach_err(int shmkey, char *name) +{ fprintf(stderr, "[%s error] key = %x\n", name, shmkey); fprintf(stderr, "errno = %d: %s\n", errno, strerror(errno)); exit(1); } -void *attach_shm(int shmkey, int shmsize) { - void *shmptr; - int shmid; +void * +attach_shm(int shmkey, int shmsize) +{ + void *shmptr; + int shmid; shmid = shmget(shmkey, shmsize, 0); - if(shmid < 0) { + if (shmid < 0) { shmid = shmget(shmkey, shmsize, IPC_CREAT | 0600); - if(shmid < 0) + if (shmid < 0) attach_err(shmkey, "shmget"); shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) + if (shmptr == (void *)-1) attach_err(shmkey, "shmat"); } else { shmptr = (void *)shmat(shmid, NULL, 0); - if(shmptr == (void *)-1) + if (shmptr == (void *)-1) attach_err(shmkey, "shmat"); } - + return shmptr; } -#define SEM_FLG 0600 /* semaphore mode */ +#define SEM_FLG 0600 /* semaphore mode */ /* ----------------------------------------------------- */ /* semaphore : for critical section */ /* ----------------------------------------------------- */ -void sem_init(int semkey,int *semid) { - union semun s; +void +sem_init(int semkey, int *semid) +{ + union semun s; - s.val=1; + s.val = 1; *semid = semget(semkey, 1, 0); - if(*semid == -1) { + if (*semid == -1) { *semid = semget(semkey, 1, IPC_CREAT | SEM_FLG); - if(*semid == -1) + if (*semid == -1) attach_err(semkey, "semget"); semctl(*semid, 0, SETVAL, s); } } -void sem_lock(int op,int semid) { - struct sembuf sops; +void +sem_lock(int op, int semid) +{ + struct sembuf sops; sops.sem_num = 0; sops.sem_flg = SEM_UNDO; @@ -101,94 +117,113 @@ void sem_lock(int op,int semid) { semop(semid, &sops, 1); } -/* uhash *******************************************/ -/* the design is this: - we use another stand-alone program to create and load data into the hash. - (that program could be run in rc-scripts or something like that) - after loading completes, the stand-alone program sets loaded to 1 and exits. - - the bbs exits if it can't attach to the shared memory or - the hash is not loaded yet. -*/ +/* uhash ****************************************** */ +/* + * the design is this: we use another stand-alone program to create and load + * data into the hash. (that program could be run in rc-scripts or something + * like that) after loading completes, the stand-alone program sets loaded to + * 1 and exits. + * + * the bbs exits if it can't attach to the shared memory or the hash is not + * loaded yet. + */ /* attach_uhash should be called before using uhash */ -void attach_SHM(void) +void +attach_SHM(void) { SHM = attach_shm(SHM_KEY, sizeof(SHM_t)); - if( !SHM->loaded ) /* (uhash) assume fresh shared memory is zeroed */ + if (!SHM->loaded) /* (uhash) assume fresh shared memory is + * zeroed */ exit(1); - if( SHM->Btouchtime == 0 ) + if (SHM->Btouchtime == 0) SHM->Btouchtime = 1; bcache = SHM->bcache; - + GLOBALVAR = SHM->GLOBALVAR; - if( SHM->Ptouchtime == 0 ) + if (SHM->Ptouchtime == 0) SHM->Ptouchtime = 1; - if( SHM->Ftouchtime == 0 ) + if (SHM->Ftouchtime == 0) SHM->Ftouchtime = 1; } -void add_to_uhash(int n, char *id) { - int *p, h = StringHash(id); - int times; +void +add_to_uhash(int n, char *id) +{ + int *p, h = StringHash(id); + int times; strcpy(SHM->userid[n], id); - + p = &(SHM->hash_head[h]); - - for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times ) + + for (times = 0; times < MAX_USERS && *p != -1; ++times) p = &(SHM->next_in_hash[*p]); - if( times == MAX_USERS ) + if (times == MAX_USERS) abort_bbs(0); SHM->next_in_hash[*p = n] = -1; } -/* note: after remove_from_uhash(), you should add_to_uhash() - (likely with a different name) */ -void remove_from_uhash(int n) { - int h = StringHash(SHM->userid[n]); - int *p = &(SHM->hash_head[h]); - int times; +/* + * note: after remove_from_uhash(), you should add_to_uhash() (likely with a + * different name) + */ +void +remove_from_uhash(int n) +{ + int h = StringHash(SHM->userid[n]); + int *p = &(SHM->hash_head[h]); + int times; - for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times ) + for (times = 0; times < MAX_USERS && (*p != -1 && *p != n); ++times) p = &(SHM->next_in_hash[*p]); - if( times == MAX_USERS ) + if (times == MAX_USERS) abort_bbs(0); - if(*p == n) + if (*p == n) *p = SHM->next_in_hash[n]; } -int setumoney(int uid, int money) { - SHM->money[uid-1]=money; - passwd_update_money(uid); - return SHM->money[uid-1]; +int +setumoney(int uid, int money) +{ + SHM->money[uid - 1] = money; + passwd_update_money(uid); + return SHM->money[uid - 1]; } -int deumoney(int uid, int money) { - if(money<0 && SHM->money[uid-1]<-money) - return setumoney(uid,0); - else - return setumoney(uid,SHM->money[uid-1]+money); +int +deumoney(int uid, int money) +{ + if (money < 0 && SHM->money[uid - 1] < -money) + return setumoney(uid, 0); + else + return setumoney(uid, SHM->money[uid - 1] + money); } -int demoney(int money) { - return deumoney(usernum,money); -} -int moneyof(int uid){ /* ptt §ï¶iª÷¿ú³B²z®Ä²v */ - return SHM->money[uid-1]; +int +demoney(int money) +{ + return deumoney(usernum, money); } -int searchuser(char *userid) { - int h, p, times; +int +moneyof(int uid) +{ /* ptt §ï¶iª÷¿ú³B²z®Ä²v */ + return SHM->money[uid - 1]; +} +int +searchuser(char *userid) +{ + int h, p, times; h = StringHash(userid); p = SHM->hash_head[h]; - - for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){ - if(strcasecmp(SHM->userid[p],userid) == 0) { - strcpy(userid,SHM->userid[p]); + + for (times = 0; times < MAX_USERS && p != -1; ++times) { + if (strcasecmp(SHM->userid[p], userid) == 0) { + strcpy(userid, SHM->userid[p]); return p + 1; } p = SHM->next_in_hash[p]; @@ -199,70 +234,80 @@ int searchuser(char *userid) { #if !defined(_BBS_UTIL_C_) -int getuser(char *userid) { - int uid; - - if((uid = searchuser(userid))) +int +getuser(char *userid) +{ + int uid; + + if ((uid = searchuser(userid))) passwd_query(uid, &xuser); return uid; } -char *getuserid(int num) { - if(--num >= 0 && num < MAX_USERS) - return ((char *) SHM->userid[num]); +char * +getuserid(int num) +{ + if (--num >= 0 && num < MAX_USERS) + return ((char *)SHM->userid[num]); return NULL; } -void setuserid(int num, char *userid) { - if(num > 0 && num <= MAX_USERS) { - if(num > SHM->number) +void +setuserid(int num, char *userid) +{ + if (num > 0 && num <= MAX_USERS) { + if (num > SHM->number) SHM->number = num; else - remove_from_uhash(num-1); - add_to_uhash(num-1,userid); + remove_from_uhash(num - 1); + add_to_uhash(num - 1, userid); } } /* 0 ==> §ä¹L´Á±b¸¹ */ /* 1 ==> «Ø¥ß·s±b¸¹ */ /* should do it by searching "" in the hash */ -int searchnewuser(int mode) { - register int i, num; +int +searchnewuser(int mode) +{ + register int i, num; num = SHM->number; i = 0; /* ¬°¤°»ò³oÃ䤣¥Î hash table ¥h§ä¦Ón¥Î linear search? */ - while(i < num) { - if(!SHM->userid[i++][0]) + while (i < num) { + if (!SHM->userid[i++][0]) return i; } - if(mode && (num < MAX_USERS)) + if (mode && (num < MAX_USERS)) return num + 1; return 0; } -char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { - register char *ptr, tmp; - register int n, total; - char tagbuf[STRLEN]; - int ch, ch2, num; +char * +u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) +{ + register char *ptr, tmp; + register int n, total; + char tagbuf[STRLEN]; + int ch, ch2, num; - if(*tag == '\0') { + if (*tag == '\0') { *pnum = SHM->number; return SHM->userid[0]; } - for(n = 0; tag[n]; n++) + for (n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; ch = tagbuf[0]; ch2 = ch - 'A' + 'a'; total = SHM->number; - for(n = num = 0; n < total; n++) { + for (n = num = 0; n < total; n++) { ptr = SHM->userid[n]; tmp = *ptr; - if(tmp == ch || tmp == ch2) { - if(chkstr(tag, tagbuf, ptr)) + if (tmp == ch || tmp == ch2) { + if (chkstr(tag, tagbuf, ptr)) strcpy(buf[num++], ptr); } } @@ -275,92 +320,110 @@ char *u_namearray(char buf[][IDLEN + 1], int *pnum, char *tag) { /* .UTMP cache */ /*-------------------------------------------------------*/ #if !defined(_BBS_UTIL_C_) -void setutmpmode(int mode) { - if(currstat != mode) +void +setutmpmode(int mode) +{ + if (currstat != mode) currutmp->mode = currstat = mode; - + /* °lÂÜ¨Ï¥ÎªÌ */ - if(HAS_PERM(PERM_LOGUSER)) { - char msg[200]; + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; sprintf(msg, "%s setutmpmode to %s(%d) at %s", cuser.userid, modestring(currutmp, 0), mode, Cdate(&now)); log_user(msg); } } #endif -static int cmputmpuserid(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->userid, (*((userinfo_t**)j))->userid); +static int +cmputmpuserid(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); } -static int cmputmpmode(const void *i, const void *j){ - return (*((userinfo_t**)i))->mode-(*((userinfo_t**)j))->mode; -} +static int +cmputmpmode(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; +} -static int cmputmpidle(const void *i, const void *j){ - return (*((userinfo_t**)i))->lastact-(*((userinfo_t**)j))->lastact; -} +static int +cmputmpidle(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; +} -static int cmputmpfrom(const void *i, const void *j){ - return strcasecmp((*((userinfo_t**)i))->from, (*((userinfo_t**)j))->from); -} +static int +cmputmpfrom(const void *i, const void *j) +{ + return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); +} -static int cmputmpfive(const void *i, const void *j){ - int type; - if((type=(*((userinfo_t**)j))->five_win - (*((userinfo_t**)i))->five_win)) - return type; - if((type=(*((userinfo_t**)i))->five_lose - (*((userinfo_t**)j))->five_lose)) - return type; - return (*((userinfo_t**)i))->five_tie-(*((userinfo_t**)j))->five_tie; -} +static int +cmputmpfive(const void *i, const void *j) +{ + int type; + if ((type = (*((userinfo_t **) j))->five_win - (*((userinfo_t **) i))->five_win)) + return type; + if ((type = (*((userinfo_t **) i))->five_lose - (*((userinfo_t **) j))->five_lose)) + return type; + return (*((userinfo_t **) i))->five_tie - (*((userinfo_t **) j))->five_tie; +} #if 0 -static int cmputmpsex(const void *i, const void *j) +static int +cmputmpsex(const void *i, const void *j) { - static int ladyfirst[]={1,0,1,0,1,0,3,3}; - return ladyfirst[(*(userinfo_t**)i)->sex&07]- - ladyfirst[(*(userinfo_t**)j)->sex&07]; + static int ladyfirst[] = {1, 0, 1, 0, 1, 0, 3, 3}; + return ladyfirst[(*(userinfo_t **) i)->sex & 07] - + ladyfirst[(*(userinfo_t **) j)->sex & 07]; } #endif -static int cmputmppid(const void *i, const void *j){ - return (*((userinfo_t**)i))->pid-(*((userinfo_t**)j))->pid; +static int +cmputmppid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; } -static int cmputmpuid(const void *i, const void *j){ - return (*((userinfo_t**)i))->uid-(*((userinfo_t**)j))->uid; +static int +cmputmpuid(const void *i, const void *j) +{ + return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; } -void sort_utmp() +void +sort_utmp() { - userinfo_t *uentp; - int count, i, ns; - short nusers[MAX_BOARD]; + userinfo_t *uentp; + int count, i, ns; + short nusers[MAX_BOARD]; now = time(0); - if( now - SHM->UTMPuptime < 60 && - (now == SHM->UTMPuptime || SHM->UTMPbusystate) ) - return; /* lazy sort */ - SHM->UTMPbusystate=1; + if (now - SHM->UTMPuptime < 60 && + (now == SHM->UTMPuptime || SHM->UTMPbusystate)) + return; /* lazy sort */ + SHM->UTMPbusystate = 1; SHM->UTMPuptime = now; ns = (SHM->currsorted ? 0 : 1); - - for( uentp = &SHM->uinfo[0], count = i = 0 ; - i < USHM_SIZE ; - ++i, uentp = &SHM->uinfo[i] ){ - if( uentp->pid ){ - if( uentp->sex < 0 || uentp->sex > 7 ) + + for (uentp = &SHM->uinfo[0], count = i = 0; + i < USHM_SIZE; + ++i, uentp = &SHM->uinfo[i]) { + if (uentp->pid) { + if (uentp->sex < 0 || uentp->sex > 7) purge_utmp(uentp); else SHM->sorted[ns][0][count++] = uentp; - } + } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t*), cmputmpuserid); - for( i = 0 ; i < count ; ++i ) - ((userinfo_t*)SHM->sorted[ns][0][i])->idoffset = i; - memcpy(SHM->sorted[ns][1],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][2],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][3],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][4],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][5],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][6],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); - memcpy(SHM->sorted[ns][7],SHM->sorted[ns][0], sizeof(userinfo_t*) * count); + qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); + for (i = 0; i < count; ++i) + ((userinfo_t *) SHM->sorted[ns][0][i])->idoffset = i; + memcpy(SHM->sorted[ns][1], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][2], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][3], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][4], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][5], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][6], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + memcpy(SHM->sorted[ns][7], SHM->sorted[ns][0], sizeof(userinfo_t *) * count); qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode); qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle); qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom); @@ -368,29 +431,31 @@ void sort_utmp() //qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpsex); qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid); qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid); - SHM->currsorted=ns; - SHM->UTMPbusystate=0; + SHM->currsorted = ns; + SHM->UTMPbusystate = 0; memset(nusers, 0, sizeof(nusers)); - for( i = 0 ; i < count ; ++i ){ + for (i = 0; i < count; ++i) { uentp = SHM->sorted[ns][0][i]; - if( uentp && uentp->pid && - 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD ) - ++nusers[ uentp->brc_id - 1 ]; + if (uentp && uentp->pid && + 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) + ++nusers[uentp->brc_id - 1]; } - for( i = 0 ; i < SHM->Bnumber ; ++i ) - if( SHM->bcache[i].brdname[0] != 0 ) + for (i = 0; i < SHM->Bnumber; ++i) + if (SHM->bcache[i].brdname[0] != 0) SHM->bcache[i].nuser = nusers[i]; } -// Ptt:³oÃä¥[¤JhashÆ[©À §äªÅªºutmp -void getnewutmpent(userinfo_t *up) { - register int i, p ; +//Ptt:³o à ä¥[¤Jhash Æ[©À§äªÅªºutmp + void getnewutmpent(userinfo_t * up) + { + register int i, p; register userinfo_t *uentp; - for(i = 0, p=StringHash(up->userid)%USHM_SIZE; i < USHM_SIZE; i++, p++) { - if(p==USHM_SIZE) p=0; + for (i = 0, p = StringHash(up->userid) % USHM_SIZE; i < USHM_SIZE; i++, p++) { + if (p == USHM_SIZE) + p = 0; uentp = &(SHM->uinfo[p]); - if(!(uentp->pid)) { + if (!(uentp->pid)) { memcpy(uentp, up, sizeof(userinfo_t)); currutmp = uentp; sort_utmp(); @@ -400,75 +465,75 @@ void getnewutmpent(userinfo_t *up) { exit(1); } -int apply_ulist(int (*fptr)(userinfo_t *)) { +int +apply_ulist(int (*fptr) (userinfo_t *)) +{ register userinfo_t *uentp; - register int i, state; + register int i, state; - for(i = 0; i < USHM_SIZE; i++) { + for (i = 0; i < USHM_SIZE; i++) { uentp = &(SHM->uinfo[i]); - if(uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) - if((state = (*fptr) (uentp))) + if (uentp->pid && (PERM_HIDE(currutmp) || !PERM_HIDE(uentp))) + if ((state = (*fptr) (uentp))) return state; } return 0; } -userinfo_t *search_ulist(int uid) { - return search_ulistn(uid,1); +userinfo_t * +search_ulist(int uid) +{ + return search_ulistn(uid, 1); } -#if !defined(_BBS_UTIL_C_) -userinfo_t *search_ulist_pid(int pid) { - register int i=0, j, start = 0, end = SHM->UTMPnumber - 1; +#if !defined(_BBS_UTIL_C_) +userinfo_t * +search_ulist_pid(int pid) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][7]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - j=pid-ulist[i]->pid; - if(!j) - { - return (userinfo_t *) (ulist[i]); - } - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + ulist = SHM->sorted[SHM->currsorted][7]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + j = pid - ulist[i]->pid; + if (!j) { + return (userinfo_t *) (ulist[i]); + } + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } -userinfo_t *search_ulistn(int uid, int unum) +userinfo_t * +search_ulistn(int uid, int unum) { - register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][6]; - for( i = ((start + end) / 2) ; ; i = (start + end) / 2 ){ + ulist = SHM->sorted[SHM->currsorted][6]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { j = uid - ulist[i]->uid; - if( j == 0 ){ - for( ; i > 0 && uid == ulist[i - 1]->uid ; --i ) - ; /* «ü¨ì²Ä¤@µ§ */ - if( ulist[i + unum - 1]!=NULL && uid==ulist[i + unum - 1]->uid ) - return (userinfo_t *)(ulist[i + unum - 1]); - break; /* ¶W¹L½d³ò */ + if (j == 0) { + for (; i > 0 && uid == ulist[i - 1]->uid; --i); /* «ü¨ì²Ä¤@µ§ */ + if (ulist[i + unum - 1] != NULL && uid == ulist[i + unum - 1]->uid) + return (userinfo_t *) (ulist[i + unum - 1]); + break; /* ¶W¹L½d³ò */ } - if(end==start){ + if (end == start) { break; - } - else if(i == start){ + } else if (i == start) { i = end; start = end; - } - else if( j > 0 ) + } else if (j > 0) start = i; else end = i; @@ -476,44 +541,43 @@ userinfo_t *search_ulistn(int uid, int unum) return 0; } -int count_logins(int uid, int show) { - register int i=0, j, start = 0, end = SHM->UTMPnumber - 1, count; +int +count_logins(int uid, int show) +{ + register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; register userinfo_t **ulist; - if( end == -1 ) + if (end == -1) return NULL; - ulist=SHM->sorted[SHM->currsorted][6]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - j = uid-ulist[i]->uid; - if(!j) - { - for(;i>0 && uid==ulist[i-1]->uid;i--);/* «ü¨ì²Ä¤@µ§ */ - for(count=0;uid==ulist[i+count]->uid;count++) - { - if(show) - prints("(%d) ¥Ø«eª¬ºA¬°: %-17.16s(¨Ó¦Û %s)\n", - count+1, modestring(ulist[i+count], 0), - ulist[i+count]->from); - } - return count; - } - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + ulist = SHM->sorted[SHM->currsorted][6]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + j = uid - ulist[i]->uid; + if (!j) { + for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* «ü¨ì²Ä¤@µ§ */ + for (count = 0; uid == ulist[i + count]->uid; count++) { + if (show) + prints("(%d) ¥Ø«eª¬ºA¬°: %-17.16s(¨Ó¦Û %s)\n", + count + 1, modestring(ulist[i + count], 0), + ulist[i + count]->from); + } + return count; + } + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } -void purge_utmp(userinfo_t *uentp) { +void +purge_utmp(userinfo_t * uentp) +{ logout_friend_online(uentp); memset(uentp, 0, sizeof(userinfo_t)); } @@ -523,78 +587,89 @@ void purge_utmp(userinfo_t *uentp) { /*-------------------------------------------------------*/ /* .BOARDS cache */ /*-------------------------------------------------------*/ -void touchdircache(int bid) +void +touchdircache(int bid) { - int *i= (int *)&SHM->dircache[bid - 1][0].filename[0]; - *i=0; -} - -void load_fileheader_cache(int bid, char *direct) + int *i = (int *)&SHM->dircache[bid - 1][0].filename[0]; + *i = 0; +} + +void +load_fileheader_cache(int bid, char *direct) { - int num=getbtotal(bid); - int n = num-DIRCACHESIZE+1; - if( SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10 ){ - SHM->busystate_b[bid-1] = now; - get_records(direct, SHM->dircache[bid - 1] , - sizeof(fileheader_t),n<1?1:n, DIRCACHESIZE); - SHM->busystate_b[bid-1] = 0; - } - else{ + int num = getbtotal(bid); + int n = num - DIRCACHESIZE + 1; + if (SHM->Bbusystate != 1 && now - SHM->busystate_b[bid - 1] >= 10) { + SHM->busystate_b[bid - 1] = now; + get_records(direct, SHM->dircache[bid - 1], + sizeof(fileheader_t), n < 1 ? 1 : n, DIRCACHESIZE); + SHM->busystate_b[bid - 1] = 0; + } else { safe_sleep(1); } } -int get_fileheader_cache(int bid, char *direct, fileheader_t *headers, - int recbase, int nlines) +int +get_fileheader_cache(int bid, char *direct, fileheader_t * headers, + int recbase, int nlines) { - int ret, n,num; + int ret, n, num; - num=getbtotal(bid); + num = getbtotal(bid); - ret = num-recbase+1, - n = (num - DIRCACHESIZE+1); + ret = num - recbase + 1, + n = (num - DIRCACHESIZE + 1); - if(SHM->dircache[bid - 1][0].filename[0]=='\0') - load_fileheader_cache(bid, direct); - if (n<1) - n=recbase-1; + if (SHM->dircache[bid - 1][0].filename[0] == '\0') + load_fileheader_cache(bid, direct); + if (n < 1) + n = recbase - 1; else - n=recbase-n; - if(n<0) n=0; - if (ret>nlines) ret=nlines; - memcpy(headers, &(SHM->dircache[bid - 1][n]),sizeof(fileheader_t)*ret); + n = recbase - n; + if (n < 0) + n = 0; + if (ret > nlines) + ret = nlines; + memcpy(headers, &(SHM->dircache[bid - 1][n]), sizeof(fileheader_t) * ret); return ret; } -static int cmpboardname(boardheader_t **brd, boardheader_t **tmp) { +static int +cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) +{ return strcasecmp((*brd)->brdname, (*tmp)->brdname); -} -static int cmpboardclass(boardheader_t **brd, boardheader_t **tmp) { - return (strncmp((*brd)->title, (*tmp)->title, 4)<<8)+ - strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void sort_bcache() +static int +cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) +{ + return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + + strcasecmp((*brd)->brdname, (*tmp)->brdname); +} +static void +sort_bcache() { - int i; - /*critical section ¤£¯à³æ¿W©I¥s ©I¥sreload_bcache or reset_board */ - for(i=0;i<SHM->Bnumber;i++){ - SHM->bsorted[1][i]=SHM->bsorted[0][i]=&bcache[i]; - } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST)cmpboardname); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), - (QCAST)cmpboardclass); -} -static void reload_bcache() { - if( SHM->Bbusystate ){ + int i; + /* critical section ¤£¯à³æ¿W©I¥s ©I¥sreload_bcache or reset_board */ + for (i = 0; i < SHM->Bnumber; i++) { + SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; + } + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardname); + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), + (QCAST) cmpboardclass); +} +static void +reload_bcache() +{ + if (SHM->Bbusystate) { safe_sleep(1); } #if !defined(_BBS_UTIL_C_) else { - int fd,i; + int fd, i; SHM->Bbusystate = 1; - if((fd = open(fn_board, O_RDONLY)) > 0) { + if ((fd = open(fn_board, O_RDONLY)) > 0) { SHM->Bnumber = read(fd, bcache, MAX_BOARD * sizeof(boardheader_t)) / sizeof(boardheader_t); @@ -604,177 +679,189 @@ static void reload_bcache() { /* µ¥©Ò¦³ boards ¸ê®Æ§ó·s«á¦A³]©w uptime */ SHM->Buptime = SHM->Btouchtime; log_usies("CACHE", "reload bcache"); - sort_bcache(); - for( i = 0 ; i < SHM->Bnumber ; ++i ){ - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; + sort_bcache(); + for (i = 0; i < SHM->Bnumber; ++i) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; } SHM->Bbusystate = 0; } #endif } -void resolve_boards() { - while( SHM->Buptime < SHM->Btouchtime ){ +void +resolve_boards() +{ + while (SHM->Buptime < SHM->Btouchtime) { reload_bcache(); } numboards = SHM->Bnumber; } -void touch_boards() { - SHM->Btouchtime=now; +void +touch_boards() +{ + SHM->Btouchtime = now; numboards = -1; - resolve_boards(); + resolve_boards(); } -void addbrd_touchcache() +void +addbrd_touchcache() { SHM->Bnumber++; - numboards=SHM->Bnumber; - reset_board(numboards); + numboards = SHM->Bnumber; + reset_board(numboards); } #if !defined(_BBS_UTIL_C_) -void reset_board(int bid) { /* Ptt: ³o¼Ë´N¤£¥Î¦Ñ¬Otouch board¤F */ - int fd,i,nuser; - boardheader_t *bhdr; - +void +reset_board(int bid) +{ /* Ptt: ³o¼Ë´N¤£¥Î¦Ñ¬Otouch board¤F */ + int fd, i, nuser; + boardheader_t *bhdr; - if(--bid < 0) + + if (--bid < 0) return; - if( SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10 ){ + if (SHM->Bbusystate || now - SHM->busystate_b[bid - 1] < 10) { safe_sleep(1); } else { - SHM->busystate_b[bid-1] = now; - nuser = bcache[bid-1].nuser; + SHM->busystate_b[bid - 1] = now; + nuser = bcache[bid - 1].nuser; bhdr = bcache; - bhdr += bid; - if((fd = open(fn_board, O_RDONLY)) > 0) { - lseek(fd, (off_t)(bid * sizeof(boardheader_t)), SEEK_SET); + bhdr += bid; + if ((fd = open(fn_board, O_RDONLY)) > 0) { + lseek(fd, (off_t) (bid * sizeof(boardheader_t)), SEEK_SET); read(fd, bhdr, sizeof(boardheader_t)); close(fd); } - sort_bcache(); - for(i=0;i<SHM->Bnumber;i++) - { - bcache[i].firstchild[0]=NULL; - bcache[i].firstchild[1]=NULL; - } - nuser = bcache[bid-1].nuser; - SHM->busystate_b[bid-1] = 0; + sort_bcache(); + for (i = 0; i < SHM->Bnumber; i++) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; + } + nuser = bcache[bid - 1].nuser; + SHM->busystate_b[bid - 1] = 0; } -} +} -int apply_boards(int (*func)(boardheader_t *)) { - register int i; +int +apply_boards(int (*func) (boardheader_t *)) +{ + register int i; register boardheader_t *bhdr; - - for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { - if(!(bhdr->brdattr & BRD_GROUPBOARD) && Ben_Perm(bhdr) && - (*func)(bhdr) == QUIT) + + for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if (!(bhdr->brdattr & BRD_GROUPBOARD) && Ben_Perm(bhdr) && + (*func) (bhdr) == QUIT) return QUIT; } return 0; } #endif -boardheader_t *getbcache(int bid) { /* Ptt§ï¼g */ +boardheader_t * +getbcache(int bid) +{ /* Ptt§ï¼g */ return bcache + bid - 1; } -int getbtotal(int bid) +int +getbtotal(int bid) { return SHM->total[bid - 1]; } -void setbtotal(int bid) { - boardheader_t *bh = getbcache(bid); - struct stat st; - char genbuf[256]; - int num,fd; +void +setbtotal(int bid) +{ + boardheader_t *bh = getbcache(bid); + struct stat st; + char genbuf[256]; + int num, fd; sprintf(genbuf, "boards/%c/%s/.DIR", bh->brdname[0], bh->brdname); - if((fd = open(genbuf, O_RDWR)) < 0) - return; /* .DIR±¾¤F */ - fstat(fd, &st); - num = st.st_size / sizeof(fileheader_t); + if ((fd = open(genbuf, O_RDWR)) < 0) + return; /* .DIR±¾¤F */ + fstat(fd, &st); + num = st.st_size / sizeof(fileheader_t); SHM->total[bid - 1] = num; - if(num>0) - { - lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); - if(read(fd, genbuf, FNLEN)>=0) - { - SHM->lastposttime[bid - 1]=(time_t) atoi(&genbuf[2]); + if (num > 0) { + lseek(fd, (off_t) (num - 1) * sizeof(fileheader_t), SEEK_SET); + if (read(fd, genbuf, FNLEN) >= 0) { + SHM->lastposttime[bid - 1] = (time_t) atoi(&genbuf[2]); } - } - else - SHM->lastposttime[bid - 1] = 0; + } else + SHM->lastposttime[bid - 1] = 0; close(fd); - if(num) - touchdircache(bid); + if (num) + touchdircache(bid); } -void touchbpostnum(int bid, int delta) +void +touchbpostnum(int bid, int delta) { - int *total = &SHM->total[bid - 1]; + int *total = &SHM->total[bid - 1]; if (*total) *total += delta; } -int getbnum(char *bname) { - register int i=0, j, start = 0, end = SHM->Bnumber - 1; +int +getbnum(char *bname) +{ + register int i = 0, j, start = 0, end = SHM->Bnumber - 1; register boardheader_t **bhdr; - bhdr=SHM->bsorted[0]; - for(i=((start+end)/2); ;i=(start+end)/2) - { - if(! (j=strcasecmp(bname,bhdr[i]->brdname))) - return (int) (bhdr[i] - bcache +1); - if(end==start) - { - break; - } - else if(i==start) - { - i=end; - start=end; - } - else if(j>0) start = i; - else end = i; - } + bhdr = SHM->bsorted[0]; + for (i = ((start + end) / 2);; i = (start + end) / 2) { + if (!(j = strcasecmp(bname, bhdr[i]->brdname))) + return (int)(bhdr[i] - bcache + 1); + if (end == start) { + break; + } else if (i == start) { + i = end; + start = end; + } else if (j > 0) + start = i; + else + end = i; + } return 0; } #if !defined(_BBS_UTIL_C_) -int haspostperm(char *bname) { - register int i; - char buf[200]; +int +haspostperm(char *bname) +{ + register int i; + char buf[200]; setbfile(buf, bname, fn_water); - if(belong(buf, cuser.userid)) + if (belong(buf, cuser.userid)) return 0; - if(!strcasecmp(bname, DEFAULT_BOARD)) + if (!strcasecmp(bname, DEFAULT_BOARD)) return 1; if (!strcasecmp(bname, "PttLaw")) - return 1; + return 1; - if(!HAS_PERM(PERM_POST)) + if (!HAS_PERM(PERM_POST)) return 0; - - if(!(i = getbnum(bname))) + + if (!(i = getbnum(bname))) return 0; /* ¯µ±K¬ÝªO¯S§O³B²z */ - if(bcache[i - 1].brdattr & BRD_HIDE) + if (bcache[i - 1].brdattr & BRD_HIDE) return 1; i = bcache[i - 1].level; if (HAS_PERM(PERM_VIOLATELAW) && (i & PERM_VIOLATELAW)) - return 1; + return 1; else if (HAS_PERM(PERM_VIOLATELAW)) - return 0; + return 0; return HAS_PERM(i & ~PERM_POST); } @@ -784,15 +871,16 @@ int haspostperm(char *bname) { /* PTT cache */ /*-------------------------------------------------------*/ /* cachefor °ÊºA¬ÝªO© */ -void reload_pttcache() +void +reload_pttcache() { - if( SHM->Pbusystate ) + if (SHM->Pbusystate) safe_sleep(1); - else { /* jochang: temporary workaround */ - fileheader_t item, subitem; - char pbuf[256], buf[256], *chr; - FILE *fp, *fp1, *fp2; - int id, section = 0; + else { /* jochang: temporary workaround */ + fileheader_t item, subitem; + char pbuf[256], buf[256], *chr; + FILE *fp, *fp1, *fp2; + int id, section = 0; SHM->Pbusystate = 1; SHM->max_film = 0; @@ -800,53 +888,53 @@ void reload_pttcache() setapath(pbuf, "Note"); setadir(buf, pbuf); id = 0; - if((fp = fopen(buf, "r"))) { - while(fread(&item, sizeof(item), 1, fp)) { - if(item.title[3]=='<' && item.title[8]=='>') { - sprintf(buf,"%s/%s", pbuf, item.filename); + if ((fp = fopen(buf, "r"))) { + while (fread(&item, sizeof(item), 1, fp)) { + if (item.title[3] == '<' && item.title[8] == '>') { + sprintf(buf, "%s/%s", pbuf, item.filename); setadir(buf, buf); - if(!(fp1 = fopen(buf, "r"))) + if (!(fp1 = fopen(buf, "r"))) continue; SHM->next_refresh[section] = SHM->n_notes[section] = id; - section ++; - while(fread(&subitem, sizeof(subitem), 1, fp1)) { - sprintf(buf,"%s/%s/%s", pbuf, item.filename , + section++; + while (fread(&subitem, sizeof(subitem), 1, fp1)) { + sprintf(buf, "%s/%s/%s", pbuf, item.filename, subitem.filename); - if(!(fp2=fopen(buf,"r"))) + if (!(fp2 = fopen(buf, "r"))) continue; - fread(SHM->notes[id],sizeof(char), 200*11, fp2); - SHM->notes[id][200*11 - 1]=0; + fread(SHM->notes[id], sizeof(char), 200 * 11, fp2); + SHM->notes[id][200 * 11 - 1] = 0; id++; fclose(fp2); - if(id >= MAX_MOVIE) - break; + if (id >= MAX_MOVIE) + break; } - fclose(fp1); - if(id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) - break; + fclose(fp1); + if (id >= MAX_MOVIE || section >= MAX_MOVIE_SECTION) + break; } } fclose(fp); } SHM->next_refresh[section] = -1; - SHM->n_notes[section] = SHM->max_film = id-1; + SHM->n_notes[section] = SHM->max_film = id - 1; SHM->max_history = SHM->max_film - 2; - if(SHM->max_history > MAX_HISTORY - 1) + if (SHM->max_history > MAX_HISTORY - 1) SHM->max_history = MAX_HISTORY - 1; - if(SHM->max_history <0) SHM->max_history=0; + if (SHM->max_history < 0) + SHM->max_history = 0; - fp = fopen("etc/today_is","r"); - if(fp) { - fgets(SHM->today_is,15,fp); - if((chr = strchr(SHM->today_is,'\n'))) + fp = fopen("etc/today_is", "r"); + if (fp) { + fgets(SHM->today_is, 15, fp); + if ((chr = strchr(SHM->today_is, '\n'))) *chr = 0; SHM->today_is[15] = 0; fclose(fp); } - /* µ¥©Ò¦³¸ê®Æ§ó·s«á¦A³]©w uptime */ - SHM->Puptime = SHM->Ptouchtime ; + SHM->Puptime = SHM->Ptouchtime; #if !defined(_BBS_UTIL_C_) log_usies("CACHE", "reload pttcache"); #endif @@ -854,17 +942,20 @@ void reload_pttcache() } } -void resolve_garbage() { - int count=0; - - while(SHM->Puptime < SHM->Ptouchtime) { /* ¤£¥Îwhileµ¥ */ +void +resolve_garbage() +{ + int count = 0; + + while (SHM->Puptime < SHM->Ptouchtime) { /* ¤£¥Îwhileµ¥ */ reload_pttcache(); - if(count ++ > 10 && SHM->Pbusystate) { -/* Ptt: ³oÃä·|¦³°ÝÃD load¶W¹L10 ¬í·|©Ò¦³¶iloopªºprocess³£Åý busystate = 0 - ³o¼Ë·|©Ò¦³prcosee³£·|¦bload °ÊºA¬ÝªO ·|³y¦¨load¤j¼W - ¦ý¨S¦³¥Î³oÓfunctionªº¸Ü ¸U¤@load passwdÀɪºprocess¦º¤F ¤S¨S¦³¤H§â¥L - ¸Ñ¶} ¦P¼Ëªº°ÝÃDµo¥Í¦breload passwd -*/ + if (count++ > 10 && SHM->Pbusystate) { + /* + * Ptt: ³oÃä·|¦³°ÝÃD load¶W¹L10 ¬í·|©Ò¦³¶iloopªºprocess + * tate = 0 ³o¼Ë·|©Ò¦³prcosee³£·|¦bload °ÊºA¬ÝªO ·|³y¦¨load¤j¼W + * ¦ý¨S¦³¥Î³oÓfunctionªº¸Ü ¸U¤@load passwdÀɪºprocess¦º¤F + * ¤S¨S¦³¤H§â¥L ¸Ñ¶} ¦P¼Ëªº°ÝÃDµo¥Í¦breload passwd + */ SHM->Pbusystate = 0; #ifndef _BBS_UTIL_C_ log_usies("CACHE", "refork Ptt dead lock"); @@ -877,36 +968,37 @@ void resolve_garbage() { /* PTT's cache */ /*-------------------------------------------------------*/ /* cachefor from host »P³Ì¦h¤W½u¤H¼Æ */ -static void reload_fcache() { - if( SHM->Fbusystate ) +static void +reload_fcache() +{ + if (SHM->Fbusystate) safe_sleep(1); else { - FILE *fp; + FILE *fp; SHM->Fbusystate = 1; bzero(SHM->domain, sizeof(SHM->domain)); - if((fp = fopen("etc/domain_name_query","r"))) { - char buf[256],*po; - - SHM->top=0; - while(fgets(buf, sizeof(buf),fp)) { - if(buf[0] && buf[0] != '#' && buf[0] != ' ' && - buf[0] != '\n') { - sscanf(buf,"%s",SHM->domain[SHM->top]); + if ((fp = fopen("etc/domain_name_query", "r"))) { + char buf[256], *po; + + SHM->top = 0; + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] && buf[0] != '#' && buf[0] != ' ' && + buf[0] != '\n') { + sscanf(buf, "%s", SHM->domain[SHM->top]); po = buf + strlen(SHM->domain[SHM->top]); - while(*po == ' ') + while (*po == ' ') po++; - strncpy(SHM->replace[SHM->top],po,49); + strncpy(SHM->replace[SHM->top], po, 49); SHM->replace[SHM->top] - [strlen(SHM->replace[SHM->top])-1] = 0; + [strlen(SHM->replace[SHM->top]) - 1] = 0; (SHM->top)++; - if(SHM->top == MAX_FROM) + if (SHM->top == MAX_FROM) break; - } + } } } - - SHM->max_user=0; + SHM->max_user = 0; /* µ¥©Ò¦³¸ê®Æ§ó·s«á¦A³]©w uptime */ SHM->Fuptime = SHM->Ftouchtime; @@ -917,31 +1009,33 @@ static void reload_fcache() { } } -void resolve_fcache() +void +resolve_fcache() { - while( SHM->Fuptime < SHM->Ftouchtime ) + while (SHM->Fuptime < SHM->Ftouchtime) reload_fcache(); } -void hbflreload(int bid) +void +hbflreload(int bid) { - int hbfl[MAX_FRIEND + 1], i, num, uid; - char buf[128]; - FILE *fp; + int hbfl[MAX_FRIEND + 1], i, num, uid; + char buf[128]; + FILE *fp; memset(hbfl, 0, sizeof(hbfl)); - setbfile(buf, bcache[bid-1].brdname, fn_visable); - if( (fp = fopen(buf, "r")) != NULL ){ - for( num = 1 ; num <= MAX_FRIEND ; ++num ){ - if( fgets(buf, sizeof(buf), fp) == NULL ) + setbfile(buf, bcache[bid - 1].brdname, fn_visable); + if ((fp = fopen(buf, "r")) != NULL) { + for (num = 1; num <= MAX_FRIEND; ++num) { + if (fgets(buf, sizeof(buf), fp) == NULL) break; - for( i = 0 ; buf[i] != 0 ; ++i ) - if( buf[i] == ' ' ){ + for (i = 0; buf[i] != 0; ++i) + if (buf[i] == ' ') { buf[i] = 0; break; } - if( strcasecmp("guest", buf) == 0 || - (uid = searchuser(buf)) == 0 ) { + if (strcasecmp("guest", buf) == 0 || + (uid = searchuser(buf)) == 0) { --num; continue; } @@ -953,47 +1047,50 @@ void hbflreload(int bid) memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); } -int hbflcheck(int bid, int uid) +int +hbflcheck(int bid, int uid) { - int i; + int i; - if( SHM->hbfl[bid][0] < login_start_time - HBFLexpire ) + if (SHM->hbfl[bid][0] < login_start_time - HBFLexpire) hbflreload(bid); - for( i = 1 ; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND ; ++i ){ - if( SHM->hbfl[bid][i] == uid ) + for (i = 1; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND; ++i) { + if (SHM->hbfl[bid][i] == uid) return 0; } return 1; } #ifdef MDCACHE -char *cachepath(const char *fpath) +char * +cachepath(const char *fpath) { - static char cpath[128]; - char *ptr; + static char cpath[128]; + char *ptr; snprintf(cpath, sizeof(cpath), "cache/%s", fpath); - for( ptr = &cpath[6] ; *ptr != 0 ; ++ptr ) - if( *ptr == '/' ) + for (ptr = &cpath[6]; *ptr != 0; ++ptr) + if (*ptr == '/') *ptr = '.'; return cpath; } -int updatemdcache(const char *CPATH, const char *fpath) +int +updatemdcache(const char *CPATH, const char *fpath) { - /* save file to mdcache with *cpath and *fpath, - return: -1 if error - else the fd - */ - int len, sourcefd, targetfd; - char buf[1024], *cpath; + /* + * save file to mdcache with *cpath and *fpath, return: -1 if error + * else the fd + */ + int len, sourcefd, targetfd; + char buf[1024], *cpath; cpath = (CPATH == NULL) ? cachepath(fpath) : (char *)CPATH; - if( (sourcefd = open(fpath, O_RDONLY)) < 0 ) + if ((sourcefd = open(fpath, O_RDONLY)) < 0) return -1; - if( (targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0 ) + if ((targetfd = open(cpath, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) /* md is full? */ return -1; - while( (len = read(sourcefd, buf, sizeof(buf))) > 0 ) - if( write(targetfd, buf, len) < len ){ + while ((len = read(sourcefd, buf, sizeof(buf))) > 0) + if (write(targetfd, buf, len) < len) { /* md is full? */ close(targetfd); unlink(cpath); @@ -1005,17 +1102,18 @@ int updatemdcache(const char *CPATH, const char *fpath) return targetfd; } -int mdcacheopen(char *fpath) +int +mdcacheopen(char *fpath) { - int fd; - char *cpath; - if( strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4) ) + int fd; + char *cpath; + if (strncmp(fpath, "boards/", 7) && strncmp(fpath, "etc/", 4)) return open(fpath, O_RDONLY); #ifdef MDCACHEHITRATE ++GLOBE[0]; #endif - if( (fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0 ) + if ((fd = open((cpath = cachepath(fpath)), O_RDONLY)) < 0) return updatemdcache(cpath, fpath); #ifdef MDCACHEHITRATE else diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 995f4c55..cd2c0d48 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -1,48 +1,53 @@ -/* $Id: cal.c,v 1.15 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: cal.c,v 1.16 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" /* ¨¾°ô Multi play */ -static int count_multiplay(int unmode) { - register int i, j; +static int +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++) { uentp = &(SHM->uinfo[i]); - if(uentp->uid == usernum) - if(uentp->lockmode == unmode) + if (uentp->uid == usernum) + if (uentp->lockmode == unmode) j++; } return j; } -int lockutmpmode(int unmode, int state) { - int errorno = 0; - - if(currutmp->lockmode) +int +lockutmpmode(int unmode, int state) +{ + int errorno = 0; + + if (currutmp->lockmode) errorno = 1; - else if(count_multiplay(unmode)) + else if (count_multiplay(unmode)) errorno = 2; - - if(errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) { + + if (errorno && !(state == LOCK_THIS && errorno == LOCK_MULTI)) { clear(); - move(10,20); - if(errorno == 1) + move(10, 20); + if (errorno == 1) prints("½Ð¥ýÂ÷¶} %s ¤~¯à¦A %s ", ModeTypeTable[currutmp->lockmode], ModeTypeTable[unmode]); - else + else prints("©êºp! ±z¤w¦³¨ä¥L½u¬Û¦PªºID¥¿¦b%s", ModeTypeTable[unmode]); pressanykey(); return errorno; } - setutmpmode(unmode); currutmp->lockmode = unmode; return 0; } -int unlockutmpmode() { +int +unlockutmpmode() +{ currutmp->lockmode = 0; return 0; } @@ -51,44 +56,50 @@ int unlockutmpmode() { #define VICE_NEW "vice.new" /* Heat:µo²¼ */ -int vice(int money, char* item) { - char buf[128]; - unsigned int viceserial=(currutmp->lastact%1000000)*100+rand()%100; - FILE *fp; +int +vice(int money, char *item) +{ + char buf[128]; + unsigned int viceserial = (currutmp->lastact % 1000000) * 100 + rand() % 100; + FILE *fp; demoney(-money); - sprintf(buf, BBSHOME"/home/%c/%s/%s", + sprintf(buf, BBSHOME "/home/%c/%s/%s", cuser.userid[0], cuser.userid, VICE_NEW); fp = fopen(buf, "a"); - if(!fp ) - {return 0;} - + if (!fp) { + return 0; + } fprintf(fp, "%08d\n", viceserial); fclose(fp); - sprintf(buf, "%s ªá¤F%d$ ½s¸¹[%08d]",item, money, viceserial); - mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt¸gÀÙ³¡"); + sprintf(buf, "%s ªá¤F%d$ ½s¸¹[%08d]", item, money, viceserial); + mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt¸gÀÙ³¡"); return 0; } -#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 #define lockbreak(unmode, state) if(lockutmpmode(unmode, state)) break #define SONGBOOK "etc/SONGBOOK" #define OSONGPATH "etc/SONGO" -static int osong(char *defaultid) { - char destid[IDLEN + 1],buf[200],genbuf[200],filename[256],say[51]; - char receiver[45],ano[2]; - FILE *fp,*fp1;// *fp2; - fileheader_t mail; - int nsongs; - +static int +osong(char *defaultid) +{ + char destid[IDLEN + 1], buf[200], genbuf[200], filename[256], + say[51]; + char receiver[45], ano[2]; + FILE *fp, *fp1; + //*fp2; + fileheader_t mail; + int nsongs; + strcpy(buf, Cdatedate(&now)); - + lockreturn0(OSONG, LOCK_MULTI); - + /* Jaky ¤@¤H¤@¤ÑÂI¤@º */ - if(!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { - move(22,0); + if (!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { + move(22, 0); outs("§A¤µ¤Ñ¤w¸gÂI¹LÅo¡A©ú¤Ñ¦AÂI§a...."); refresh(); pressanykey(); @@ -96,8 +107,7 @@ static int osong(char *defaultid) { unlockutmpmode(); return 0; } - - if(cuser.money < 200) { + if (cuser.money < 200) { move(22, 0); outs("ÂIºqn200»Èò!...."); refresh(); @@ -110,120 +120,117 @@ static int osong(char *defaultid) { sprintf(buf, "¿Ë·Rªº %s Åwªï¨Ó¨ì¼Ú®á¦Û°ÊÂIºq¨t²Î\n", cuser.userid); outs(buf); trans_buffer[0] = 0; - if(!defaultid){ - getdata(13, 0, "nÂIµ¹½Ö©O:[¥iª½±µ«ö Enter ¥ý¿ïºq]", - destid, sizeof(destid), DOECHO); - while (!destid[0]){ - a_menu("ÂIºqºq¥»", SONGBOOK,0 ); - clear(); - getdata(13, 0, "nÂIµ¹½Ö©O:[¥i«ö Enter «·s¿ïºq]", - destid, sizeof(destid), DOECHO); - } + if (!defaultid) { + getdata(13, 0, "nÂIµ¹½Ö©O:[¥iª½±µ«ö Enter ¥ý¿ïºq]", + destid, sizeof(destid), DOECHO); + while (!destid[0]) { + a_menu("ÂIºqºq¥»", SONGBOOK, 0); + clear(); + getdata(13, 0, "nÂIµ¹½Ö©O:[¥i«ö Enter «·s¿ïºq]", + destid, sizeof(destid), DOECHO); } - else - strcpy(destid,defaultid); + } else + strcpy(destid, defaultid); - /* Heat:ÂIºqªÌ°Î¦W¥\¯à */ - getdata(14,0, "n°Î¦W¶Ü?[y/n]:", ano, sizeof(ano), DOECHO); - - if(!destid[0]) { + /* Heat:ÂIºqªÌ°Î¦W¥\¯à */ + getdata(14, 0, "n°Î¦W¶Ü?[y/n]:", ano, sizeof(ano), DOECHO); + + if (!destid[0]) { unlockutmpmode(); return 0; } - getdata_str(14, 0, "·Qnn¹ï¥L(¦o)»¡..:", say, sizeof(say), DOECHO, "§Ú·R©p.."); - sprintf(save_title, "%s:%s", (ano[0]=='y')?"°Î¦WªÌ":cuser.userid, say); + sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "°Î¦WªÌ" : cuser.userid, say); getdata_str(16, 0, "±H¨ì½Öªº«H½c(¥i¥ÎE-mail)?", receiver, sizeof(receiver), LCECHO, destid); - - if (!trans_buffer[0]){ - outs("\n±µµÛn¿ïºqÅo..¶i¤Jºq¥»¦n¦nªº¿ï¤@ººq§a..^o^"); - pressanykey(); - a_menu("ÂIºqºq¥»", SONGBOOK,0 ); + + if (!trans_buffer[0]) { + outs("\n±µµÛn¿ïºqÅo..¶i¤Jºq¥»¦n¦nªº¿ï¤@ººq§a..^o^"); + pressanykey(); + a_menu("ÂIºqºq¥»", SONGBOOK, 0); } - if(!trans_buffer[0] || strstr(trans_buffer, "home") || - strstr(trans_buffer, "boards") || !(fp = fopen(trans_buffer, "r"))) { + if (!trans_buffer[0] || strstr(trans_buffer, "home") || + strstr(trans_buffer, "boards") || !(fp = fopen(trans_buffer, "r"))) { unlockutmpmode(); return 0; } - strcpy(filename, OSONGPATH); - + stampfile(filename, &mail); - + unlink(filename); - - if(!(fp1 = fopen(filename, "w"))) { + + if (!(fp1 = fopen(filename, "w"))) { fclose(fp); unlockutmpmode(); return 0; } - strcpy(mail.owner, "ÂIºq¾÷"); - sprintf(mail.title, "¡º %s ÂIµ¹ %s ", (ano[0]=='y')?"°Î¦WªÌ":cuser.userid, destid); - - while(fgets(buf, 200, fp)) { - char *po; - if(!strncmp(buf, "¼ÐÃD: ", 6)) { + sprintf(mail.title, "¡º %s ÂIµ¹ %s ", (ano[0] == 'y') ? "°Î¦WªÌ" : cuser.userid, destid); + + while (fgets(buf, 200, fp)) { + char *po; + if (!strncmp(buf, "¼ÐÃD: ", 6)) { clear(); - move(10,10);prints("%s", buf); + move(10, 10); + prints("%s", buf); pressanykey(); fclose(fp); unlockutmpmode(); return 0; } - while((po = strstr(buf, "<~Src~>"))) { + while ((po = strstr(buf, "<~Src~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,(ano[0]=='y')?"°Î¦WªÌ":cuser.userid,po+7); - strcpy(buf,genbuf); - } - while((po = strstr(buf, "<~Des~>"))) { + sprintf(genbuf, "%s%s%s", buf, (ano[0] == 'y') ? "°Î¦WªÌ" : cuser.userid, po + 7); + strcpy(buf, genbuf); + } + while ((po = strstr(buf, "<~Des~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,destid,po+7); - strcpy(buf,genbuf); - } - while((po = strstr(buf, "<~Say~>"))) { + sprintf(genbuf, "%s%s%s", buf, destid, po + 7); + strcpy(buf, genbuf); + } + while ((po = strstr(buf, "<~Say~>"))) { po[0] = 0; - sprintf(genbuf,"%s%s%s",buf,say,po+7); - strcpy(buf,genbuf); - } - fputs(buf,fp1); + sprintf(genbuf, "%s%s%s", buf, say, po + 7); + strcpy(buf, genbuf); + } + fputs(buf, fp1); } fclose(fp1); fclose(fp); -// do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); - - if(do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { - cuser.lastsong = now; + //do_append(OSONGMAIL "/.DIR", &mail2, sizeof(mail2)); + + if (do_append(OSONGPATH "/.DIR", &mail, sizeof(mail)) != -1) { + cuser.lastsong = now; /* Jaky ¶W¹L 500 ººq´N¶}©l¬å */ - nsongs=get_num_records(OSONGPATH "/.DIR", sizeof(mail)); - if (nsongs > 500){ - delete_range(OSONGPATH "/.DIR", 1, nsongs-500); - } + nsongs = get_num_records(OSONGPATH "/.DIR", sizeof(mail)); + if (nsongs > 500) { + delete_range(OSONGPATH "/.DIR", 1, nsongs - 500); + } /* §â²Ä¤@º®³±¼ */ - vice(200, "ÂIºq"); + vice(200, "ÂIºq"); } - sprintf(save_title, "%s:%s", (ano[0]=='y')?"°Î¦WªÌ":cuser.userid, say); + sprintf(save_title, "%s:%s", (ano[0] == 'y') ? "°Î¦WªÌ" : cuser.userid, say); hold_mail(filename, destid); - if(receiver[0]) { + if (receiver[0]) { #ifndef USE_BSMTP bbs_sendmail(filename, save_title, receiver); #else - bsmtp(filename, save_title, receiver,0); + bsmtp(filename, save_title, receiver, 0); #endif } clear(); outs( - "\n\n ®¥³ß±zÂIºq§¹¦¨Åo..\n" - " ¤@¤p®É¤º°ÊºA¬ÝªO·|¦Û°Ê«·s§ó·s\n" - " ¤j®a´N¥i¥H¬Ý¨ì±zÂIªººqÅo\n\n" - " ÂIºq¦³¥ô¦ó°ÝÃD¥i¥H¨ìNoteªOªººëµØ°Ï§äµª®×\n" - " ¤]¥i¦bNoteªOºëµØ°Ï¬Ý¨ì¦Û¤vªºÂIºq°O¿ý\n" - " ¦³¥ô¦ó«O¶Qªº·N¨£¤]Åwªï¨ìNoteªO¯d¸Ü\n" - " Åý¿Ë¤ÁªºªO¥D¬°±zªA°È\n"); + "\n\n ®¥³ß±zÂIºq§¹¦¨Åo..\n" + " ¤@¤p®É¤º°ÊºA¬ÝªO·|¦Û°Ê«·s§ó·s\n" + " ¤j®a´N¥i¥H¬Ý¨ì±zÂIªººqÅo\n\n" + " ÂIºq¦³¥ô¦ó°ÝÃD¥i¥H¨ìNoteªOªººëµØ°Ï§äµª®×\n" + " ¤]¥i¦bNoteªOºëµØ°Ï¬Ý¨ì¦Û¤vªºÂIºq°O¿ý\n" + " ¦³¥ô¦ó«O¶Qªº·N¨£¤]Åwªï¨ìNoteªO¯d¸Ü\n" + " Åý¿Ë¤ÁªºªO¥D¬°±zªA°È\n"); pressanykey(); sortsong(); topsong(); @@ -232,12 +239,16 @@ static int osong(char *defaultid) { return 1; } -int ordersong() { +int +ordersong() +{ osong(NULL); return 0; } -static int inmailbox(int m) { +static int +inmailbox(int m) +{ passwd_query(usernum, &xuser); cuser.exmailbox = xuser.exmailbox + m; passwd_update(usernum, &cuser); @@ -247,14 +258,16 @@ static int inmailbox(int m) { #if !HAVE_FREECLOAK /* ªá¿ú¿ï³æ */ -int p_cloak() { - char buf[4]; - getdata(b_lines-1, 0, +int +p_cloak() +{ + char buf[4]; + getdata(b_lines - 1, 0, currutmp->invisible ? "½T©wn²{¨?[y/N]" : "½T©wnÁô¨?[y/N]", buf, sizeof(buf), LCECHO); - if(buf[0] != 'y') + if (buf[0] != 'y') return 0; - if(cuser.money >= 19) { + if (cuser.money >= 19) { vice(19, "cloak"); currutmp->invisible %= 2; outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); @@ -265,107 +278,117 @@ int p_cloak() { } #endif -int p_from() { - char ans[4]; +int +p_from() +{ + char ans[4]; - getdata(b_lines-2, 0, "½T©wn§ï¬G¶m?[y/N]", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + getdata(b_lines - 2, 0, "½T©wn§ï¬G¶m?[y/N]", ans, sizeof(ans), LCECHO); + if (ans[0] != 'y') return 0; reload_money(); - if(cuser.money < 49) + if (cuser.money < 49) return 0; - if(getdata_buf(b_lines-1, 0, "½Ð¿é¤J·s¬G¶m:", - currutmp->from, sizeof(currutmp->from), DOECHO)) { - vice(49,"home"); - currutmp->from_alias=0; + if (getdata_buf(b_lines - 1, 0, "½Ð¿é¤J·s¬G¶m:", + currutmp->from, sizeof(currutmp->from), DOECHO)) { + vice(49, "home"); + currutmp->from_alias = 0; } return 0; } -int p_exmail() { - char ans[4],buf[200]; - int n; +int +p_exmail() +{ + char ans[4], buf[200]; + int n; - if(cuser.exmailbox >= MAX_EXKEEPMAIL) { - sprintf(buf,"®e¶q³Ì¦h¼W¥[ %d «Ê¡A¤£¯à¦A¶R¤F¡C", MAX_EXKEEPMAIL); + if (cuser.exmailbox >= MAX_EXKEEPMAIL) { + sprintf(buf, "®e¶q³Ì¦h¼W¥[ %d «Ê¡A¤£¯à¦A¶R¤F¡C", MAX_EXKEEPMAIL); outs(buf); refresh(); return 0; } - sprintf(buf,"±z´¿¼WÁÊ %d «Ê®e¶q¡AÁÙn¦A¶R¦h¤Ö?", + sprintf(buf, "±z´¿¼WÁÊ %d «Ê®e¶q¡AÁÙn¦A¶R¦h¤Ö?", cuser.exmailbox); - - getdata_str(b_lines-2, 0, buf, ans, sizeof(ans), LCECHO, "10"); - + + getdata_str(b_lines - 2, 0, buf, ans, sizeof(ans), LCECHO, "10"); + n = atoi(ans); - if(!ans[0] || !n) + if (!ans[0] || !n) return 0; - if(n + cuser.exmailbox > MAX_EXKEEPMAIL) + if (n + cuser.exmailbox > MAX_EXKEEPMAIL) n = MAX_EXKEEPMAIL - cuser.exmailbox; reload_money(); - if(cuser.money < n * 1000) + if (cuser.money < n * 1000) return 0; vice(n * 1000, "mail"); inmailbox(n); return 0; } -void mail_redenvelop(char* from, char* to, int money, char mode){ - char genbuf[200]; - fileheader_t fhdr; - FILE* fp; +void +mail_redenvelop(char *from, char *to, int money, char mode) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; sprintf(genbuf, "home/%c/%s", to[0], to); stampfile(genbuf, &fhdr); if (!(fp = fopen(genbuf, "w"))) - return; + return; fprintf(fp, "§@ªÌ: %s\n" - "¼ÐÃD: ©Û°]¶iÄ_\n" - "®É¶¡: %s\n" - "\033[1;33m¿Ë·Rªº %s ¡G\n\n\033[m" - "\033[1;31m §Ú¥]µ¹§A¤@Ó %d ¤¸ªº¤j¬õ¥]³á ^_^\n\n" - " §»´±¡·N«¡A½Ð¯º¯Ç...... ^_^\033[m\n" - , from, ctime(&now), to, money); + "¼ÐÃD: ©Û°]¶iÄ_\n" + "®É¶¡: %s\n" + "\033[1;33m¿Ë·Rªº %s ¡G\n\n\033[m" + "\033[1;31m §Ú¥]µ¹§A¤@Ó %d ¤¸ªº¤j¬õ¥]³á ^_^\n\n" + " §»´±¡·N«¡A½Ð¯º¯Ç...... ^_^\033[m\n" + ,from, ctime(&now), to, money); fclose(fp); sprintf(fhdr.title, "©Û°]¶iÄ_"); strcpy(fhdr.owner, from); if (mode == 'y') - vedit(genbuf, NA, NULL); - sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); + vedit(genbuf, NA, NULL); + sprintf(genbuf, "home/%c/%s/.DIR", to[0], to); append_record(genbuf, &fhdr, sizeof(fhdr)); } /* pºâÃØ»Pµ| */ -int give_tax(int money) +int +give_tax(int money) { - int i, tax = 0; - static int tax_bound[] = { 1000000, 100000, 10000, 1000, 0}; - static double tax_rate[] = { 0.4, 0.3, 0.2, 0.1, 0.08 }; - for( i = 0; i <= 4 ; i++ ) - if ( money > tax_bound[i] ) { - tax += (money - tax_bound[i]) * tax_rate[i]; - money -= (money - tax_bound[i]); - } - return (tax <= 0) ? 1 : tax; + int i, tax = 0; + static int tax_bound[] = {1000000, 100000, 10000, 1000, 0}; + static double tax_rate[] = {0.4, 0.3, 0.2, 0.1, 0.08}; + for (i = 0; i <= 4; i++) + if (money > tax_bound[i]) { + tax += (money - tax_bound[i]) * tax_rate[i]; + money -= (money - tax_bound[i]); + } + return (tax <= 0) ? 1 : tax; } -int p_give() { - int money, tax; - char id[IDLEN + 1], genbuf[90]; - - move(1,0); +int +p_give() +{ + int money, tax; + char id[IDLEN + 1], genbuf[90]; + + move(1, 0); usercomplete("³o¦ì©¯¹B¨àªºid:", id); - if(!id[0] || !strcmp(cuser.userid,id) || - !getdata(2, 0, "nµ¹¦h¤Ö¿ú:", genbuf, 7, LCECHO)) + if (!id[0] || !strcmp(cuser.userid, id) || + !getdata(2, 0, "nµ¹¦h¤Ö¿ú:", genbuf, 7, LCECHO)) return 0; money = atoi(genbuf); reload_money(); - if(money > 0 && cuser.money >= money ) { + if (money > 0 && cuser.money >= money) { tax = give_tax(money); - if ( money - tax <= 0 ) return 0; /* ú§¹µ|´N¨S¿úµ¹¤F */ - deumoney(searchuser(id), money - tax); + if (money - tax <= 0) + return 0; /* ú§¹µ|´N¨S¿úµ¹¤F */ + deumoney(searchuser(id), money - tax); demoney(-money); - sprintf(genbuf,"%s\tµ¹%s\t%d\t%s", cuser.userid, id, money - tax, + sprintf(genbuf, "%s\tµ¹%s\t%d\t%s", cuser.userid, id, money - tax, ctime(&now)); log_file(FN_MONEY, genbuf); genbuf[0] = 'n'; @@ -375,14 +398,15 @@ int p_give() { return 0; } -int p_sysinfo(void) +int +p_sysinfo(void) { - char buf[128], *cpuloadstr; - int load; + char buf[128], *cpuloadstr; + int load; load = cpuload(buf); cpuloadstr = (load < 5 ? "¨}¦n" : (load < 20 ? "©|¥i" : "¹L«")); - + clear(); showtitle("¨t²Î¸ê°T", BBSNAME); move(2, 0); @@ -398,31 +422,35 @@ int p_sysinfo(void) } /* ¤ppºâ¾÷ */ -static void ccount(float *a, float b, int cmode) { - switch(cmode) { - case 0: - case 1: - case 2: - *a += b; - break; +static void +ccount(float *a, float b, int cmode) +{ + switch (cmode) { + case 0: + case 1: + case 2: + *a += b; + break; case 3: - *a -= b; - break; + *a -= b; + break; case 4: - *a *= b; - break; + *a *= b; + break; case 5: - *a /= b; - break; + *a /= b; + break; } } -int cal() { - float a = 0; - char flo = 0, ch = 0; - char mode[6] = {' ','=','+','-','*','/'} , cmode = 0; - char buf[100] = "[ 0] [ ] ", b[20] = "0"; - +int +cal() +{ + float a = 0; + char flo = 0, ch = 0; + char mode[6] = {' ', '=', '+', '-', '*', '/'}, cmode = 0; + char buf[100] = "[ 0] [ ] ", b[20] = "0"; + move(b_lines - 1, 0); clrtoeol(); outs(buf); @@ -431,28 +459,28 @@ int cal() { outs("\033[44m ¤ppºâ¾÷ \033[31;47m (0123456789+-*/=) " "\033[30m¿é¤J \033[31m " "(Q)\033[30m Â÷¶} \033[m"); - while(1) { + while (1) { ch = igetch(); - switch(ch) { + switch (ch) { case '\r': - ch = '='; + ch = '='; case '=': case '+': case '-': case '*': case '/': - ccount(&a, atof(b), cmode); - flo = 0; - b[0] = '0'; - b[1] = 0; - move(b_lines - 1, 0); - sprintf(buf, "[%13.2f] [%c] ", a, ch); - outs(buf); - break; + ccount(&a, atof(b), cmode); + flo = 0; + b[0] = '0'; + b[1] = 0; + move(b_lines - 1, 0); + sprintf(buf, "[%13.2f] [%c] ", a, ch); + outs(buf); + break; case '.': - if(!flo) + if (!flo) flo = 1; - else + else break; case '1': case '2': @@ -464,12 +492,12 @@ int cal() { case '8': case '9': case '0': - if(strlen(b) > 13) + if (strlen(b) > 13) break; - if(flo || b[0] != '0') - sprintf(b,"%s%c",b,ch); + if (flo || b[0] != '0') + sprintf(b, "%s%c", b, ch); else - b[0]=ch; + b[0] = ch; move(b_lines - 1, 0); sprintf(buf, "[%13s] [%c]", b, mode[(int)cmode]); outs(buf); @@ -477,8 +505,8 @@ int cal() { case 'q': return 0; } - - switch(ch) { + + switch (ch) { case '=': a = 0; cmode = 0; diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index f807c8a9..a3d7943c 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -1,145 +1,181 @@ -/* $Id: calendar.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: calendar.c,v 1.4 2002/07/05 17:10:26 in2 Exp $ */ #include "bbs.h" typedef struct event_t { - int year, month, day, days; - int color; - char *content; + int year, month, day, days; + int color; + char *content; struct event_t *next; -} event_t; +} event_t; + +static int +MonthDay(int m, int leap) +{ + static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -static int MonthDay(int m, int leap) { - static int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - return leap && m == 2 ? 29 : day[m - 1]; } -static int IsLeap(int y) { - if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) +static int +IsLeap(int y) +{ + if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) return 1; else return 0; } -static int Days(int y, int m, int d) { - int i, w; - +static int +Days(int y, int m, int d) +{ + int i, w; + w = 1 + 365 * (y - 1) + ((y - 1) / 4) - ((y - 1) / 100) + ((y - 1) / 400) + d - 1; - for(i = 1; i < m; i++) + for (i = 1; i < m; i++) w += MonthDay(i, IsLeap(y)); return w; } -static int ParseDate(char *date, event_t *t) { - char *y, *m, *d; - +static int +ParseDate(char *date, event_t * t) +{ + char *y, *m, *d; + y = strtok(date, "/"); m = strtok(NULL, "/"); d = strtok(NULL, ""); - if(!y || !m || !d) + if (!y || !m || !d) return 1; - + t->year = atoi(y); t->month = atoi(m); t->day = atoi(d); - if(t->year < 1 || t->month < 1 || t->month > 12 || - t->day < 1 || t->day > 31) + if (t->year < 1 || t->month < 1 || t->month > 12 || + t->day < 1 || t->day > 31) return 1; t->days = Days(t->year, t->month, t->day); return 0; } -static int ParseColor(char *color) { +static int +ParseColor(char *color) +{ struct { - char *str; - int val; - } c[] = { - {"black", 0}, - {"red", 1}, - {"green", 2}, - {"yellow", 3}, - {"blue", 4}, - {"magenta", 5}, - {"cyan", 6}, - {"white", 7} + char *str; + int val; + } c[] = { + { + "black", 0 + }, + { + "red", 1 + }, + { + "green", 2 + }, + { + "yellow", 3 + }, + { + "blue", 4 + }, + { + "magenta", 5 + }, + { + "cyan", 6 + }, + { + "white", 7 + } }; - int i; - - for(i = 0; i < sizeof(c) / sizeof(c[0]); i++) - if(strcasecmp(color, c[i].str) == 0) + int i; + + for (i = 0; i < sizeof(c) / sizeof(c[0]); i++) + if (strcasecmp(color, c[i].str) == 0) return c[i].val; return 7; } -static void InsertEvent(event_t *head, event_t *t) { - event_t *p; - - for(p = head; p->next && p->next->days < t->days; p = p->next); +static void +InsertEvent(event_t * head, event_t * t) +{ + event_t *p; + + for (p = head; p->next && p->next->days < t->days; p = p->next); t->next = p->next; p->next = t; } -static void FreeEvent(event_t *e) { - event_t *n; - - while(e) { +static void +FreeEvent(event_t * e) +{ + event_t *n; + + while (e) { n = e->next; free(e); e = n; } } -static event_t *ReadEvent(int today) { - FILE *fp; - char buf[256]; - static event_t head; - +static event_t * +ReadEvent(int today) +{ + FILE *fp; + char buf[256]; + static event_t head; + head.next = NULL; setcalfile(buf, cuser.userid); fp = fopen(buf, "r"); - if(fp) { - while(fgets(buf, sizeof(buf), fp)) { - char *date, *color, *content; - event_t *t; - - if(buf[0] == '#') + if (fp) { + while (fgets(buf, sizeof(buf), fp)) { + char *date, *color, *content; + event_t *t; + + if (buf[0] == '#') continue; - + date = strtok(buf, " \t\n"); color = strtok(NULL, " \t\n"); content = strtok(NULL, "\n"); - if(!date || !color || !content) + if (!date || !color || !content) continue; - + t = malloc(sizeof(event_t)); - if(ParseDate(date, t) || t->days < today) { + if (ParseDate(date, t) || t->days < today) { free(t); continue; } t->color = ParseColor(color) + 30; - for(; *content == ' ' || *content == '\t'; content++); + for (; *content == ' ' || *content == '\t'; content++); t->content = strdup(content); InsertEvent(&head, t); } fclose(fp); - } + } return head.next; } -static char **AllocCalBuffer(int line, int len) { - int i; - char **p; - +static char ** +AllocCalBuffer(int line, int len) +{ + int i; + char **p; + p = malloc(sizeof(char *) * line); p[0] = malloc(sizeof(char) * line * len); - for(i = 1; i < line; i++) + for (i = 1; i < line; i++) p[i] = p[i - 1] + len; return p; } -static void FreeCalBuffer(char **buf) { +static void +FreeCalBuffer(char **buf) +{ free(buf[0]); free(buf); } @@ -149,115 +185,119 @@ static void FreeCalBuffer(char **buf) { #define HEADER_SUNDAY_COLOR "\33[31m" #define HEADER_DAY_COLOR "\33[33m" -static int GenerateCalendar(char **buf, int y, int m, int today, event_t *e) { - static char *week_str[7] = {"¤é", "¤@", "¤G", "¤T", "¥|", "¤", "¤»"}; - static char *month_color[12] = { +static int +GenerateCalendar(char **buf, int y, int m, int today, event_t * e) +{ + static char *week_str[7] = {"¤é", "¤@", "¤G", "¤T", "¥|", "¤", "¤»"}; + static char *month_color[12] = { "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m", "\33[1;32m", "\33[1;33m", "\33[1;35m", "\33[1;36m" }; - static char *month_str[12] = { + static char *month_str[12] = { "¤@¤ë ", "¤G¤ë ", "¤T¤ë ", "¥|¤ë ", "¤¤ë ", "¤»¤ë ", "¤C¤ë ", "¤K¤ë ", "¤E¤ë ", "¤Q¤ë ", "¤Q¤@¤ë", "¤Q¤G¤ë" }; - - char *p, attr1[16], *attr2; - int i, d, w, line = 0, first_day = Days(y, m, 1); - + char *p, attr1[16], *attr2; + int i, d, w, line = 0, first_day = Days(y, m, 1); + + /* week day banner */ p = buf[line]; p += sprintf(p, " %s%s%s%s", HEADER_COLOR, HEADER_SUNDAY_COLOR, week_str[0], HEADER_DAY_COLOR); - for(i = 1; i < 7; i++) + for (i = 1; i < 7; i++) p += sprintf(p, " %s", week_str[i]); p += sprintf(p, "\33[m"); - + /* indent for first line */ p = buf[++line]; p += sprintf(p, " %s", CALENDAR_COLOR); - for(i = 0, w = first_day % 7; i < w; i++) + for (i = 0, w = first_day % 7; i < w; i++) p += sprintf(p, " "); - + /* initial event */ - for(; e && e->days < first_day; e = e->next); - + for (; e && e->days < first_day; e = e->next); + d = MonthDay(m, IsLeap(y)); - for(i = 1; i <= d; i++, w = (w + 1) % 7) { - attr1[0] = 0; - attr2 = ""; - while(e && e->days == first_day + i - 1) { + for (i = 1; i <= d; i++, w = (w + 1) % 7) { + attr1[0] = 0; + attr2 = ""; + while (e && e->days == first_day + i - 1) { sprintf(attr1, "\33[1;%dm", e->color); attr2 = CALENDAR_COLOR; e = e->next; } - if(today == first_day + i - 1) { + if (today == first_day + i - 1) { strcpy(attr1, "\33[1;37;42m"); attr2 = CALENDAR_COLOR; } p += sprintf(p, "%s%2d%s", attr1, i, attr2); - - if(w == 6) { + + if (w == 6) { p += sprintf(p, "\33[m"); p = buf[++line]; /* show month */ - if(line >= 2 && line <= 4) + if (line >= 2 && line <= 4) p += sprintf(p, "%s%2.2s\33[m %s", month_color[m - 1], month_str[m - 1] + (line - 2) * 2, CALENDAR_COLOR); - else if(i < d) + else if (i < d) p += sprintf(p, " %s", CALENDAR_COLOR); } else *p++ = ' '; } - + /* fill up the last line */ - if(w) { - for(w = 7 - w; w; w--) + if (w) { + for (w = 7 - w; w; w--) p += sprintf(p, w == 1 ? " " : " "); p += sprintf(p, "\33[m"); } return line + 1; } -int calendar() { - char **buf; - struct tm snow; - int i, y, m, today, lines = 0; - event_t *head = NULL, *e = NULL; - +int +calendar() +{ + char **buf; + struct tm snow; + int i, y, m, today, lines = 0; + event_t *head = NULL, *e = NULL; + /* initialize date */ memcpy(&snow, localtime(&now), sizeof(struct tm)); today = Days(snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday); y = snow.tm_year + 1900, m = snow.tm_mon + 1; - + /* read event */ head = e = ReadEvent(today); - + /* generate calendar */ buf = AllocCalBuffer(22, 256); - for(i = 0; i < 22; i++) + for (i = 0; i < 22; i++) sprintf(buf[i], "%24s", ""); - for(i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { lines += GenerateCalendar(buf + lines, y, m, today, e) + 1; - if(m == 12) + if (m == 12) y++, m = 1; else m++; } - + /* output */ clear(); outc('\n'); - for(i = 0; i < 22; i++) { + for (i = 0; i < 22; i++) { outs(buf[i]); - if(i == 0) { + if (i == 0) { prints("\t\33[1;37m²{¦b¬O %d.%02d.%02d %2d:%02d:%02d%cm\33[m", snow.tm_year + 1900, snow.tm_mon + 1, snow.tm_mday, - (snow.tm_hour == 0 || snow.tm_hour == 12) ? + (snow.tm_hour == 0 || snow.tm_hour == 12) ? 12 : snow.tm_hour % 12, snow.tm_min, snow.tm_sec, snow.tm_hour >= 12 ? 'p' : 'a'); - } else if(i >= 2 && e) { + } else if (i >= 2 && e) { prints("\t\33[1;37m(\33[%dm%3d\33[37m)\33[m %02d/%02d %s", e->color, e->days - today, e->month, e->day, e->content); diff --git a/mbbsd/card.c b/mbbsd/card.c index e5ac18e7..2b09d9c2 100644 --- a/mbbsd/card.c +++ b/mbbsd/card.c @@ -1,255 +1,281 @@ -/* $Id: card.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: card.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static int card_remain(int cards[]) { - int i, temp = 0; - - for(i = 0; i < 52; i++) - temp += cards[i]; - if(temp == 52) - return 1; +static int +card_remain(int cards[]) +{ + int i, temp = 0; + + for (i = 0; i < 52; i++) + temp += cards[i]; + if (temp == 52) + return 1; return 0; } /* 0 Spare , 1 heart , ...3 dimon */ -static int card_flower(int card) { +static int +card_flower(int card) +{ return (card / 13); } /* 1...13 */ -static int card_number(int card) { +static int +card_number(int card) +{ return (card % 13 + 1); } -static int card_select(int *now) { - char *cc[2] = {"\033[44m \033[m", - "\033[1;33;41m ¡µ \033[m"}; - - while(1) { - move(20, 0); - clrtoeol(); - prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], - (*now == 1) ? cc[1] : cc[0], - (*now == 2) ? cc[1] : cc[0], - (*now == 3) ? cc[1] : cc[0], - (*now == 4) ? cc[1] : cc[0]); - switch(egetch()) { - case 'Q': - case 'q': - return 0; - case '+': - case ',': - return 1; - case '\r': - return -1; - case KEY_LEFT: - *now = (*now + 4) % 5; - break; - case KEY_RIGHT: - *now = (*now + 1) % 5; - break; - case '1': - *now = 0; - break; - case '2': - *now = 1; - break; - case '3': - *now = 2; - break; - case '4': - *now = 3; - break; - case '5': - *now = 4; - break; - } +static int +card_select(int *now) +{ + char *cc[2] = {"\033[44m \033[m", + "\033[1;33;41m ¡µ \033[m"}; + + while (1) { + move(20, 0); + clrtoeol(); + prints("%s%s%s%s%s", (*now == 0) ? cc[1] : cc[0], + (*now == 1) ? cc[1] : cc[0], + (*now == 2) ? cc[1] : cc[0], + (*now == 3) ? cc[1] : cc[0], + (*now == 4) ? cc[1] : cc[0]); + switch (egetch()) { + case 'Q': + case 'q': + return 0; + case '+': + case ',': + return 1; + case '\r': + return -1; + case KEY_LEFT: + *now = (*now + 4) % 5; + break; + case KEY_RIGHT: + *now = (*now + 1) % 5; + break; + case '1': + *now = 0; + break; + case '2': + *now = 1; + break; + case '3': + *now = 2; + break; + case '4': + *now = 3; + break; + case '5': + *now = 4; + break; + } } } -static void card_display(int cline, int number, int flower, int show) { - int color = 31; - char *cn[13] = {"¢Ï", "¢±", "¢²", "¢³", "¢´", "¢µ", - "¢¶", "¢·", "¢¸", "10", "¢Ø", "¢ß", "¢Ù"}; - if(flower == 0 || flower == 3) - color = 36; - if((show < 0) && (cline > 1 && cline < 8)) - prints("¢x\033[1;33;42m¡°¡°¡°¡°\033[m¢x"); +static void +card_display(int cline, int number, int flower, int show) +{ + int color = 31; + char *cn[13] = {"¢Ï", "¢±", "¢²", "¢³", "¢´", "¢µ", + "¢¶", "¢·", "¢¸", "10", "¢Ø", "¢ß", "¢Ù"}; + if (flower == 0 || flower == 3) + color = 36; + if ((show < 0) && (cline > 1 && cline < 8)) + prints("¢x\033[1;33;42m¡°¡°¡°¡°\033[m¢x"); else - switch(cline) { - case 1: - prints("¢~¢w¢w¢w¢w¢¡"); - break; - case 2: - prints("¢x\033[1;%dm%s\033[m ¢x", color, cn[number - 1]); - break; - case 3: - if(flower == 1) - prints("¢x\033[1;%dm¢¨¢©¢¨¢©\033[m¢x", color); - else - prints("¢x\033[1;%dm ¢¨¢© \033[m¢x", color); - break; - case 4: - if(flower == 1) - prints("¢x\033[1;%dm¢i¢i¢i¢i\033[m¢x", color); - else if (flower == 3) - prints("¢x\033[1;%dm¢©¢i¢i¢¨\033[m¢x", color); - else - prints("¢x\033[1;%dm¢¨¢i¢i¢©\033[m¢x", color); - break; - case 5: - if(flower == 0) - prints("¢x\033[1;%dm¢i¢i¢i¢i\033[m¢x", color); - else if (flower == 3) - prints("¢x\033[1;%dm¢i¢ª¢«¢i\033[m¢x", color); - else - prints("¢x\033[1;%dm¢ª¢i¢i¢«\033[m¢x", color); - break; - case 6: - if(flower == 0) - prints("¢x\033[1;%dm ¢¨¢© \033[m¢x", color); - else if (flower == 3) - prints("¢x\033[1;%dm¢ª¢¨¢©¢«\033[m¢x", color); - else - prints("¢x\033[1;%dm ¢ª¢« \033[m¢x", color); - break; - case 7: - prints("¢x \033[1;%dm%s\033[m¢x", color, cn[number - 1]); - break; - case 8: - prints("¢¢¢w¢w¢w¢w¢£"); - break; - } + switch (cline) { + case 1: + prints("¢~¢w¢w¢w¢w¢¡"); + break; + case 2: + prints("¢x\033[1;%dm%s\033[m ¢x", color, cn[number - 1]); + break; + case 3: + if (flower == 1) + prints("¢x\033[1;%dm¢¨¢©¢¨¢©\033[m¢x", color); + else + prints("¢x\033[1;%dm ¢¨¢© \033[m¢x", color); + break; + case 4: + if (flower == 1) + prints("¢x\033[1;%dm¢i¢i¢i¢i\033[m¢x", color); + else if (flower == 3) + prints("¢x\033[1;%dm¢©¢i¢i¢¨\033[m¢x", color); + else + prints("¢x\033[1;%dm¢¨¢i¢i¢©\033[m¢x", color); + break; + case 5: + if (flower == 0) + prints("¢x\033[1;%dm¢i¢i¢i¢i\033[m¢x", color); + else if (flower == 3) + prints("¢x\033[1;%dm¢i¢ª¢«¢i\033[m¢x", color); + else + prints("¢x\033[1;%dm¢ª¢i¢i¢«\033[m¢x", color); + break; + case 6: + if (flower == 0) + prints("¢x\033[1;%dm ¢¨¢© \033[m¢x", color); + else if (flower == 3) + prints("¢x\033[1;%dm¢ª¢¨¢©¢«\033[m¢x", color); + else + prints("¢x\033[1;%dm ¢ª¢« \033[m¢x", color); + break; + case 7: + prints("¢x \033[1;%dm%s\033[m¢x", color, cn[number - 1]); + break; + case 8: + prints("¢¢¢w¢w¢w¢w¢£"); + break; + } } -static void card_show(int cpu[], int c[], int me[], int m[]) { - int i, j; - - for(j = 0; j < 8; j++) { - move(2 + j, 0); - clrtoeol(); - for(i = 0; i < 5 && cpu[i] >= 0; i++) - card_display(j + 1, card_number(cpu[i]), - card_flower(cpu[i]), c[i]); +static void +card_show(int cpu[], int c[], int me[], int m[]) +{ + int i, j; + + for (j = 0; j < 8; j++) { + move(2 + j, 0); + clrtoeol(); + for (i = 0; i < 5 && cpu[i] >= 0; i++) + card_display(j + 1, card_number(cpu[i]), + card_flower(cpu[i]), c[i]); } - for(j = 0; j < 8; j++) { - move(11 + j, 0); - clrtoeol(); - for(i = 0; i < 5 && me[i] >= 0; i++) - card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); + for (j = 0; j < 8; j++) { + move(11 + j, 0); + clrtoeol(); + for (i = 0; i < 5 && me[i] >= 0; i++) + card_display(j + 1, card_number(me[i]), card_flower(me[i]), m[i]); } } -static void card_new(int cards[]) { - memset(cards, 0, sizeof(int)*52); -} - -static int card_give(int cards[]) { - int i, error; - for(error=0, i=rand()%52; cards[i] == 1 && error<52; error++, i=rand()%52); - if(error==52) card_new(cards); // Ptt:³oÃ䦳dead lock°ÝÃD - cards[i] = 1; +static void +card_new(int cards[]) +{ + memset(cards, 0, sizeof(int) * 52); +} + +static int +card_give(int cards[]) +{ + int i, error; + for (error = 0, i = rand() % 52; cards[i] == 1 && error < 52; error++, i = rand() % 52); + if (error == 52) + card_new(cards); +//Ptt:³o à 䦳dead lock ° ÝÃD + cards[i] = 1; return i; } -static void card_start(char name[]) { +static void +card_start(char name[]) +{ clear(); stand_title(name); move(1, 0); prints(" \033[1;33;41m ¹q ¸£ \033[m"); move(10, 0); prints("\033[1;34;44m¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã" - "¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»\033[m"); + "¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»¡ã¡»\033[m"); move(19, 0); prints(" \033[1;37;42m ¦Û ¤v \033[m"); } -static int card_99_add(int i, int aom, int count) { +static int +card_99_add(int i, int aom, int count) +{ if (i == 4 || i == 5 || i == 11) - return count; - else if(i == 12) - return count + 20 * aom; - else if(i == 10) - return count + 10 * aom; - else if(i == 13) - return 99; + return count; + else if (i == 12) + return count + 20 * aom; + else if (i == 10) + return count + 10 * aom; + else if (i == 13) + return 99; else - return count + i; + return count + i; } -static int card_99_cpu(int cpu[], int *count) { - int stop = -1; - int twenty = -1; - int ten = -1; - int kill = -1; - int temp, num[10]; - int other = -1; - int think = 99-(*count); - int i, j; - - for(i = 0; i < 10; i++) - num[i] = -1; - for(i = 0; i < 5; i++) { - temp = card_number(cpu[i]); - if(temp == 4 || temp == 5 || temp == 11) - stop = i; - else if(temp == 12) - twenty = i; - else if (temp == 10) - ten = i; - else if (temp == 13) - kill = i; - else { - other = i; - num[temp] = i; - } +static int +card_99_cpu(int cpu[], int *count) +{ + int stop = -1; + int twenty = -1; + int ten = -1; + int kill = -1; + int temp, num[10]; + int other = -1; + int think = 99 - (*count); + int i, j; + + for (i = 0; i < 10; i++) + num[i] = -1; + for (i = 0; i < 5; i++) { + temp = card_number(cpu[i]); + if (temp == 4 || temp == 5 || temp == 11) + stop = i; + else if (temp == 12) + twenty = i; + else if (temp == 10) + ten = i; + else if (temp == 13) + kill = i; + else { + other = i; + num[temp] = i; + } } - for(j = 9; j > 0; j--) - if(num[j] >= 0 && j != 4 && j != 5 && think >= j) { - (*count) += j; - return num[j]; - } - if((think >= 20) && (twenty >= 0)) { - (*count) += 20; - return twenty; - } else if((think >= 10) && (ten >= 0)) { - (*count) += 10; - return ten; - } else if(stop >= 0) - return stop; + for (j = 9; j > 0; j--) + if (num[j] >= 0 && j != 4 && j != 5 && think >= j) { + (*count) += j; + return num[j]; + } + if ((think >= 20) && (twenty >= 0)) { + (*count) += 20; + return twenty; + } else if ((think >= 10) && (ten >= 0)) { + (*count) += 10; + return ten; + } else if (stop >= 0) + return stop; else if (kill >= 0) { - (*count) = 99; - return kill; - } else if(ten >= 0) { - (*count) -= 10; - return ten; - } else if(twenty >= 0) { - (*count) -= 20; - return twenty; + (*count) = 99; + return kill; + } else if (ten >= 0) { + (*count) -= 10; + return ten; + } else if (twenty >= 0) { + (*count) -= 20; + return twenty; } else { - (*count) += card_number(cpu[0]); - return 0; + (*count) += card_number(cpu[0]); + return 0; } } -int card_99() { - int i, j, turn; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; - int count = 0; - char *ff[4] = {"\033[1;36m¶Â®ç", "\033[1;31m¬õ¤ß", - "\033[1;31m¤è¶ô", "\033[1;36m¶Âªá"}; - char *cn[13] = {"¢Ï", "¢±", "¢²", "¢³", "¢´", "¢µ", - "¢¶", "¢·", "¢¸", "10", "¢Ø", "¢ß", "¢Ù"}; - for(i = 0; i < 5; i++) - cpu[i] = c[i] = me[i] = m[i] = -1; +int +card_99() +{ + int i, j, turn; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + int count = 0; + char *ff[4] = {"\033[1;36m¶Â®ç", "\033[1;31m¬õ¤ß", + "\033[1;31m¤è¶ô", "\033[1;36m¶Âªá"}; + char *cn[13] = {"¢Ï", "¢±", "¢²", "¢³", "¢´", "¢µ", + "¢¶", "¢·", "¢¸", "10", "¢Ø", "¢ß", "¢Ù"}; + for (i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; setutmpmode(CARD_99); card_start("¤Ñªø¦a¤["); card_new(cards); - for(i = 0; i < 5; i++) { - cpu[i] = card_give(cards); - me[i] = card_give(cards); - m[i] = 1; + for (i = 0; i < 5; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + m[i] = 1; } card_show(cpu, c, me, m); j = 0; @@ -258,232 +284,244 @@ int card_99() { clrtoeol(); prints("[0]¥Ø«e %d , ´Ý %d ÂI\n", count, 99 - count); prints("¥ª¥kÁä²¾°Ê´å¼Ð, [Enter]½T©w, [ + ]ªí¥[¤G¤Q(¥[¤Q), [Q/q]©ñ±ó¹CÀ¸"); - while(1) { - i = card_select(&j); - if(i == 0) /*©ñ±ó¹CÀ¸*/ - return 0; - count = card_99_add(card_number(me[j]), i, count); - move(21 + (turn / 2) % 2, 0); - clrtoeol(); - prints("[%d]±z¥X %s%s\033[m ¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", - turn, ff[card_flower(me[j])], - cn[card_number(me[j]) - 1], count, 99 - count); - me[j] = card_give(cards); - turn++; - if(count < 0) - count = 0; - card_show(cpu, c, me, m); - pressanykey(); - if(count > 99) { - move(22, 0); - clrtoeol(); - prints("[%d]µ²ªG..YOU LOSS..¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", - turn, count, 99 - count); - pressanykey(); - return 0; - } - i = card_99_cpu(cpu, &count); - move(21 + (turn / 2 + 1) % 2, 40); - prints("[%d]¹q¸£¥X %s%s\033[m ¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", - turn, ff[card_flower(cpu[i])], - cn[card_number(cpu[i]) - 1], count, 99 - count); - cpu[i] = card_give(cards); - turn++; - if(count < 0) - count = 0; - if(count > 99) { - move(22, 0); - clrtoeol(); - prints("[%d]µ²ªG..YOU WIN!..¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", - turn, count, 99 - count); - pressanykey(); - return 0; - } - if(!card_remain(cards)) { - card_new(cards); - for(i = 0; i < 5; i++) { - cards[me[i]] = 1; - cards[cpu[i]] = 1; - } - } + while (1) { + i = card_select(&j); + if (i == 0) /* ©ñ±ó¹CÀ¸ */ + return 0; + count = card_99_add(card_number(me[j]), i, count); + move(21 + (turn / 2) % 2, 0); + clrtoeol(); + prints("[%d]±z¥X %s%s\033[m ¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", + turn, ff[card_flower(me[j])], + cn[card_number(me[j]) - 1], count, 99 - count); + me[j] = card_give(cards); + turn++; + if (count < 0) + count = 0; + card_show(cpu, c, me, m); + pressanykey(); + if (count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]µ²ªG..YOU LOSS..¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", + turn, count, 99 - count); + pressanykey(); + return 0; + } + i = card_99_cpu(cpu, &count); + move(21 + (turn / 2 + 1) % 2, 40); + prints("[%d]¹q¸£¥X %s%s\033[m ¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", + turn, ff[card_flower(cpu[i])], + cn[card_number(cpu[i]) - 1], count, 99 - count); + cpu[i] = card_give(cards); + turn++; + if (count < 0) + count = 0; + if (count > 99) { + move(22, 0); + clrtoeol(); + prints("[%d]µ²ªG..YOU WIN!..¥Ø«e \033[1;31m%d/\033[34m%d\033[m ÂI", + turn, count, 99 - count); + pressanykey(); + return 0; + } + if (!card_remain(cards)) { + card_new(cards); + for (i = 0; i < 5; i++) { + cards[me[i]] = 1; + cards[cpu[i]] = 1; + } + } } } #define PMONEY (10) -#define TEN_HALF (5) /*¤QÂI¥bªºTicket*/ -#define JACK (10) /*¶Â³Ç§JªºTicket*/ -#define NINE99 (99) /*99 ªºTicket*/ +#define TEN_HALF (5) /* ¤QÂI¥bªºTicket */ +#define JACK (10) /* ¶Â³Ç§JªºTicket */ +#define NINE99 (99) /* 99 ªºTicket */ -static int game_log(int type, int money) { - FILE *fp; +static int +game_log(int type, int money) +{ + FILE *fp; - if(money > 0) + if (money > 0) demoney(money); - switch(type) { + switch (type) { case JACK: - fp = fopen(BBSHOME "/etc/card/jack.log", "a"); - if(!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; + fp = fopen(BBSHOME "/etc/card/jack.log", "a"); + if (!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; case TEN_HALF: - fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); - if(!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; + fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); + if (!fp) + return 0; + fprintf(fp, "%s win:%d\n", cuser.userid, money); + fclose(fp); + break; } return 0; } -static int card_double_ask() { - char buf[100], buf2[3]; +static int +card_double_ask() +{ + char buf[100], buf2[3]; sprintf(buf, "[ %s ]±z²{¦b¦@¦³ %d P¹ô, ²{¦bn¤À²Õ(¥[¦¬ %d ¤¸)¶Ü? [y/N]", - cuser.userid, cuser.money, JACK); + cuser.userid, cuser.money, JACK); reload_money(); - if(cuser.money < JACK) - return 0; + if (cuser.money < JACK) + return 0; getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); - if(buf2[0] == 'y' || buf2[0] == 'Y') - return 1; + if (buf2[0] == 'y' || buf2[0] == 'Y') + return 1; return 0; } -static int card_ask() { - char buf[100], buf2[3]; +static int +card_ask() +{ + char buf[100], buf2[3]; sprintf(buf, "[ %s ]±z²{¦b¦@¦³ %d P¹ô, ÁÙn¥[µP¶Ü? [y/N]", - cuser.userid, cuser.money); - getdata(20, 0 , buf, buf2, sizeof(buf2), LCECHO); - if(buf2[0] == 'y' || buf2[0] == 'Y') - return 1; + cuser.userid, cuser.money); + getdata(20, 0, buf, buf2, sizeof(buf2), LCECHO); + if (buf2[0] == 'y' || buf2[0] == 'Y') + return 1; return 0; } -static int card_alls_lower(int all[]) { - int i, count = 0; +static int +card_alls_lower(int all[]) +{ + int i, count = 0; for (i = 0; i < 5 && all[i] >= 0; i++) - if(card_number(all[i]) <= 10) - count += card_number(all[i]); - else - count += 10; + if (card_number(all[i]) <= 10) + count += card_number(all[i]); + else + count += 10; return count; } -static int card_alls_upper(int all[]) { - int i, count; +static int +card_alls_upper(int all[]) +{ + int i, count; count = card_alls_lower(all); for (i = 0; i < 5 && all[i] >= 0 && count <= 11; i++) - if (card_number(all[i]) == 1) - count += 10; + if (card_number(all[i]) == 1) + count += 10; return count; } -static int card_jack(int *db) { - int i, j; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; - - for(i = 0;i<5;i++) - cpu[i] = c[i] = me[i] = m[i] = -1; - - if((*db)<0) { - card_new(cards); - card_start("¶Â³Ç§J"); - for(i = 0; i < 2; i++) { - cpu[i] = card_give(cards); - me[i] = card_give(cards); - } +static int +card_jack(int *db) +{ + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; + + for (i = 0; i < 5; i++) + cpu[i] = c[i] = me[i] = m[i] = -1; + + if ((*db) < 0) { + card_new(cards); + card_start("¶Â³Ç§J"); + for (i = 0; i < 2; i++) { + cpu[i] = card_give(cards); + me[i] = card_give(cards); + } } else { - card_start("¶Â³Ç§JDOUBLE°l¥[§½"); - cpu[0] = card_give(cards); - cpu[1] = card_give(cards); - me[0] = *db; - me[1] = card_give(cards); + card_start("¶Â³Ç§JDOUBLE°l¥[§½"); + cpu[0] = card_give(cards); + cpu[1] = card_give(cards); + me[0] = *db; + me[1] = card_give(cards); } c[1] = m[0] = m[1] = 1; card_show(cpu, c, me, m); - if((card_number(me[0]) == 0 && card_number(me[1]) == 12) || - (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { - if(card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { - move(b_lines - 1, 0); - prints("«D±`¤£¿ùò! (¶W¯Å¶Â³Ç§J!! ¥[ %d ¤¸)", JACK * 10); - game_log(JACK, JACK * 10); - pressanykey(); - return 0; - } else { - move(b_lines - 1, 0); - prints("«Ü¤£¿ùò! (¶Â³Ç§J!! ¥[ %d ¤¸)", JACK * 5); - game_log(JACK, JACK * 5); - pressanykey(); - return 0; - } + if ((card_number(me[0]) == 0 && card_number(me[1]) == 12) || + (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { + if (card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { + move(b_lines - 1, 0); + prints("«D±`¤£¿ùò! (¶W¯Å¶Â³Ç§J!! ¥[ %d ¤¸)", JACK * 10); + game_log(JACK, JACK * 10); + pressanykey(); + return 0; + } else { + move(b_lines - 1, 0); + prints("«Ü¤£¿ùò! (¶Â³Ç§J!! ¥[ %d ¤¸)", JACK * 5); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; + } } - if((card_number(cpu[0]) == 0 && card_number(cpu[1]) == 12) || - (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { - c[0] = 1; - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("¼K¼K...¤£¦n·N«ä....¶Â³Ç§J!!"); - game_log(JACK, 0); - pressanykey(); - return 0; + if ((card_number(cpu[0]) == 0 && card_number(cpu[1]) == 12) || + (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { + c[0] = 1; + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("¼K¼K...¤£¦n·N«ä....¶Â³Ç§J!!"); + game_log(JACK, 0); + pressanykey(); + return 0; } - if((*db < 0)&& (card_number(me[0]) == card_number(me[1])) && - (card_double_ask())) { - *db = me[1]; - me[1] = card_give(cards); - card_show(cpu, c, me, m); + if ((*db < 0) && (card_number(me[0]) == card_number(me[1])) && + (card_double_ask())) { + *db = me[1]; + me[1] = card_give(cards); + card_show(cpu, c, me, m); } i = 2; - while(i < 5 && card_ask()) { - me[i] = card_give(cards); - m[i] = 1; - card_show(cpu, c, me, m); - if(card_alls_lower(me) > 21) { - move(b_lines - 1, 0); - prints("¶ã¶ã...Ãz±¼¤F!"); - game_log(JACK, 0); - pressanykey(); - return 0; - } - i++; - if((i == 3) && (card_number(me[0]) == 7) && - (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { - move(b_lines - 1, 0); - prints("«Ü¤£¿ùò! (©¯¹B¤C¸¹!! ¥[ %d ¤¸)", JACK * 7); - game_log(JACK, JACK * 7); - pressanykey(); - return 0; - } + while (i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if (card_alls_lower(me) > 21) { + move(b_lines - 1, 0); + prints("¶ã¶ã...Ãz±¼¤F!"); + game_log(JACK, 0); + pressanykey(); + return 0; + } + i++; + if ((i == 3) && (card_number(me[0]) == 7) && + (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { + move(b_lines - 1, 0); + prints("«Ü¤£¿ùò! (©¯¹B¤C¸¹!! ¥[ %d ¤¸)", JACK * 7); + game_log(JACK, JACK * 7); + pressanykey(); + return 0; + } } - if(i == 5) {/*¹L¤Ãö*/ - move(b_lines - 1, 0); - prints("¦n¼F®`ò! ¹L¤Ãö¹Æ! ¥[P¹ô %d ¤¸!", 5 * JACK); - game_log(JACK, JACK * 5); - pressanykey(); - return 0; + if (i == 5) { /* ¹L¤Ãö */ + move(b_lines - 1, 0); + prints("¦n¼F®`ò! ¹L¤Ãö¹Æ! ¥[P¹ô %d ¤¸!", 5 * JACK); + game_log(JACK, JACK * 5); + pressanykey(); + return 0; } j = 2; c[0] = 1; - while((card_alls_upper(cpu) < card_alls_upper(me))|| - ((card_alls_upper(cpu) == card_alls_upper(me) && j < i ) && j < 5)) { - cpu[j] = card_give(cards); - c[j] = 1; - if(card_alls_lower(cpu) > 21) { - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("¨þ¨þ...¹q¸£Ãz±¼¤F! §AŤF! ¥i±oP¹ô %d ¤¸", JACK * 2); - game_log(JACK, JACK * 2); - pressanykey(); - return 0; - } - j++; + while ((card_alls_upper(cpu) < card_alls_upper(me)) || + ((card_alls_upper(cpu) == card_alls_upper(me) && j < i) && j < 5)) { + cpu[j] = card_give(cards); + c[j] = 1; + if (card_alls_lower(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("¨þ¨þ...¹q¸£Ãz±¼¤F! §AŤF! ¥i±oP¹ô %d ¤¸", JACK * 2); + game_log(JACK, JACK * 2); + pressanykey(); + return 0; + } + j++; } card_show(cpu, c, me, m); move(b_lines - 1, 0); @@ -493,93 +531,99 @@ static int card_jack(int *db) { return 0; } -int g_card_jack() { - int db; - char buf[3]; +int +g_card_jack() +{ + int db; + char buf[3]; setutmpmode(JACK_CARD); - while(1) { - reload_money(); - if(cuser.money < JACK) { - outs("±zªº¿ú¤£°÷ò!¥h¦hµoªí¨Ç¦³·N¸qªº¤å³¹¦A¨Ó~~~"); - return 0; - } - getdata(b_lines - 1, 0, "½T©wnª±¶Â³Ç§J¶Ü ¤@¦¸¤Q¤¸ò?(Y/N)?[N]", - buf, 3, LCECHO); - if((*buf != 'y') && (*buf != 'Y')) - break; - else { - db = -1; + while (1) { + reload_money(); + if (cuser.money < JACK) { + outs("±zªº¿ú¤£°÷ò!¥h¦hµoªí¨Ç¦³·N¸qªº¤å³¹¦A¨Ó~~~"); + return 0; + } + getdata(b_lines - 1, 0, "½T©wnª±¶Â³Ç§J¶Ü ¤@¦¸¤Q¤¸ò?(Y/N)?[N]", + buf, 3, LCECHO); + if ((*buf != 'y') && (*buf != 'Y')) + break; + else { + db = -1; vice(PMONEY, "¶Â³Ç§J"); - card_jack(&db); - if(db >= 0) - card_jack(&db); - } + card_jack(&db); + if (db >= 0) + card_jack(&db); + } } return 0; } -static int card_all(int all[]) { - int i, count = 0; +static int +card_all(int all[]) +{ + int i, count = 0; for (i = 0; i < 5 && all[i] >= 0; i++) - if(card_number(all[i]) <= 10) - count += 2 * card_number(all[i]); - else - count += 1; + if (card_number(all[i]) <= 10) + count += 2 * card_number(all[i]); + else + count += 1; return count; } -static int ten_helf() { - int i, j; - int cpu[5], c[5], me[5], m[5]; - int cards[52]; +static int +ten_helf() +{ + int i, j; + int cpu[5], c[5], me[5], m[5]; + int cards[52]; card_start("¤QÂI¥b"); card_new(cards); for (i = 0; i < 5; i++) - cpu[i] = c[i] = me[i] = m[i] = -1; + cpu[i] = c[i] = me[i] = m[i] = -1; cpu[0] = card_give(cards); me[0] = card_give(cards); m[0] = 1; card_show(cpu, c, me, m); i = 1; - while(i < 5 && card_ask()) { - me[i] = card_give(cards); - m[i] = 1; - card_show(cpu, c, me, m); - if(card_all(me) > 21) { - move(b_lines - 1, 0); - prints("¶ã¶ã...Ãz±¼¤F!"); - game_log(TEN_HALF, 0); - pressanykey(); - return 0; - } - i++; + while (i < 5 && card_ask()) { + me[i] = card_give(cards); + m[i] = 1; + card_show(cpu, c, me, m); + if (card_all(me) > 21) { + move(b_lines - 1, 0); + prints("¶ã¶ã...Ãz±¼¤F!"); + game_log(TEN_HALF, 0); + pressanykey(); + return 0; + } + i++; } - if(i == 5) {/*¹L¤Ãö*/ - move(b_lines - 1, 0); - prints("¦n¼F®`ò! ¹L¤Ãö¹Æ! ¥[P¹ô %d ¤¸!", 5 * PMONEY); - game_log(TEN_HALF, PMONEY * 5); - pressanykey(); - return 0; + if (i == 5) { /* ¹L¤Ãö */ + move(b_lines - 1, 0); + prints("¦n¼F®`ò! ¹L¤Ãö¹Æ! ¥[P¹ô %d ¤¸!", 5 * PMONEY); + game_log(TEN_HALF, PMONEY * 5); + pressanykey(); + return 0; } j = 1; c[0] = 1; - while( j<5 && ((card_all(cpu) < card_all(me)) || - (card_all(cpu) == card_all(me) && j < i))) { - cpu[j] = card_give(cards); - c[j] = 1; - if(card_all(cpu) > 21) { - card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("¨þ¨þ...¹q¸£Ãz±¼¤F! §AŤF! ¥i±oP¹ô %d ¤¸", PMONEY * 2); - game_log(TEN_HALF, PMONEY * 2); - pressanykey(); - return 0; - } - j++; + while (j < 5 && ((card_all(cpu) < card_all(me)) || + (card_all(cpu) == card_all(me) && j < i))) { + cpu[j] = card_give(cards); + c[j] = 1; + if (card_all(cpu) > 21) { + card_show(cpu, c, me, m); + move(b_lines - 1, 0); + prints("¨þ¨þ...¹q¸£Ãz±¼¤F! §AŤF! ¥i±oP¹ô %d ¤¸", PMONEY * 2); + game_log(TEN_HALF, PMONEY * 2); + pressanykey(); + return 0; + } + j++; } card_show(cpu, c, me, m); move(b_lines - 1, 0); @@ -589,25 +633,27 @@ static int ten_helf() { return 0; } -int g_ten_helf() { - char buf[3]; +int +g_ten_helf() +{ + char buf[3]; setutmpmode(TENHALF); - while(1) { - reload_money(); - if(cuser.money < TEN_HALF) { - outs("±zªº¿ú¤£°÷ò!¥h¦hµoªí¨Ç¦³·N¸qªº¤å³¹¦A¨Ó~~~"); - return 0; - } - getdata(b_lines - 1, 0, - "\033[1;37m½T©wnª±¤QÂI¥b¶Ü ¤@¦¸¤Q¤¸ò?(Y/N)?[N]\033[m", - buf, 3, LCECHO); - if(buf[0] != 'y' && buf[0] != 'Y') - return 0; - else { - vice(PMONEY, "¤QÂI¥b"); - ten_helf(); - } + while (1) { + reload_money(); + if (cuser.money < TEN_HALF) { + outs("±zªº¿ú¤£°÷ò!¥h¦hµoªí¨Ç¦³·N¸qªº¤å³¹¦A¨Ó~~~"); + return 0; + } + getdata(b_lines - 1, 0, + "\033[1;37m½T©wnª±¤QÂI¥b¶Ü ¤@¦¸¤Q¤¸ò?(Y/N)?[N]\033[m", + buf, 3, LCECHO); + if (buf[0] != 'y' && buf[0] != 'Y') + return 0; + else { + vice(PMONEY, "¤QÂI¥b"); + ten_helf(); + } } return 0; } diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 17e004b0..5dd2d768 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -1,13 +1,15 @@ -/* $Id: chat.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chat.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static int chatline, stop_line; -static FILE *flog; -static void printchatline(char *str) { +static int chatline, stop_line; +static FILE *flog; +static void +printchatline(char *str) +{ move(chatline, 0); - if(*str == '>' && !PERM_HIDE(currutmp)) + if (*str == '>' && !PERM_HIDE(currutmp)) return; - else if(chatline < stop_line - 1) + else if (chatline < stop_line - 1) chatline++; else { region_scroll_up(2, stop_line - 2); @@ -16,13 +18,15 @@ static void printchatline(char *str) { outs(str); outc('\n'); outs("¡÷"); - - if(flog) + + if (flog) fprintf(flog, "%s\n", str); } -static void chat_clear() { - for(chatline = 2; chatline < stop_line; chatline++) { +static void +chat_clear() +{ + for (chatline = 2; chatline < stop_line; chatline++) { move(chatline, 0); clrtoeol(); } @@ -32,44 +36,50 @@ static void chat_clear() { outs("¡÷"); } -static void print_chatid(char *chatid) { +static void +print_chatid(char *chatid) +{ move(b_lines - 1, 0); clrtoeol(); outs(chatid); outc(':'); } -static int chat_send(int fd, char *buf) { - int len; - char genbuf[200]; +static int +chat_send(int fd, char *buf) +{ + int len; + char genbuf[200]; sprintf(genbuf, "%s\n", buf); len = strlen(genbuf); return (send(fd, genbuf, len, 0) == len); } -static char chatroom[IDLEN]; /* Chat-Room Name */ +static char chatroom[IDLEN];/* Chat-Room Name */ -static int chat_recv(int fd, char *chatid) { - static char buf[512]; - static int bufstart = 0; - char genbuf[200]; - int c, len; - char *bptr; +static int +chat_recv(int fd, char *chatid) +{ + static char buf[512]; + static int bufstart = 0; + char genbuf[200]; + int c, len; + char *bptr; len = sizeof(buf) - bufstart - 1; - if((c = recv(fd, buf + bufstart, len, 0)) <= 0) + if ((c = recv(fd, buf + bufstart, len, 0)) <= 0) return -1; c += bufstart; bptr = buf; - while(c > 0) { + while (c > 0) { len = strlen(bptr) + 1; - if(len > c && len < (sizeof buf / 2)) + if (len > c && len < (sizeof buf / 2)) break; - if(*bptr == '/') { - switch(bptr[1]) { + if (*bptr == '/') { + switch (bptr[1]) { case 'c': chat_clear(); break; @@ -95,7 +105,7 @@ static int chat_recv(int fd, char *chatid) { bptr += len; } - if(c > 0) { + if (c > 0) { strcpy(genbuf, bptr); strcpy(buf, genbuf); bufstart = len - 1; @@ -104,28 +114,30 @@ static int chat_recv(int fd, char *chatid) { return 0; } -static int printuserent(userinfo_t *uentp) { - static char uline[80]; - static int cnt; - char pline[30]; +static int +printuserent(userinfo_t * uentp) +{ + static char uline[80]; + static int cnt; + char pline[30]; - if(!uentp) { - if(cnt) + if (!uentp) { + if (cnt) printchatline(uline); bzero(uline, 80); cnt = 0; return 0; } - if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) + if (!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) return 0; sprintf(pline, "%-13s%c%-10s ", uentp->userid, uentp->invisible ? '#' : ' ', modestring(uentp, 1)); - if(cnt < 2) + if (cnt < 2) strcat(pline, "¢x"); strcat(uline, pline); - if(++cnt == 3) { + if (++cnt == 3) { printchatline(uline); memset(uline, 0, 80); cnt = 0; @@ -133,15 +145,19 @@ static int printuserent(userinfo_t *uentp) { return 0; } -static void chathelp(char *cmd, char *desc) { - char buf[STRLEN]; - +static void +chathelp(char *cmd, char *desc) +{ + char buf[STRLEN]; + sprintf(buf, " %-20s- %s", cmd, desc); printchatline(buf); } -static void chat_help(char *arg) { - if(strstr(arg, " op")) { +static void +chat_help(char *arg) +{ + if (strstr(arg, " op")) { printchatline("½Í¤Ñ«ÇºÞ²zû±M¥Î«ü¥O"); chathelp("[/f]lag [+-][ls]", "³]©wÂê©w¡B¯µ±Kª¬ºA"); chathelp("[/i]nvite <id>", "ÁܽР<id> ¥[¤J½Í¤Ñ«Ç"); @@ -169,45 +185,51 @@ static void chat_help(char *arg) { } } -static void chat_date() { - char genbuf[200]; +static void +chat_date() +{ + char genbuf[200]; sprintf(genbuf, "¡» " BBSNAME "¼Ð·Ç®É¶¡: %s", Cdate(&now)); printchatline(genbuf); } -static void chat_pager() { - char genbuf[200]; +static void +chat_pager() +{ + char genbuf[200]; - char *msgs[] = {"Ãö³¬", "¥´¶}", "©Þ±¼", "¨¾¤ô","¦n¤Í"}; + char *msgs[] = {"Ãö³¬", "¥´¶}", "©Þ±¼", "¨¾¤ô", "¦n¤Í"}; sprintf(genbuf, "¡» ±zªº©I¥s¾¹:[%s]", - msgs[currutmp->pager = (currutmp->pager+1)%5]); + msgs[currutmp->pager = (currutmp->pager + 1) % 5]); printchatline(genbuf); } -static void chat_query(char *arg) { - char *uid; - int tuid; - +static void +chat_query(char *arg) +{ + char *uid; + int tuid; + printchatline(""); strtok(arg, str_space); - if((uid = strtok(NULL, str_space)) && (tuid = getuser(uid))) { - char buf[128], *ptr; - FILE *fp; - + if ((uid = strtok(NULL, str_space)) && (tuid = getuser(uid))) { + char buf[128], *ptr; + FILE *fp; + sprintf(buf, "%s(%s) ¦@¤W¯¸ %d ¦¸¡Aµoªí¹L %d ½g¤å³¹", - xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); + xuser.userid, xuser.username, xuser.numlogins, xuser.numposts); printchatline(buf); - + sprintf(buf, "³Ìªñ(%s)±q[%s]¤W¯¸", Cdate(&xuser.lastlogin), (xuser.lasthost[0] ? xuser.lasthost : "(¤£¸Ô)")); printchatline(buf); - + sethomefile(buf, xuser.userid, fn_plans); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { tuid = 0; - while(tuid++ < MAX_QUERYLINES && fgets(buf, 128, fp)) { - if((ptr = strchr(buf, '\n'))) + while (tuid++ < MAX_QUERYLINES && fgets(buf, 128, fp)) { + if ((ptr = strchr(buf, '\n'))) ptr[0] = '\0'; printchatline(buf); } @@ -217,20 +239,22 @@ static void chat_query(char *arg) { printchatline(err_uid); } -static void chat_users() { +static void +chat_users() +{ printchatline(""); printchatline("¡i " BBSNAME "ªº¹C«È¦Cªí ¡j"); printchatline(msg_shortulist); - if(apply_ulist(printuserent) == -1) + if (apply_ulist(printuserent) == -1) printchatline("ªÅµL¤@¤H"); printuserent(NULL); } typedef struct chat_command_t { - char *cmdname; /* Chatroom command length */ - void (*cmdfunc) (); /* Pointer to function */ -} chat_command_t; + char *cmdname; /* Chatroom command length */ + void (*cmdfunc) (); /* Pointer to function */ +} chat_command_t; static chat_command_t chat_cmdtbl[] = { {"help", chat_help}, @@ -242,21 +266,25 @@ static chat_command_t chat_cmdtbl[] = { {NULL, NULL} }; -static int chat_cmd_match(char *buf, char *str) { - while(*str && *buf && !isspace(*buf)) - if(tolower(*buf++) != *str++) +static int +chat_cmd_match(char *buf, char *str) +{ + while (*str && *buf && !isspace(*buf)) + if (tolower(*buf++) != *str++) return 0; return 1; } -static int chat_cmd(char *buf, int fd) { - int i; +static int +chat_cmd(char *buf, int fd) +{ + int i; - if(*buf++ != '/') + if (*buf++ != '/') return 0; - for(i = 0; chat_cmdtbl[i].cmdname; i++) { - if(chat_cmd_match(buf, chat_cmdtbl[i].cmdname)) { + for (i = 0; chat_cmdtbl[i].cmdname; i++) { + if (chat_cmd_match(buf, chat_cmdtbl[i].cmdname)) { chat_cmdtbl[i].cmdfunc(buf); return 1; } @@ -265,31 +293,33 @@ static int chat_cmd(char *buf, int fd) { } #if 0 -static char *select_address() { - int c; - FILE *fp; - char nametab[25][90]; - char iptab[25][18], buf[80]; +static char * +select_address() +{ + int c; + FILE *fp; + char nametab[25][90]; + char iptab[25][18], buf[80]; move(1, 0); clrtobot(); outs("\n \033[36m¡i§äÓ¦a¤è©ï©ïºb§a!¡j\033[m " "¡· ¡i¥H¤U¬°¥»¯¸µn°O¦³®×ªº¯ù¼Ó¡j \n"); - trans_buffer[0]=0; - if((fp = fopen("etc/teashop", "r"))) { - for(c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { - sprintf(buf,"\n (\033[36m%d\033[0m) %-30s [%s]", + trans_buffer[0] = 0; + if ((fp = fopen("etc/teashop", "r"))) { + for (c = 0; fscanf(fp, "%s%s", iptab[c], nametab[c]) != EOF; c++) { + sprintf(buf, "\n (\033[36m%d\033[0m) %-30s [%s]", c + 1, nametab[c], iptab[c]); - outs(buf); + outs(buf); } - getdata(20, 10, "¡¹\033[32m ½Ð¿ï¾Ü¡A[0]Â÷¶}¡G\033[0m", buf, 3, + getdata(20, 10, "¡¹\033[32m ½Ð¿ï¾Ü¡A[0]Â÷¶}¡G\033[0m", buf, 3, LCECHO); - if(buf[1]) + if (buf[1]) buf[0] = (buf[0] + 1) * 10 + (buf[1] - '1'); else buf[0] -= '1'; - if(buf[0] >= 0 && buf[0] < c) - strcpy(trans_buffer,iptab[(int)buf[0]]); + if (buf[0] >= 0 && buf[0] < c) + strcpy(trans_buffer, iptab[(int)buf[0]]); } else { outs("¥»¯¸¨S¦³µn°O¥ô¦ó¦X®æ¯ù¼Ó"); pressanykey(); @@ -299,25 +329,27 @@ static char *select_address() { #endif #define MAXLASTCMD 6 -static int chatid_len = 10; +static int chatid_len = 10; -int t_chat() { - char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; +int +t_chat() +{ + char inbuf[80], chatid[20], lastcmd[MAXLASTCMD][80], *ptr = ""; struct sockaddr_in sin; struct hostent *h; - int cfd, cmdpos, ch; - int currchar; - int newmail; - int chatting = YEA; - char fpath[80]; - char genbuf[200]; - char roomtype; - - if(inbuf[0] == 0) + int cfd, cmdpos, ch; + int currchar; + int newmail; + int chatting = YEA; + char fpath[80]; + char genbuf[200]; + char roomtype; + + if (inbuf[0] == 0) return -1; outs(" ÅX¨®«e©¹ ½Ð±éÔ........ "); - if(!(h = gethostbyname("localhost"))) { + if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); return -1; } @@ -329,69 +361,69 @@ int t_chat() { memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = htons(NEW_CHATPORT); cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) roomtype = 1; else { sin.sin_port = CHATPORT; cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if(!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) + if (!(connect(cfd, (struct sockaddr *) & sin, sizeof sin))) roomtype = 2; else { outs("\n " "«z! ¨S¤H¦b¨ºÃäC...n¦³¨º¦a¤èªº¤H¥ý¥h¶}ªù°Õ!..."); - system("bin/xchatd"); + system("bin/xchatd"); pressanykey(); return -1; } } - - while(1) { + + while (1) { getdata(b_lines - 1, 0, "½Ð¿é¤J²á¤Ñ¥N¸¹¡G", inbuf, 9, DOECHO); sprintf(chatid, "%s", (inbuf[0] ? inbuf : cuser.userid)); chatid[8] = '\0'; -/* - ®榡: /! ¨Ï¥ÎªÌ½s¸¹ ¨Ï¥ÎªÌµ¥¯Å UserID ChatID - ·s®æ¦¡: /! UserID ChatID Password -*/ - if(roomtype == 1) + /* + * ®榡: /! ¨Ï¥ÎªÌ½s¸¹ ¨Ï¥ÎªÌµ¥¯Å UserID ChatID ·s®æ¦¡: /! + * UserID ChatID Password + */ + if (roomtype == 1) sprintf(inbuf, "/! %s %s %s", cuser.userid, chatid, cuser.passwd); else sprintf(inbuf, "/! %d %d %s %s", usernum, cuser.userlevel, cuser.userid, chatid); chat_send(cfd, inbuf); - if(recv(cfd, inbuf, 3, 0) != 3) + if (recv(cfd, inbuf, 3, 0) != 3) return 0; - if(!strcmp(inbuf, CHAT_LOGIN_OK)) + if (!strcmp(inbuf, CHAT_LOGIN_OK)) break; - else if(!strcmp(inbuf, CHAT_LOGIN_EXISTS)) + else if (!strcmp(inbuf, CHAT_LOGIN_EXISTS)) ptr = "³oÓ¥N¸¹¤w¸g¦³¤H¥Î¤F"; - else if(!strcmp(inbuf, CHAT_LOGIN_INVALID)) + else if (!strcmp(inbuf, CHAT_LOGIN_INVALID)) ptr = "³oÓ¥N¸¹¬O¿ù»~ªº"; - else if(!strcmp(inbuf, CHAT_LOGIN_BOGUS)) + else if (!strcmp(inbuf, CHAT_LOGIN_BOGUS)) ptr = "½Ð¤Å¬£»º¤À¨¶i¤J²á¤Ñ«Ç !!"; - + move(b_lines - 2, 0); outs(ptr); clrtoeol(); bell(); } - + add_io(cfd, 0); - + newmail = currchar = 0; cmdpos = -1; memset(lastcmd, 0, MAXLASTCMD * 80); - + setutmpmode(CHATING); currutmp->in_chat = YEA; strcpy(currutmp->chatid, chatid); - + clear(); chatline = 2; strcpy(inbuf, chatid); stop_line = t_lines - 3; - + move(stop_line, 0); outs(msg_seperator); move(1, 0); @@ -403,11 +435,11 @@ int t_chat() { strcpy(fpath, tempnam(fpath, "chat_")); flog = fopen(fpath, "w"); - while(chatting) { + while (chatting) { move(b_lines - 1, currchar + chatid_len); ch = igetkey(); - switch(ch) { + switch (ch) { case KEY_DOWN: cmdpos += MAXLASTCMD - 2; case KEY_UP: @@ -420,37 +452,36 @@ int t_chat() { currchar = strlen(inbuf); continue; case KEY_LEFT: - if(currchar) + if (currchar) --currchar; continue; case KEY_RIGHT: - if(inbuf[currchar]) + if (inbuf[currchar]) ++currchar; continue; } - if(!newmail && currutmp->mailalert ) { + if (!newmail && currutmp->mailalert) { newmail = 1; printchatline("¡» ¾´¡I¶l®t¤S¨Ó¤F..."); } - - if(ch == I_OTHERDATA) { /* incoming */ - if(chat_recv(cfd, chatid) == -1) { + if (ch == I_OTHERDATA) {/* incoming */ + if (chat_recv(cfd, chatid) == -1) { chatting = chat_send(cfd, "/b"); break; } continue; } - if(isprint2(ch)) { - if(currchar < 68) { - if(inbuf[currchar]) { /* insert */ - int i; - - for(i = currchar; inbuf[i] && i < 68; i++); - inbuf[i + 1 ] = '\0'; - for(; i > currchar; i--) + if (isprint2(ch)) { + if (currchar < 68) { + if (inbuf[currchar]) { /* insert */ + int i; + + for (i = currchar; inbuf[i] && i < 68; i++); + inbuf[i + 1] = '\0'; + for (; i > currchar; i--) inbuf[i] = inbuf[i - 1]; - } else /* append */ + } else /* append */ inbuf[currchar + 1] = '\0'; inbuf[currchar] = ch; move(b_lines - 1, currchar + chatid_len); @@ -458,19 +489,18 @@ int t_chat() { } continue; } - - if(ch == '\n' || ch == '\r') { - if(*inbuf) { + if (ch == '\n' || ch == '\r') { + if (*inbuf) { chatting = chat_cmd(inbuf, cfd); - if(chatting == 0) + if (chatting == 0) chatting = chat_send(cfd, inbuf); - if(!strncmp(inbuf, "/b", 2)) + if (!strncmp(inbuf, "/b", 2)) break; - - for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) + + for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); strcpy(lastcmd[0], inbuf); - + inbuf[0] = '\0'; currchar = 0; cmdpos = -1; @@ -479,9 +509,8 @@ int t_chat() { move(b_lines - 1, chatid_len); continue; } - - if(ch == Ctrl('H') || ch == '\177') { - if(currchar) { + if (ch == Ctrl('H') || ch == '\177') { + if (currchar) { currchar--; inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); @@ -491,20 +520,19 @@ int t_chat() { } continue; } - if(ch == Ctrl('Z') || ch == Ctrl('Y')) { + if (ch == Ctrl('Z') || ch == Ctrl('Y')) { inbuf[0] = '\0'; currchar = 0; print_chatid(chatid); move(b_lines - 1, chatid_len); continue; } - - if(ch == Ctrl('C')) { + if (ch == Ctrl('C')) { chat_send(cfd, "/b"); break; } - if(ch == Ctrl('D')) { - if(currchar < strlen(inbuf)) { + if (ch == Ctrl('D')) { + if (currchar < strlen(inbuf)) { inbuf[69] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 69 - currchar); move(b_lines - 1, currchar + chatid_len); @@ -513,22 +541,22 @@ int t_chat() { } continue; } - if(ch == Ctrl('K')) { + if (ch == Ctrl('K')) { inbuf[currchar] = 0; move(b_lines - 1, currchar + chatid_len); clrtoeol(); continue; } - if(ch == Ctrl('A')) { + if (ch == Ctrl('A')) { currchar = 0; continue; } - if(ch == Ctrl('E')) { + if (ch == Ctrl('E')) { currchar = strlen(inbuf); continue; } - if(ch == Ctrl('I')) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + if (ch == Ctrl('I')) { + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); add_io(0, 0); @@ -539,32 +567,32 @@ int t_chat() { add_io(cfd, 0); continue; } - if(ch == Ctrl('Q')) { + if (ch == Ctrl('Q')) { print_chatid(chatid); move(b_lines - 1, chatid_len); outs(inbuf); continue; } } - + close(cfd); add_io(0, 0); currutmp->in_chat = currutmp->chatid[0] = 0; - - if(flog) { - char ans[4]; - + + if (flog) { + char ans[4]; + fclose(flog); more(fpath, NA); getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) (C/M)?[C]", ans, sizeof(ans), LCECHO); if (*ans == 'm') { - fileheader_t mymail; - char title[128]; - + fileheader_t mymail; + char title[128]; + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ|FILE_HOLD; + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]"); strcpy(mymail.title, "·|ij\033[1;33m°O¿ý\033[m"); sethomedir(title, cuser.userid); @@ -573,7 +601,6 @@ int t_chat() { } else unlink(fpath); } - return 0; } /* -------------------------------------------------- */ diff --git a/mbbsd/chc_draw.c b/mbbsd/chc_draw.c index bb9a15a9..9f4091b1 100644 --- a/mbbsd/chc_draw.c +++ b/mbbsd/chc_draw.c @@ -1,4 +1,4 @@ -/* $Id: chc_draw.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_draw.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define SIDE_ROW 10 @@ -9,49 +9,51 @@ #define MYWIN_ROW 17 #define HISWIN_ROW 18 -static char *turn_str[2] = {"¶Âªº", "¬õªº"}; +static char *turn_str[2] = {"¶Âªº", "¬õªº"}; -static char *num_str[10] = { +static char *num_str[10] = { "", "¤@", "¤G", "¤T", "¥|", "¤", "¤»", "¤C", "¤K", "¤E" }; -static char *chess_str[2][8] = { +static char *chess_str[2][8] = { /* 0 1 2 3 4 5 6 7 */ {" ", "±N", "¤h", "¶H", "¨®", "°¨", "¥]", "¨ò"}, {" ", "«Ó", "¥K", "¬Û", "¨®", "ØX", "¬¶", "§L"} }; -static char *chess_brd[BRD_ROW * 2 - 1] = { - /*0 1 2 3 4 5 6 7 8*/ - "¢z¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢{", /* 0 */ +static char *chess_brd[BRD_ROW * 2 - 1] = { + /* 0 1 2 3 4 5 6 7 8 */ + "¢z¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢{", /* 0 */ "¢x ¢x ¢x ¢x¢@¢x¡þ¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 1 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 1 */ "¢x ¢x ¢x ¢x¡þ¢x¢@¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 2 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 2 */ "¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 3 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 3 */ "¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x", - "¢u¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢t", /* 4 */ + "¢u¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢t", /* 4 */ "¢x ·¡ ªe º~ ¬É ¢x", - "¢u¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢t", /* 5 */ + "¢u¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢t", /* 5 */ "¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 6 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 6 */ "¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 7 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 7 */ "¢x ¢x ¢x ¢x¢@¢x¡þ¢x ¢x ¢x ¢x", - "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 8 */ + "¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t", /* 8 */ "¢x ¢x ¢x ¢x¡þ¢x¢@¢x ¢x ¢x ¢x", - "¢|¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢}" /* 9 */ + "¢|¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢}" /* 9 */ }; -static char *hint_str[] = { +static char *hint_str[] = { " q »{¿éÂ÷¶}", " p n¨D©M´Ñ", "¤è¦VÁä ²¾°Ê¹C¼Ð", "Enter ¿ï¾Ü/²¾°Ê" }; -void chc_movecur(int r, int c) { +void +chc_movecur(int r, int c) +{ move(r * 2 + 3, c * 4 + 4); } @@ -61,22 +63,25 @@ void chc_movecur(int r, int c) { #define RED_REVERSE "\033[1;37;41m" #define TURN_COLOR "\033[1;33m" -static void showstep(board_t board) { - int turn, fc, tc, eatten; - char *dir; - +static void +showstep(board_t board) +{ + int turn, fc, tc, eatten; + char *dir; + turn = CHE_O(board[chc_from.r][chc_from.c]); fc = (turn == (chc_my ^ 1) ? chc_from.c + 1 : 9 - chc_from.c); tc = (turn == (chc_my ^ 1) ? chc_to.c + 1 : 9 - chc_to.c); - if(chc_from.r == chc_to.r) + if (chc_from.r == chc_to.r) dir = "¥"; else { - if(chc_from.c == chc_to.c) + if (chc_from.c == chc_to.c) tc = chc_from.r - chc_to.r; - if(tc < 0) tc = -tc; - - if((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || - (turn == chc_my && chc_to.r < chc_from.r)) + if (tc < 0) + tc = -tc; + + if ((turn == (chc_my ^ 1) && chc_to.r > chc_from.r) || + (turn == chc_my && chc_to.r < chc_from.r)) dir = "¶i"; else dir = "°h"; @@ -86,28 +91,30 @@ static void showstep(board_t board) { chess_str[turn][CHE_P(board[chc_from.r][chc_from.c])], num_str[fc], dir, num_str[tc]); eatten = board[chc_to.r][chc_to.c]; - if(eatten) + if (eatten) prints("¡G %s%s", CHE_O(eatten) == 0 ? BLACK_COLOR : RED_COLOR, chess_str[CHE_O(eatten)][CHE_P(eatten)]); prints("\033[m"); } -void chc_drawline(board_t board, int line) { - int i, j; - +void +chc_drawline(board_t board, int line) +{ + int i, j; + move(line, 0); clrtoeol(); - if(line == 0) { + if (line == 0) { prints("\033[1;46m ¶H´Ñ¹ï¾Ô \033[45m%30s VS %-30s\033[m", cuser.userid, chc_mateid); - } else if(line >= 3 && line <= 21) { + } else if (line >= 3 && line <= 21) { outs(" "); - for(i = 0; i < 9; i++) { + for (i = 0; i < 9; i++) { j = board[RTL(line)][i]; - if((line & 1) == 1 && j) { - if(chc_selected && - chc_select.r == RTL(line) && chc_select.c == i) + if ((line & 1) == 1 && j) { + if (chc_selected && + chc_select.r == RTL(line) && chc_select.c == i) prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, chess_str[CHE_O(j)][CHE_P(j)]); @@ -118,36 +125,36 @@ void chc_drawline(board_t board, int line) { } else prints("%c%c", chess_brd[line - 3][i * 4], chess_brd[line - 3][i * 4 + 1]); - if(i != 8) + if (i != 8) prints("%c%c", chess_brd[line - 3][i * 4 + 2], chess_brd[line - 3][i * 4 + 3]); } outs(" "); - if(line >= 3 && line < 3 + dim(hint_str)) { + if (line >= 3 && line < 3 + dim(hint_str)) { outs(hint_str[line - 3]); - } else if(line == SIDE_ROW) { + } else if (line == SIDE_ROW) { prints("\033[1m§A¬O%s%s\033[m", chc_my == 0 ? BLACK_COLOR : RED_COLOR, turn_str[chc_my]); - } else if(line == TURN_ROW) { + } else if (line == TURN_ROW) { prints("%s%s\033[m", TURN_COLOR, chc_my == chc_turn ? "½ü¨ì§A¤U´Ñ¤F" : "µ¥«Ý¹ï¤è¤U´Ñ"); - } else if(line == STEP_ROW && !chc_firststep) { + } else if (line == STEP_ROW && !chc_firststep) { showstep(board); - } else if(line == TIME_ROW) { + } else if (line == TIME_ROW) { prints("³Ñ¾l®É¶¡ %d:%02d", chc_lefttime / 60, chc_lefttime % 60); - } else if(line == WARN_ROW) { + } else if (line == WARN_ROW) { outs(chc_warnmsg); - } else if(line == MYWIN_ROW) { + } else if (line == MYWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m³Ó " "\033[34m%2d\033[37m±Ñ " "\033[36m%2d\033[37m©M\033[m", cuser.userid, cuser.chc_win, cuser.chc_lose - 1, cuser.chc_tie); - } else if(line == HISWIN_ROW) { + } else if (line == HISWIN_ROW) { prints("\033[1;33m%12.12s " "\033[1;31m%2d\033[37m³Ó " "\033[34m%2d\033[37m±Ñ " @@ -155,20 +162,22 @@ void chc_drawline(board_t board, int line) { chc_mateid, chc_hiswin, chc_hislose - 1, chc_histie); } - } else if(line == 2 || line == 22) { + } else if (line == 2 || line == 22) { outs(" "); - if(line == 2) - for(i = 1; i <= 9; i++) + if (line == 2) + for (i = 1; i <= 9; i++) prints("%s ", num_str[i]); else - for(i = 9; i >= 1; i--) + for (i = 9; i >= 1; i--) prints("%s ", num_str[i]); } } -void chc_redraw(board_t board) { - int i; - - for(i = 0; i <= 22; i++) +void +chc_redraw(board_t board) +{ + int i; + + for (i = 0; i <= 22; i++) chc_drawline(board, i); } diff --git a/mbbsd/chc_net.c b/mbbsd/chc_net.c index b9f63d8f..ba52bf26 100644 --- a/mbbsd/chc_net.c +++ b/mbbsd/chc_net.c @@ -1,21 +1,25 @@ -/* $Id: chc_net.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_net.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" typedef struct drc_t { - rc_t from, to; -} drc_t; + rc_t from, to; +} drc_t; -int chc_recvmove(int s) { - drc_t buf; +int +chc_recvmove(int s) +{ + drc_t buf; - if(read(s, &buf, sizeof(buf)) != sizeof(buf)) + if (read(s, &buf, sizeof(buf)) != sizeof(buf)) return 1; chc_from = buf.from, chc_to = buf.to; return 0; } -void chc_sendmove(int s) { - drc_t buf; - +void +chc_sendmove(int s) +{ + drc_t buf; + buf.from = chc_from, buf.to = chc_to; write(s, &buf, sizeof(buf)); } diff --git a/mbbsd/chc_play.c b/mbbsd/chc_play.c index cffe3959..de093052 100644 --- a/mbbsd/chc_play.c +++ b/mbbsd/chc_play.c @@ -1,8 +1,8 @@ -/* $Id: chc_play.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_play.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -typedef int (*play_func_t)(int, board_t, board_t); +typedef int (*play_func_t) (int, board_t, board_t); -static int chc_ipass = 0, chc_hepass = 0; +static int chc_ipass = 0, chc_hepass = 0; #define CHC_TIMEOUT 300 #define SIDE_ROW 10 @@ -13,14 +13,16 @@ static int chc_ipass = 0, chc_hepass = 0; #define MYWIN_ROW 17 #define HISWIN_ROW 18 -static int hisplay(int s, board_t board, board_t tmpbrd) { - int start_time; - int endgame = 0, endturn = 0; - +static int +hisplay(int s, board_t board, board_t tmpbrd) +{ + int start_time; + int endgame = 0, endturn = 0; + start_time = now; - while(!endturn) { + while (!endturn) { chc_lefttime = CHC_TIMEOUT - (now - start_time); - if(chc_lefttime < 0) { + if (chc_lefttime < 0) { chc_lefttime = 0; /* to make him break out igetkey() */ @@ -30,13 +32,13 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { chc_drawline(board, TIME_ROW); move(1, 0); oflush(); - switch(igetkey()) { + switch (igetkey()) { case 'q': endgame = 2; endturn = 1; break; case 'p': - if(chc_hepass) { + if (chc_hepass) { chc_from.r = -1; chc_sendmove(s); endgame = 3; @@ -44,11 +46,11 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { } break; case I_OTHERDATA: - if(chc_recvmove(s)) { /* disconnect */ + if (chc_recvmove(s)) { /* disconnect */ endturn = 1; endgame = 1; } else { - if(chc_from.r == -1) { + if (chc_from.r == -1) { chc_hepass = 1; strcpy(chc_warnmsg, "\033[1;33mn¨D©M§½!\033[m"); chc_drawline(board, WARN_ROW); @@ -56,7 +58,7 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; chc_cursor = chc_to; - if(CHE_P(board[chc_to.r][chc_to.c]) == 1) + if (CHE_P(board[chc_to.r][chc_to.c]) == 1) endgame = 2; endturn = 1; chc_hepass = 0; @@ -72,50 +74,52 @@ static int hisplay(int s, board_t board, board_t tmpbrd) { return endgame; } -static int myplay(int s, board_t board, board_t tmpbrd) { - int ch, start_time; - int endgame = 0, endturn = 0; - +static int +myplay(int s, board_t board, board_t tmpbrd) +{ + int ch, start_time; + int endgame = 0, endturn = 0; + chc_ipass = 0, chc_selected = 0; start_time = now; chc_lefttime = CHC_TIMEOUT - (now - start_time); bell(); - while(!endturn) { + while (!endturn) { chc_drawline(board, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); ch = igetkey(); - chc_lefttime = CHC_TIMEOUT - (now - start_time); - if(chc_lefttime < 0) + chc_lefttime = CHC_TIMEOUT - (now - start_time); + if (chc_lefttime < 0) ch = 'q'; - switch(ch) { + switch (ch) { case I_OTHERDATA: - if(chc_recvmove(s)) { /* disconnect */ + if (chc_recvmove(s)) { /* disconnect */ endgame = 1; endturn = 1; - } else if(chc_from.r == -1 && chc_ipass) { + } else if (chc_from.r == -1 && chc_ipass) { endgame = 3; endturn = 1; } break; case KEY_UP: chc_cursor.r--; - if(chc_cursor.r < 0) + if (chc_cursor.r < 0) chc_cursor.r = BRD_ROW - 1; break; case KEY_DOWN: chc_cursor.r++; - if(chc_cursor.r >= BRD_ROW) + if (chc_cursor.r >= BRD_ROW) chc_cursor.r = 0; break; case KEY_LEFT: chc_cursor.c--; - if(chc_cursor.c < 0) + if (chc_cursor.c < 0) chc_cursor.c = BRD_COL - 1; break; case KEY_RIGHT: chc_cursor.c++; - if(chc_cursor.c >= BRD_COL) + if (chc_cursor.c >= BRD_COL) chc_cursor.c = 0; break; case 'q': @@ -133,21 +137,21 @@ static int myplay(int s, board_t board, board_t tmpbrd) { case '\r': case '\n': case ' ': - if(chc_selected) { - if(chc_cursor.r == chc_select.r && - chc_cursor.c == chc_select.c) { + if (chc_selected) { + if (chc_cursor.r == chc_select.r && + chc_cursor.c == chc_select.c) { chc_selected = 0; chc_drawline(board, LTR(chc_cursor.r)); - } else if(chc_canmove(board, chc_select, chc_cursor)) { - if(CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) + } else if (chc_canmove(board, chc_select, chc_cursor)) { + if (CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) endgame = 1; chc_from = chc_select; chc_to = chc_cursor; - if(!endgame) { + if (!endgame) { memcpy(tmpbrd, board, sizeof(board_t)); chc_movechess(tmpbrd); } - if(endgame || !chc_iskfk(tmpbrd)) { + if (endgame || !chc_iskfk(tmpbrd)) { chc_drawline(board, STEP_ROW); chc_movechess(board); chc_sendmove(s); @@ -161,8 +165,8 @@ static int myplay(int s, board_t board, board_t tmpbrd) { chc_drawline(board, WARN_ROW); } } - } else if(board[chc_cursor.r][chc_cursor.c] && - CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { + } else if (board[chc_cursor.r][chc_cursor.c] && + CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { chc_selected = 1; chc_select = chc_cursor; chc_drawline(board, LTR(chc_cursor.r)); @@ -173,29 +177,31 @@ static int myplay(int s, board_t board, board_t tmpbrd) { return endgame; } -static void mainloop(int s, board_t board) { - int endgame; - board_t tmpbrd; - play_func_t play_func[2]; - +static void +mainloop(int s, board_t board) +{ + int endgame; + board_t tmpbrd; + play_func_t play_func[2]; + play_func[chc_my] = myplay; play_func[chc_my ^ 1] = hisplay; - for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { + for (chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { chc_firststep = 0; chc_drawline(board, TURN_ROW); - if(chc_ischeck(board, chc_turn)) { + if (chc_ischeck(board, chc_turn)) { strcpy(chc_warnmsg, "\033[1;31m±Nx!\033[m"); bell(); } else chc_warnmsg[0] = 0; chc_drawline(board, WARN_ROW); - endgame = play_func[chc_turn](s, board, tmpbrd); + endgame = play_func[chc_turn] (s, board, tmpbrd); } - - if(endgame == 1) { + + if (endgame == 1) { strcpy(chc_warnmsg, "¹ï¤è»{¿é¤F!"); cuser.chc_win++; - } else if(endgame == 2) { + } else if (endgame == 2) { strcpy(chc_warnmsg, "§A»{¿é¤F!"); cuser.chc_lose++; } else { @@ -209,8 +215,10 @@ static void mainloop(int s, board_t board) { oflush(); } -static void chc_init(int s, board_t board) { - userinfo_t *my = currutmp; +static void +chc_init(int s, board_t board) +{ + userinfo_t *my = currutmp; setutmpmode(CHC); clear(); @@ -222,34 +230,37 @@ static void chc_init(int s, board_t board) { chc_redraw(board); chc_cursor.r = 9, chc_cursor.c = 0; add_io(s, 0); - - if(my->turn) chc_recvmove(s); + + if (my->turn) + chc_recvmove(s); passwd_query(usernum, &xuser); cuser.chc_win = xuser.chc_win; cuser.chc_lose = xuser.chc_lose + 1; cuser.chc_tie = xuser.chc_tie; - cuser.money = xuser.money; + cuser.money = xuser.money; passwd_update(usernum, &cuser); - + getuser(chc_mateid); chc_hiswin = xuser.chc_win; chc_hislose = xuser.chc_lose; chc_histie = xuser.chc_tie; - - if(!my->turn) { + + if (!my->turn) { chc_sendmove(s); chc_hislose++; } - chc_redraw(board); } -void chc(int s) { - board_t board; - +void +chc(int s) +{ + board_t board; + chc_init(s, board); mainloop(s, board); close(s); add_io(0, 0); - if(chc_my) pressanykey(); + if (chc_my) + pressanykey(); } diff --git a/mbbsd/chc_rule.c b/mbbsd/chc_rule.c index e5a92c32..62996764 100644 --- a/mbbsd/chc_rule.c +++ b/mbbsd/chc_rule.c @@ -1,177 +1,195 @@ -/* $Id: chc_rule.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: chc_rule.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define CENTER(a, b) (((a) + (b)) >> 1) -void chc_init_board(board_t board) { +void +chc_init_board(board_t board) +{ memset(board, 0, sizeof(board_t)); - board[0][4] = CHE(1, chc_my ^ 1); /* ±N */ - board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* ¤h */ - board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* ¶H */ - board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* ¨® */ - board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* °¨ */ - board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* ¥] */ + board[0][4] = CHE(1, chc_my ^ 1); /* ±N */ + board[0][3] = board[0][5] = CHE(2, chc_my ^ 1); /* ¤h */ + board[0][2] = board[0][6] = CHE(3, chc_my ^ 1); /* ¶H */ + board[0][0] = board[0][8] = CHE(4, chc_my ^ 1); /* ¨® */ + board[0][1] = board[0][7] = CHE(5, chc_my ^ 1); /* °¨ */ + board[2][1] = board[2][7] = CHE(6, chc_my ^ 1); /* ¥] */ board[3][0] = board[3][2] = board[3][4] = - board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* ¨ò */ - - board[9][4] = CHE(1, chc_my); /* «Ó */ - board[9][3] = board[9][5] = CHE(2, chc_my); /* ¥K */ - board[9][2] = board[9][6] = CHE(3, chc_my); /* ¬Û */ - board[9][0] = board[9][8] = CHE(4, chc_my); /* ¨® */ - board[9][1] = board[9][7] = CHE(5, chc_my); /* ØX */ - board[7][1] = board[7][7] = CHE(6, chc_my); /* ¬¶ */ + board[3][6] = board[3][8] = CHE(7, chc_my ^ 1); /* ¨ò */ + + board[9][4] = CHE(1, chc_my); /* «Ó */ + board[9][3] = board[9][5] = CHE(2, chc_my); /* ¥K */ + board[9][2] = board[9][6] = CHE(3, chc_my); /* ¬Û */ + board[9][0] = board[9][8] = CHE(4, chc_my); /* ¨® */ + board[9][1] = board[9][7] = CHE(5, chc_my); /* ØX */ + board[7][1] = board[7][7] = CHE(6, chc_my); /* ¬¶ */ board[6][0] = board[6][2] = board[6][4] = - board[6][6] = board[6][8] = CHE(7, chc_my); /* §L */ + board[6][6] = board[6][8] = CHE(7, chc_my); /* §L */ } -void chc_movechess(board_t board) { +void +chc_movechess(board_t board) +{ board[chc_to.r][chc_to.c] = board[chc_from.r][chc_from.c]; board[chc_from.r][chc_from.c] = 0; } -static int dist(rc_t from, rc_t to, int rowcol) { - int d; - +static int +dist(rc_t from, rc_t to, int rowcol) +{ + int d; + d = rowcol ? from.c - to.c : from.r - to.r; return d > 0 ? d : -d; } -static int between(board_t board, rc_t from, rc_t to, int rowcol) { - int i, rtv = 0; +static int +between(board_t board, rc_t from, rc_t to, int rowcol) +{ + int i, rtv = 0; - if(rowcol) { - if(from.c > to.c) + if (rowcol) { + if (from.c > to.c) i = from.c, from.c = to.c, to.c = i; - for(i = from.c + 1; i < to.c; i++) - if(board[to.r][i]) rtv++; + for (i = from.c + 1; i < to.c; i++) + if (board[to.r][i]) + rtv++; } else { - if(from.r > to.r) + if (from.r > to.r) i = from.r, from.r = to.r, to.r = i; - for(i = from.r + 1; i < to.r; i++) - if(board[i][to.c]) rtv++; + for (i = from.r + 1; i < to.r; i++) + if (board[i][to.c]) + rtv++; } return rtv; } -int chc_canmove(board_t board, rc_t from, rc_t to) { - int i; - int rd, cd, turn; +int +chc_canmove(board_t board, rc_t from, rc_t to) +{ + int i; + int rd, cd, turn; rd = dist(from, to, 0); cd = dist(from, to, 1); turn = CHE_O(board[from.r][from.c]); - + /* general check */ - if(board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) + if (board[to.r][to.c] && CHE_O(board[to.r][to.c]) == turn) return 0; /* individual check */ - switch(CHE_P(board[from.r][from.c])) { - case 1: /* ±N «Ó */ - if(!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) + switch (CHE_P(board[from.r][from.c])) { + case 1: /* ±N «Ó */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) return 0; - if((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || to.c < 3 || to.c > 5) - return 0; + return 0; break; - case 2: /* ¤h ¥K */ - if(!(rd == 1 && cd == 1)) + case 2: /* ¤h ¥K */ + if (!(rd == 1 && cd == 1)) return 0; - if((turn == (chc_my ^ 1) && to.r > 2) || - (turn == chc_my && to.r < 7) || + if ((turn == (chc_my ^ 1) && to.r > 2) || + (turn == chc_my && to.r < 7) || to.c < 3 || to.c > 5) - return 0; - break; - case 3: /* ¶H ¬Û */ - if(!(rd == 2 && cd == 2)) return 0; - if((turn == (chc_my ^ 1) && to.r > 4) || - (turn == chc_my && to.r < 5)) + break; + case 3: /* ¶H ¬Û */ + if (!(rd == 2 && cd == 2)) + return 0; + if ((turn == (chc_my ^ 1) && to.r > 4) || + (turn == chc_my && to.r < 5)) return 0; /* ©ä¶H»L */ - if(board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) + if (board[CENTER(from.r, to.r)][CENTER(from.c, to.c)]) return 0; break; - case 4: /* ¨® */ - if(!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) + case 4: /* ¨® */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) return 0; - if(between(board, from, to, rd == 0)) + if (between(board, from, to, rd == 0)) return 0; break; - case 5: /* °¨ ØX */ - if(!(rd == 2 && cd == 1) && - !(rd == 1 && cd == 2)) + case 5: /* °¨ ØX */ + if (!(rd == 2 && cd == 1) && + !(rd == 1 && cd == 2)) return 0; /* ©ä°¨¸} */ - if(rd == 2) { - if(board[CENTER(from.r, to.r)][from.c]) + if (rd == 2) { + if (board[CENTER(from.r, to.r)][from.c]) return 0; } else { - if(board[from.r][CENTER(from.c, to.c)]) + if (board[from.r][CENTER(from.c, to.c)]) return 0; - } + } break; - case 6: /* ¥] ¬¶ */ - if(!(rd > 0 && cd == 0) && - !(rd == 0 && cd > 0)) + case 6: /* ¥] ¬¶ */ + if (!(rd > 0 && cd == 0) && + !(rd == 0 && cd > 0)) return 0; i = between(board, from, to, rd == 0); - if((i > 1) || - (i == 1 && !board[to.r][to.c]) || - (i == 0 && board[to.r][to.c])) - return 0; + if ((i > 1) || + (i == 1 && !board[to.r][to.c]) || + (i == 0 && board[to.r][to.c])) + return 0; break; - case 7: /* ¨ò §L */ - if(!(rd == 1 && cd == 0) && - !(rd == 0 && cd == 1)) + case 7: /* ¨ò §L */ + if (!(rd == 1 && cd == 0) && + !(rd == 0 && cd == 1)) return 0; - if(((turn == (chc_my ^ 1) && to.r < 5) || - (turn == chc_my && to.r > 4)) && + if (((turn == (chc_my ^ 1) && to.r < 5) || + (turn == chc_my && to.r > 4)) && cd != 0) return 0; - if((turn == (chc_my ^ 1) && to.r < from.r) || - (turn == chc_my && to.r > from.r)) + if ((turn == (chc_my ^ 1) && to.r < from.r) || + (turn == chc_my && to.r > from.r)) return 0; break; } return 1; } -static void findking(board_t board, int turn, rc_t *buf) { - int i, r, c; +static void +findking(board_t board, int turn, rc_t * buf) +{ + int i, r, c; r = (turn == (chc_my ^ 1)) ? 0 : 7; - for(i = 0; i < 3; r++, i++) - for(c = 3; c < 6; c++) - if(CHE_P(board[r][c]) == 1 && - CHE_O(board[r][c]) == turn) { + for (i = 0; i < 3; r++, i++) + for (c = 3; c < 6; c++) + if (CHE_P(board[r][c]) == 1 && + CHE_O(board[r][c]) == turn) { buf->r = r, buf->c = c; - return ; + return; } } -int chc_iskfk(board_t board) { - rc_t from, to; - +int +chc_iskfk(board_t board) +{ + rc_t from, to; + findking(board, 0, &to); findking(board, 1, &from); - if(from.c == to.c && between(board, from, to, 0) == 0) + if (from.c == to.c && between(board, from, to, 0) == 0) return 1; return 0; } -int chc_ischeck(board_t board, int turn) { - rc_t from, to; - +int +chc_ischeck(board_t board, int turn) +{ + rc_t from, to; + findking(board, turn, &to); - for(from.r = 0;from.r < BRD_ROW; from.r++) - for(from.c = 0; from.c < BRD_COL; from.c++) - if(board[from.r][from.c] && - CHE_O(board[from.r][from.c]) != turn) - if(chc_canmove(board, from, to)) + for (from.r = 0; from.r < BRD_ROW; from.r++) + for (from.c = 0; from.c < BRD_COL; from.c++) + if (board[from.r][from.c] && + CHE_O(board[from.r][from.c]) != turn) + if (chc_canmove(board, from, to)) return 1; return 0; } diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 0b1c9320..6b43ee33 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -1,44 +1,44 @@ -/* $Id: chicken.c,v 1.5 2002/06/06 21:34:11 in2 Exp $ */ +/* $Id: chicken.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#define NUM_KINDS 13 /* ¦³¦h¤ÖºØ°Êª« */ +#define NUM_KINDS 13 /* ¦³¦h¤ÖºØ°Êª« */ -static const char *cage[17] = { +static const char *cage[17] = { "½Ï¥Í", "¶g·³", "¥®¦~", "¤Ö¦~", "«C¬K", "«C¦~", "«C¦~", "¬¡¤O", "§§¦~", "§§¦~", "§§¦~", "¤¤¦~", - "¤¤¦~", "¦Ñ¦~", "¦Ñ¦~", "¦Ñáàáà", "¥j§Æ"}; -static const char *chicken_type[NUM_KINDS] = { +"¤¤¦~", "¦Ñ¦~", "¦Ñ¦~", "¦Ñáàáà", "¥j§Æ"}; +static const char *chicken_type[NUM_KINDS] = { "¤pÂû", "¬ü¤Ö¤k", "«i¤h", "»jµï", "®£Às", "¦ÑÆN", "¿ß", "Äúµ§¤p·s", "ª¯ª¯", "´cÅ]", "§ÔªÌ", "£««ó", - "°¨^¤E"}; -static const char *chicken_food[NUM_KINDS] = { +"°¨^¤E"}; +static const char *chicken_food[NUM_KINDS] = { "Âû¹}®Æ", "Àç¾i«p¤ù", "Âû±Æ«K·í", "¦º½¹½º", "«ÍÅé", "¤pÂû", "¿ß»æ°®", "¤pºµ»æ°®", "Ä_¿ý", "ÆF®ð", "¶º¹Î", "«K·í", - "Âû»L"}; -static const int egg_price[NUM_KINDS] = { +"Âû»L"}; +static const int egg_price[NUM_KINDS] = { 5, 25, 30, 40, 80, 50, 15, 35, 17, 100, 85, 200, - 200}; -static const int food_price[NUM_KINDS] = { +200}; +static const int food_price[NUM_KINDS] = { 4, 6, 8, 10, 12, 12, 5, 6, 5, 20, 15, 23, - 23}; -static const char *attack_type[NUM_KINDS] = { +23}; +static const char *attack_type[NUM_KINDS] = { "°Ö", "Ã@¥´", "ºl", "«r", "¼²À»", "°Ö", "§ì", "½ð", - "«r","¿U¿N","·tÀ»","´Ò¥´", - "¼CÀ»"}; + "«r", "¿U¿N", "·tÀ»", "´Ò¥´", +"¼CÀ»"}; -static const char *damage_degree[] = { +static const char *damage_degree[] = { "°A¤l¦üªº", "ÄÌÄo¦üªº", "¤p¤Oªº", "»´·Lªº", "¦³ÂI¯kªº", "¨Ï¤Oªº", "¶Ë¤Hªº", "««ªº", "¨Ï¥þ¤Oªº", "´c¬½¬½ªº", "¦MÀIªº", "ºÆ¨gªº", "²r¯Pªº", "¨g·¼É«B¦üªº", "Åå¤Ñ°Ê¦aªº", - "P©Rªº", NULL}; +"P©Rªº", NULL}; enum { OO, FOOD, WEIGHT, CLEAN, RUN, ATTACK, BOOK, HAPPY, SATIS, @@ -46,55 +46,60 @@ enum { }; static chicken_t *mychicken = &cuser.mychicken; -static int age; +static int age; -static const int time_change[NUM_KINDS][14] = -/* ¸É«~ ¹ª« Åé« °®²b ±Ó±¶ §ðÀ»¤O ª¾ÃÑ §Ö¼Ö º¡·N ®ð½è ¯h³Ò ¯f®ð º¡¦å º¡ªk*/ +static const int time_change[NUM_KINDS][14] = +/* ¸É«~ ¹ª« Åé« °®²b ±Ó±¶ §ðÀ»¤O ª¾ÃÑ §Ö¼Ö º¡·N ®ð½è ¯h³Ò ¯f®ð º¡¦å º¡ªk */ { -/*Âû*/ - { 1, 1, 30, 3, 8, 3, 3, 40, 9, 1, 7, 3, 30, 1}, -/*¬ü¤Ö¤k*/ - { 1, 1, 110, 1, 4, 7, 41, 20, 9, 25, 25, 7, 110, 15}, -/*«i¤h*/ - { 1, 1, 200, 5, 4, 10, 33, 20, 15, 10, 27, 1, 200, 9}, -/*»jµï*/ - { 1, 1, 10, 5, 8, 1, 1, 5, 3, 1, 4, 1, 10, 30}, -/*®£Às*/ - { 1, 1,1000, 9, 1, 13, 4, 12, 3, 1, 200, 1, 1000, 3}, -/*¦ÑÆN*/ - { 1, 1, 90, 7, 10, 7, 4, 12, 3, 30, 20, 5, 90, 20}, -/*¿ß*/ - { 1, 1, 30, 5, 5, 6, 4, 8, 3, 15, 7, 4, 30, 21}, -/*Äúµ§¤p·s*/ - { 1, 1, 100, 9, 7, 7, 20, 50, 10, 8, 24, 4, 100, 9}, -/*ª¯*/ - { 1, 1, 45, 8, 7, 9, 3, 40, 20, 3, 9, 5, 45, 1}, -/* ´cÅ] */ - { 1, 1, 45, 10, 11, 11, 5, 21, 11, 1, 9, 5, 45, 25}, -/* §ÔªÌ */ - { 1, 1, 45, 2, 12, 10, 25, 1, 1, 10, 9, 5, 45, 26}, -/* ªü«ó */ - { 1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, -/* °¨^¤E */ - { 1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} + /* Âû */ + {1, 1, 30, 3, 8, 3, 3, 40, 9, 1, 7, 3, 30, 1}, + /* ¬ü¤Ö¤k */ + {1, 1, 110, 1, 4, 7, 41, 20, 9, 25, 25, 7, 110, 15}, + /* «i¤h */ + {1, 1, 200, 5, 4, 10, 33, 20, 15, 10, 27, 1, 200, 9}, + /* »jµï */ + {1, 1, 10, 5, 8, 1, 1, 5, 3, 1, 4, 1, 10, 30}, + /* ®£Às */ + {1, 1, 1000, 9, 1, 13, 4, 12, 3, 1, 200, 1, 1000, 3}, + /* ¦ÑÆN */ + {1, 1, 90, 7, 10, 7, 4, 12, 3, 30, 20, 5, 90, 20}, + /* ¿ß */ + {1, 1, 30, 5, 5, 6, 4, 8, 3, 15, 7, 4, 30, 21}, + /* Äúµ§¤p·s */ + {1, 1, 100, 9, 7, 7, 20, 50, 10, 8, 24, 4, 100, 9}, + /* ª¯ */ + {1, 1, 45, 8, 7, 9, 3, 40, 20, 3, 9, 5, 45, 1}, + /* ´cÅ] */ + {1, 1, 45, 10, 11, 11, 5, 21, 11, 1, 9, 5, 45, 25}, + /* §ÔªÌ */ + {1, 1, 45, 2, 12, 10, 25, 1, 1, 10, 9, 5, 45, 26}, + /* ªü«ó */ + {1, 1, 150, 4, 8, 13, 95, 25, 7, 10, 25, 5, 175, 85}, + /* °¨^¤E */ + {1, 1, 147, 2, 10, 10, 85, 20, 4, 25, 25, 5, 145, 95} }; -int reload_chicken() { +int +reload_chicken() +{ passwd_query(usernum, &xuser); memcpy(mychicken, &xuser.mychicken, sizeof(chicken_t)); - if(!mychicken->name[0]) + if (!mychicken->name[0]) return 0; - else return 1; + else + return 1; } #define CHICKENLOG "etc/chicken" -static int new_chicken() { - char buf[150]; - int price; - +static int +new_chicken() +{ + char buf[150]; + int price; + clear(); - move(2,0); + move(2, 0); outs("ÅwªïÆ[Á{ \033[33m¡·\033[37;44m PttÃdª«¥«³õ \033[33;40m¡·\033[m.. " "¥Ø«e³J»ù¡G\n" "(a)¤pÂû $5 (b)¬ü¤Ö¤k $25 (c)«i¤h $30 (d)»jµï $40 " @@ -106,65 +111,69 @@ static int new_chicken() { getdata_str(6, 0, "½Ð¿ï¾Ü§An¾iªº°Êª«¡G", buf, 3, LCECHO, "0"); buf[0] -= 'a'; - if(buf[0]<0 || buf[0]>NUM_KINDS-1) + if (buf[0] < 0 || buf[0] > NUM_KINDS - 1) return 0; - + mychicken->type = buf[0]; - + reload_money(); price = egg_price[(int)mychicken->type]; - if(cuser.money < price) { + if (cuser.money < price) { prints("\n ¿ú¤£°÷¶R³J³J,³J³Jn %d ¤¸", price); refresh(); return 0; } - vice(price,"Ãdª«³J"); - while(strlen(mychicken->name)<3) + vice(price, "Ãdª«³J"); + while (strlen(mychicken->name) < 3) getdata(8, 0, "À°¨e¨úÓ¦n¦W¦r¡G", mychicken->name, sizeof(mychicken->name), DOECHO); - sprintf(buf,"\033[31m%s \033[m¾i¤F¤@°¦¥s\033[33m %s \033[mªº " - "\033[32m%s\033[m ©ó %s",cuser.userid, - mychicken->name,chicken_type[(int)mychicken->type],ctime(&now)); - log_file(CHICKENLOG,buf); + sprintf(buf, "\033[31m%s \033[m¾i¤F¤@°¦¥s\033[33m %s \033[mªº " + "\033[32m%s\033[m ©ó %s", cuser.userid, + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + log_file(CHICKENLOG, buf); mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; - mychicken->food = 0; - mychicken->weight = time_change[(int)mychicken->type][WEIGHT]/3; - mychicken->clean = 0; - mychicken->run = time_change[(int)mychicken->type][RUN]; + mychicken->food = 0; + mychicken->weight = time_change[(int)mychicken->type][WEIGHT] / 3; + mychicken->clean = 0; + mychicken->run = time_change[(int)mychicken->type][RUN]; mychicken->attack = time_change[(int)mychicken->type][ATTACK]; - mychicken->book = time_change[(int)mychicken->type][BOOK]; - mychicken->happy = time_change[(int)mychicken->type][HAPPY]; - mychicken->satis = time_change[(int)mychicken->type][SATIS]; + mychicken->book = time_change[(int)mychicken->type][BOOK]; + mychicken->happy = time_change[(int)mychicken->type][HAPPY]; + mychicken->satis = time_change[(int)mychicken->type][SATIS]; mychicken->temperament = time_change[(int)mychicken->type][TEMPERAMENT]; mychicken->tiredstrong = 0; - mychicken->sick = 0; - mychicken->hp = time_change[(int)mychicken->type][WEIGHT]; + mychicken->sick = 0; + mychicken->hp = time_change[(int)mychicken->type][WEIGHT]; mychicken->hp_max = time_change[(int)mychicken->type][WEIGHT]; - mychicken->mm = 0; - mychicken->mm_max = 0; + mychicken->mm = 0; + mychicken->mm_max = 0; return 1; } -int show_file(char *filename, int y, int lines, int mode) { - FILE *fp; - char buf[256]; - - if(y >= 0) - move(y,0); +int +show_file(char *filename, int y, int lines, int mode) +{ + FILE *fp; + char buf[256]; + + if (y >= 0) + move(y, 0); clrtoline(lines + y); - if((fp=fopen(filename,"r"))) { - while(fgets(buf,256,fp) && lines--) - outs(Ptt_prints(buf,mode)); + if ((fp = fopen(filename, "r"))) { + while (fgets(buf, 256, fp) && lines--) + outs(Ptt_prints(buf, mode)); fclose(fp); } else return 0; return 1; } -static void show_chicken_stat(chicken_t *thechicken) { - struct tm *ptime; - +static void +show_chicken_stat(chicken_t * thechicken) +{ + struct tm *ptime; + ptime = localtime(&thechicken->birthday); prints(" Name :\033[33m%s\033[m (\033[32m%s\033[m)%*s¥Í¤é " ":\033[31m%02d\033[m¦~\033[31m%2d\033[m¤ë\033[31m%2d\033[m¤é " @@ -178,92 +187,96 @@ static void show_chicken_stat(chicken_t *thechicken) { " ¯f®ð :\033[33m%-7d\033[m °®²b :\033[33m%-7d\033[m ¹ª« :" "\033[33m%-7d\033[m ¤j¸É¤Y:\033[33m%-7d\033[m ÃÄ«~ :\033[33m%-7d" "\033[m \n", - thechicken->name, chicken_type[(int)thechicken->type], + thechicken->name, chicken_type[(int)thechicken->type], 15 - strlen(thechicken->name), "", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, - cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, + cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, thechicken->mm, thechicken->mm_max, thechicken->attack, thechicken->run, thechicken->book, thechicken->happy, thechicken->satis, thechicken->tiredstrong, thechicken->temperament, - ((float)(thechicken->hp_max+(thechicken->weight/50))) / 100, + ((float)(thechicken->hp_max + (thechicken->weight / 50))) / 100, thechicken->sick, thechicken->clean, thechicken->food, thechicken->oo, thechicken->medicine); } #define CHICKEN_PIC "etc/chickens" -void show_chicken_data(chicken_t *thechicken, chicken_t *pkchicken) { - char buf[1024]; - age = ((now - thechicken->cbirth)/ (60*60*24)); - if(age < 0) { - thechicken->birthday = thechicken->cbirth = now-10*(60*60*24); - age = 10; +void +show_chicken_data(chicken_t * thechicken, chicken_t * pkchicken) +{ + char buf[1024]; + age = ((now - thechicken->cbirth) / (60 * 60 * 24)); + if (age < 0) { + thechicken->birthday = thechicken->cbirth = now - 10 * (60 * 60 * 24); + age = 10; } - /*Ptt:debug*/ + /* Ptt:debug */ thechicken->type %= NUM_KINDS; clear(); showtitle(pkchicken ? "¢Þtt°«Âû³õ" : "¢Þtt¾iÂû³õ", BBSName); - move(1,0); - + move(1, 0); + show_chicken_stat(thechicken); - + sprintf(buf, CHICKEN_PIC "/%c%d", thechicken->type + 'a', age > 16 ? 16 : age); show_file(buf, 5, 14, NO_RELOAD); - - move(18,0); - - if(thechicken->sick) + + move(18, 0); + + if (thechicken->sick) outs("¥Í¯f¤F..."); - if(thechicken->sick > thechicken->hp / 5) + if (thechicken->sick > thechicken->hp / 5) outs("\033[5;31m¾á¤ß...¯f«!!\033[m"); - if(thechicken->clean > 150) + if (thechicken->clean > 150) outs("\033[31m¤S¯ä¤Sżªº..\033[m"); - else if(thechicken->clean > 80) + else if (thechicken->clean > 80) outs("¦³ÂIż.."); - else if(thechicken->clean < 20) + else if (thechicken->clean < 20) outs("\033[32m«Ü°®²b..\033[m"); - if(thechicken->weight > thechicken->hp_max*4) + if (thechicken->weight > thechicken->hp_max * 4) outs("\033[31m§Ö¹¡¦º¤F!.\033[m"); - else if(thechicken->weight > thechicken->hp_max*3) + else if (thechicken->weight > thechicken->hp_max * 3) outs("\033[32m¹¡¹Ê¹Ê..\033[m"); - else if(thechicken->weight < (thechicken->hp_max / 4)) + else if (thechicken->weight < (thechicken->hp_max / 4)) outs("\033[31m§Ö¾j¦º¤F!..\033[m"); - else if(thechicken->weight < (thechicken->hp_max / 2)) + else if (thechicken->weight < (thechicken->hp_max / 2)) outs("¾j¤F.."); - if(thechicken->tiredstrong > thechicken->hp * 1.7) + if (thechicken->tiredstrong > thechicken->hp * 1.7) outs("\033[31m²Ö±o©ü°g¤F...\033[m"); - else if(thechicken->tiredstrong > thechicken->hp) + else if (thechicken->tiredstrong > thechicken->hp) outs("²Ö¤F.."); - else if(thechicken->tiredstrong < thechicken->hp / 4) + else if (thechicken->tiredstrong < thechicken->hp / 4) outs("\033[32mºë¤O©ô²±...\033[m"); - if(thechicken->hp < thechicken->hp_max / 4) + if (thechicken->hp < thechicken->hp_max / 4) outs("\033[31mÅé¤O¥ÎºÉ..©a©a¤@®§..\033[m"); - if(thechicken->happy > 500) + if (thechicken->happy > 500) outs("\033[32m«Ü§Ö¼Ö..\033[m"); - else if(thechicken->happy < 100) + else if (thechicken->happy < 100) outs("¤£§Ö¼Ö.."); - if(thechicken->satis > 500) + if (thechicken->satis > 500) outs("\033[32m«Üº¡¨¬..\033[m"); - else if(thechicken->satis < 50) + else if (thechicken->satis < 50) outs("¤£º¡¨¬.."); - if(pkchicken) { + if (pkchicken) { outs("\n"); show_chicken_stat(pkchicken); outs("[¥ô·NÁä] §ðÀ»¹ï¤è [q] ¸¨¶] [o] ¦Y¤j¸É¤Y"); } } -static void ch_eat() { - if(mychicken->food) { +static void +ch_eat() +{ + if (mychicken->food) { mychicken->weight += time_change[(int)mychicken->type][WEIGHT] + - mychicken->hp_max/5 ; + mychicken->hp_max / 5; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG] / 2; mychicken->hp_max++; @@ -271,13 +284,15 @@ static void ch_eat() { mychicken->satis += 7; mychicken->food--; move(10, 10); - + show_file(CHICKEN_PIC "/eat", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_clean() { +static void +ch_clean() +{ mychicken->clean = 0; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG] / 3; @@ -285,37 +300,43 @@ static void ch_clean() { pressanykey(); } -static void ch_guess() { - char *guess[3] = {"°Å¤M", "¥ÛÀY", "¥¬"}, me, ch, win; - - mychicken->happy += time_change[(int)mychicken->type][HAPPY]*1.5; +static void +ch_guess() +{ + char *guess[3] = {"°Å¤M", "¥ÛÀY", "¥¬"}, me, ch, win; + + mychicken->happy += time_change[(int)mychicken->type][HAPPY] * 1.5; mychicken->satis += time_change[(int)mychicken->type][SATIS]; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; - mychicken->attack += time_change[(int)mychicken->type][ATTACK]/4; - move(20,0); + mychicken->attack += time_change[(int)mychicken->type][ATTACK] / 4; + move(20, 0); clrtobot(); outs("§An¥X[\033[32m1\033[m]\033[33m°Å¤M\033[m(\033[32m2\033[m)" "\033[33m¥ÛÀY\033[m(\033[32m3\033[m)\033[33m¥¬\033[m:\n"); me = igetch(); me -= '1'; - if(me > 2 || me < 0) + if (me > 2 || me < 0) me = 0; - win = (int)(3.0 * rand()/(RAND_MAX + 1.0)) - 1; - ch = (me + win + 3)%3; + win = (int)(3.0 * rand() / (RAND_MAX + 1.0)) - 1; + ch = (me + win + 3) % 3; prints("%s:%s ! %s:%s !.....%s", cuser.userid, guess[(int)me], mychicken->name, guess[(int)ch], - win==0 ? "¥¤â" : win < 0 ? "C..ŤF :D!!" : "¶ã..§Ú¿é¤F :~"); + win == 0 ? "¥¤â" : win < 0 ? "C..ŤF :D!!" : "¶ã..§Ú¿é¤F :~"); pressanykey(); } -static void ch_book() { +static void +ch_book() +{ mychicken->book += time_change[(int)mychicken->type][BOOK]; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; show_file(CHICKEN_PIC "/read", 5, 14, NO_RELOAD); pressanykey(); } -static void ch_kiss() { +static void +ch_kiss() +{ mychicken->happy += time_change[(int)mychicken->type][HAPPY]; mychicken->satis += time_change[(int)mychicken->type][SATIS]; mychicken->tiredstrong += @@ -324,289 +345,307 @@ static void ch_kiss() { pressanykey(); } -static void ch_hit() { +static void +ch_hit() +{ mychicken->attack += time_change[(int)mychicken->type][ATTACK]; mychicken->run += time_change[(int)mychicken->type][RUN]; - mychicken->mm_max += time_change[(int)mychicken->type][MM_MAX]/15; - mychicken->weight -= mychicken->hp_max / 15 ; + mychicken->mm_max += time_change[(int)mychicken->type][MM_MAX] / 15; + mychicken->weight -= mychicken->hp_max / 15; mychicken->hp -= (int)((float)time_change[(int)mychicken->type][HP_MAX] * - rand()/(RAND_MAX+1.0)) / 2 + 1; - - if(mychicken->book > 2) + rand() / (RAND_MAX + 1.0)) / 2 + 1; + + if (mychicken->book > 2) mychicken->book -= 2; - if(mychicken->happy > 2) + if (mychicken->happy > 2) mychicken->happy -= 2; - if(mychicken->satis > 2) + if (mychicken->satis > 2) mychicken->satis -= 2; mychicken->tiredstrong += time_change[(int)mychicken->type][TIREDSTRONG]; show_file(CHICKEN_PIC "/hit", 5, 14, NO_RELOAD); pressanykey(); } -void ch_buyitem(int money, char *picture, int *item) { - int num = 0; - char buf[5]; - +void +ch_buyitem(int money, char *picture, int *item) +{ + int num = 0; + char buf[5]; + getdata_str(b_lines - 1, 0, "n¶R¦h¤Ö¥÷©O:", buf, sizeof(buf), DOECHO, "1"); num = atoi(buf); - if(num < 1) + if (num < 1) return; reload_money(); - if(cuser.money > money*num) { + if (cuser.money > money * num) { *item += num; - vice(money*num,"ÁʶRÃdª«,½ä½L¶µ¥Ø"); + vice(money * num, "ÁʶRÃdª«,½ä½L¶µ¥Ø"); show_file(picture, 5, 14, NO_RELOAD); } else { - move(b_lines-1,0); + move(b_lines - 1, 0); clrtoeol(); outs("²{ª÷¤£°÷ !!!"); } pressanykey(); } -static void ch_eatoo() { - if(mychicken->oo > 0) { +static void +ch_eatoo() +{ + if (mychicken->oo > 0) { mychicken->oo--; mychicken->tiredstrong = 0; - if(mychicken->happy > 5) + if (mychicken->happy > 5) mychicken->happy -= 5; show_file(CHICKEN_PIC "/oo", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_eatmedicine() { - if(mychicken->medicine > 0) { +static void +ch_eatmedicine() +{ + if (mychicken->medicine > 0) { mychicken->medicine--; mychicken->sick = 0; - if(mychicken->hp_max > 10) + if (mychicken->hp_max > 10) mychicken->hp_max -= 3; mychicken->hp = mychicken->hp_max; - if(mychicken->happy>10) + if (mychicken->happy > 10) mychicken->happy -= 10; show_file(CHICKEN_PIC "/medicine", 5, 14, NO_RELOAD); pressanykey(); } } -static void ch_kill() { - char buf[150],ans[4]; - +static void +ch_kill() +{ + char buf[150], ans[4]; + sprintf(buf, "±ó¾i³o%sn³Q»@ 100 ¤¸, ¬O§_n±ó¾i?(y/N)", chicken_type[(int)mychicken->type]); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if(ans[0] == 'y') { - - vice(100,"±ó¾iÃdª«¶O"); - more(CHICKEN_PIC "/deadth",YEA); + if (ans[0] == 'y') { + + vice(100, "±ó¾iÃdª«¶O"); + more(CHICKEN_PIC "/deadth", YEA); sprintf(buf, "\033[31m%s \033[m§â \033[33m%s\033[m\033[32m %s " "\033[m®_¤F ©ó %s", cuser.userid, - mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); log_file(CHICKENLOG, buf); - mychicken->name[0]=0; + mychicken->name[0] = 0; } } -static int ch_sell() { -/* - int money = (mychicken->weight - time_change[(int)mychicken->type][WEIGHT]) - *(food_price[(int)mychicken->type])/4 + - ( - + ((mychicken->clean / time_change[(int)mychicken->type][CLEAN]) - + (mychicken->run / time_change[(int)mychicken->type][RUN]) - + (mychicken->attack / time_change[(int)mychicken->type][ATTACK]) - + (mychicken->book / time_change[(int)mychicken->type][BOOK]) - + (mychicken->happy / time_change[(int)mychicken->type][HAPPY]) - + (mychicken->satis / time_change[(int)mychicken->type][SATIS]) - + (mychicken->temperament / time_change[(int)mychicken->type][TEMPERAMENT]) - - (mychicken->tiredstrong / time_change[(int)mychicken->type][TIREDSTRONG]) - - (mychicken->sick / time_change[(int)mychicken->type][SICK]) - + (mychicken->hp / time_change[(int)mychicken->type][HP_MAX]) - + (mychicken->mm / time_change[(int)mychicken->type][MM_MAX]) - + 7 - abs(age - 7)) * 3 - ; -*/ - int money = (age * food_price[(int)mychicken->type] * 3 - + (mychicken->hp_max * 10 + mychicken->weight) / - time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - - mychicken->sick; - char buf[150],ans[4]; - - if(money < 0) - money =0 ; - else if(money > MAX_CHICKEN_MONEY) - money = MAX_CHICKEN_MONEY; //¨¾¤î©ÇÂû - if(mychicken->type == 1 || mychicken->type == 7) { +static int +ch_sell() +{ + /* + * int money = (mychicken->weight - + * time_change[(int)mychicken->type][WEIGHT]) + * (food_price[(int)mychicken->type])/4 + ( + ((mychicken->clean / + * time_change[(int)mychicken->type][CLEAN]) + (mychicken->run / + * time_change[(int)mychicken->type][RUN]) + (mychicken->attack / + * time_change[(int)mychicken->type][ATTACK]) + (mychicken->book / + * time_change[(int)mychicken->type][BOOK]) + (mychicken->happy / + * time_change[(int)mychicken->type][HAPPY]) + (mychicken->satis / + * time_change[(int)mychicken->type][SATIS]) + (mychicken->temperament / + * time_change[(int)mychicken->type][TEMPERAMENT]) - + * (mychicken->tiredstrong / + * time_change[(int)mychicken->type][TIREDSTRONG]) - (mychicken->sick / + * time_change[(int)mychicken->type][SICK]) + (mychicken->hp / + * time_change[(int)mychicken->type][HP_MAX]) + (mychicken->mm / + * time_change[(int)mychicken->type][MM_MAX]) + 7 - abs(age - 7)) * 3 ; + */ + int money = (age * food_price[(int)mychicken->type] * 3 + + (mychicken->hp_max * 10 + mychicken->weight) / + time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - + mychicken->sick; + char buf[150], ans[4]; + + if (money < 0) + money = 0; + else if (money > MAX_CHICKEN_MONEY) + money = MAX_CHICKEN_MONEY; + //¨¾¤î©ÇÂû + if (mychicken->type == 1 || mychicken->type == 7) { outs("\n\033[31m £..¿Ë·Rªº..³c½æ¤H¤f¬O·|¥Çªkªºò..\033[m"); pressanykey(); return 0; } - if(age < 5) { + if (age < 5) { outs("\n ÁÙ¥¼¦¨¦~¤£¯à½æ"); pressanykey(); return 0; } - if(age > 30) { + if (age > 30) { outs("\n\033[31m ³o..¤Ó¦Ñ¨S¤Hn¤F\033[m"); pressanykey(); return 0; } - sprintf(buf, "³o°¦%d·³%s¥i¥H½æ %d ¤¸, ¬O§_n½æ?(y/N)", age, chicken_type[(int)mychicken->type], money); getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if(ans[0]=='y') { + if (ans[0] == 'y') { sprintf(buf, "\033[31m%s\033[m §â \033[33m%s\033[m " "\033[32m%s\033[m ¥Î \033[36m%d\033[m ½æ¤F ©ó %s", cuser.userid, mychicken->name, - chicken_type[(int)mychicken->type],money,ctime(&now)); + chicken_type[(int)mychicken->type], money, ctime(&now)); log_file(CHICKENLOG, buf); - mychicken->lastvisit = mychicken->name[0]=0; + mychicken->lastvisit = mychicken->name[0] = 0; passwd_update(usernum, &cuser); - more(CHICKEN_PIC "/sell",YEA); + more(CHICKEN_PIC "/sell", YEA); demoney(money); return 1; } return 0; } -static void geting_old(int *hp, int *weight, int diff, int age) { - float ex = 0.9; - - if(age > 70) +static void +geting_old(int *hp, int *weight, int diff, int age) +{ + float ex = 0.9; + + if (age > 70) ex = 0.1; - else if(age > 30) + else if (age > 30) ex = 0.5; - else if(age > 20) + else if (age > 20) ex = 0.7; - diff /= 60*6; - while(diff--) { + diff /= 60 * 6; + while (diff--) { *hp *= ex; *weight *= ex; } } /* ¨Ì®É¶¡Åܰʪº¸ê®Æ */ -void time_diff(chicken_t *thechicken) { - int diff; - int theage = ((now - thechicken->cbirth)/ (60 * 60 * 24)); - - thechicken->type %= NUM_KINDS ; - diff = (now-thechicken->lastvisit)/60; - - if((diff) < 1) +void +time_diff(chicken_t * thechicken) +{ + int diff; + int theage = ((now - thechicken->cbirth) / (60 * 60 * 24)); + + thechicken->type %= NUM_KINDS; + diff = (now - thechicken->lastvisit) / 60; + + if ((diff) < 1) return; - if(theage > 13 ) /* ¦Ñ¦º */ + if (theage > 13) /* ¦Ñ¦º */ geting_old(&thechicken->hp_max, &thechicken->weight, diff, age); - + thechicken->lastvisit = now; - thechicken->weight -= thechicken->hp_max * diff / 540; /* Åé« */ - if(thechicken->weight < 1) { - thechicken->sick -= thechicken->weight / 10; /* ¾j±o¯f®ð¤W¤É */ - thechicken->weight =1; + thechicken->weight -= thechicken->hp_max * diff / 540; /* Åé« */ + if (thechicken->weight < 1) { + thechicken->sick -= thechicken->weight / 10; /* ¾j±o¯f®ð¤W¤É */ + thechicken->weight = 1; } - - /* ²M¼ä«× */ + /* ²M¼ä«× */ thechicken->clean += diff * time_change[(int)thechicken->type][CLEAN] / 30; - + /* §Ö¼Ö«× */ thechicken->happy -= diff / 60; - if(thechicken->happy < 0) - thechicken->happy=0; + if (thechicken->happy < 0) + thechicken->happy = 0; thechicken->attack -= time_change[(int)thechicken->type][ATTACK] * diff / (60 * 32); - if(thechicken->attack < 0) + if (thechicken->attack < 0) thechicken->attack = 0; /* §ðÀ»¤O */ thechicken->run -= time_change[(int)thechicken->type][RUN] * diff / (60 * 32); /* ±Ó±¶ */ - if(thechicken->run < 0) + if (thechicken->run < 0) thechicken->run = 0; - thechicken->book -= time_change[(int)thechicken->type][BOOK]*diff/ (60*32); + thechicken->book -= time_change[(int)thechicken->type][BOOK] * diff / (60 * 32); /* ª¾ÃÑ */ - if(thechicken->book < 0) + if (thechicken->book < 0) thechicken->book = 0; /* ®ð½è */ thechicken->temperament++; - + thechicken->satis -= diff / 60 / 3 * time_change[(int)thechicken->type][SATIS]; /* º¡·N«× */ - if(thechicken->satis < 0) + if (thechicken->satis < 0) thechicken->satis = 0; /* ż¯fªº */ - if(mychicken->clean > 1000) - mychicken->sick += (mychicken->clean - 400) / 10; + if (mychicken->clean > 1000) + mychicken->sick += (mychicken->clean - 400) / 10; - if(thechicken->weight > 1) + if (thechicken->weight > 1) thechicken->sick -= diff / 60; /* ¯f®ð«ìÅ@ */ - if(thechicken->sick < 0) + if (thechicken->sick < 0) thechicken->sick = 0; thechicken->tiredstrong -= diff * time_change[(int)thechicken->type][TIREDSTRONG] / 4; /* ¯h³Ò */ - if(thechicken->tiredstrong < 0) + if (thechicken->tiredstrong < 0) thechicken->tiredstrong = 0; /* hp_max */ - if(thechicken->hp >= thechicken->hp_max/2) + if (thechicken->hp >= thechicken->hp_max / 2) thechicken->hp_max += - time_change[(int)thechicken->type][HP_MAX]*diff/ (60*12); + time_change[(int)thechicken->type][HP_MAX] * diff / (60 * 12); /* hp«ìÅ@ */ - if(!thechicken->sick) + if (!thechicken->sick) thechicken->hp += - time_change[(int)thechicken->type][HP_MAX]*diff/ (60*6); - if(thechicken->hp>thechicken->hp_max) + time_change[(int)thechicken->type][HP_MAX] * diff / (60 * 6); + if (thechicken->hp > thechicken->hp_max) thechicken->hp = thechicken->hp_max; /* mm_max */ - if(thechicken->mm >= thechicken->mm_max/2) + if (thechicken->mm >= thechicken->mm_max / 2) thechicken->mm_max += - time_change[(int)thechicken->type][MM_MAX]*diff/ (60*8); + time_change[(int)thechicken->type][MM_MAX] * diff / (60 * 8); /* mm«ìÅ@ */ - if(!thechicken->sick) + if (!thechicken->sick) thechicken->mm += diff; - if(thechicken->mm>thechicken->mm_max) + if (thechicken->mm > thechicken->mm_max) thechicken->mm = thechicken->mm_max; } -static void check_sick() { +static void +check_sick() +{ /* ż¯fªº */ - if(mychicken->tiredstrong > mychicken->hp * 0.3 && mychicken->clean > 150) - mychicken->sick += (mychicken->clean - 150) / 10; + if (mychicken->tiredstrong > mychicken->hp * 0.3 && mychicken->clean > 150) + mychicken->sick += (mychicken->clean - 150) / 10; /* ²Ö¯fªº */ - if(mychicken->tiredstrong > mychicken->hp*1.3) - mychicken->sick += time_change[(int)mychicken->type][SICK]; + if (mychicken->tiredstrong > mychicken->hp * 1.3) + mychicken->sick += time_change[(int)mychicken->type][SICK]; /* ¯f®ð¤Ó«ÁÙ°µ¨Æ´îhp */ - if(mychicken->sick > mychicken->hp / 5) { - mychicken->hp -= (mychicken->sick - mychicken->hp / 5)/4; - if(mychicken->hp < 0 ) + if (mychicken->sick > mychicken->hp / 5) { + mychicken->hp -= (mychicken->sick - mychicken->hp / 5) / 4; + if (mychicken->hp < 0) mychicken->hp = 0; } } -static int deadtype(chicken_t *thechicken) { - int i; - char buf[150]; - - if(thechicken->hp <= 0) /* hp¥ÎºÉ */ +static int +deadtype(chicken_t * thechicken) +{ + int i; + char buf[150]; + + if (thechicken->hp <= 0) /* hp¥ÎºÉ */ i = 1; - else if(thechicken->tiredstrong > thechicken->hp * 3 ) /* ¾Þ³Ò¹L«× */ + else if (thechicken->tiredstrong > thechicken->hp * 3) /* ¾Þ³Ò¹L«× */ i = 2; - else if(thechicken->weight > thechicken->hp_max*5) /* ªÎD¹L«× */ + else if (thechicken->weight > thechicken->hp_max * 5) /* ªÎD¹L«× */ i = 3; - else if(thechicken->weight == 1 && - thechicken->sick > thechicken->hp_max / 4) - i = 4; /* ¾j¦º¤F */ - else if(thechicken->satis <= 0) /* «Ü¤£º¡·N */ + else if (thechicken->weight == 1 && + thechicken->sick > thechicken->hp_max / 4) + i = 4; /* ¾j¦º¤F */ + else if (thechicken->satis <= 0) /* «Ü¤£º¡·N */ i = 5; else return 0; - if(thechicken == mychicken) { - sprintf(buf,"\033[31m%s\033[m ©Ò¯k·Rªº\033[33m %s\033[32m %s " + if (thechicken == mychicken) { + sprintf(buf, "\033[31m%s\033[m ©Ò¯k·Rªº\033[33m %s\033[32m %s " "\033[m±¾¤F ©ó %s", cuser.userid, thechicken->name, chicken_type[(int)thechicken->type], @@ -614,23 +653,25 @@ static int deadtype(chicken_t *thechicken) { log_file(CHICKENLOG, buf); mychicken->name[0] = 0; passwd_update(usernum, &cuser); - } + } return i; } -int showdeadth(int type) { - switch(type) { - case 1: - more(CHICKEN_PIC "/nohp",YEA); +int +showdeadth(int type) +{ + switch (type) { + case 1: + more(CHICKEN_PIC "/nohp", YEA); break; case 2: - more(CHICKEN_PIC "/tootired",YEA); + more(CHICKEN_PIC "/tootired", YEA); break; case 3: - more(CHICKEN_PIC "/toofat",YEA); + more(CHICKEN_PIC "/toofat", YEA); break; case 4: - more(CHICKEN_PIC "/nofood",YEA); + more(CHICKEN_PIC "/nofood", YEA); break; case 5: more(CHICKEN_PIC "/nosatis", YEA); @@ -638,40 +679,46 @@ int showdeadth(int type) { default: return 0; } - more(CHICKEN_PIC "/deadth",YEA); + more(CHICKEN_PIC "/deadth", YEA); return type; } -int isdeadth(chicken_t *thechicken) { - int i; - - if(!(i = deadtype(thechicken))) +int +isdeadth(chicken_t * thechicken) +{ + int i; + + if (!(i = deadtype(thechicken))) return 0; return showdeadth(i); } -static void ch_changename() { - char buf[150], newname[20] = ""; - +static void +ch_changename() +{ + char buf[150], newname[20] = ""; + getdata_str(b_lines - 1, 0, "¶â..§ïÓ¦n¦W¦r§a:", newname, 18, DOECHO, - mychicken->name); - - if(strlen(newname) >= 3 && strcmp(newname,mychicken->name)) { + mychicken->name); + + if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { sprintf(buf, "\033[31m%s\033[m §â¯k·Rªº\033[33m %s\033[32m %s " "\033[m§ï¦W¬°\033[33m %s\033[m ©ó %s", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], newname, ctime(&now)); strcpy(mychicken->name, newname); - log_file(CHICKENLOG,buf); + log_file(CHICKENLOG, buf); } } -static int select_menu() { - char ch; - +static int +select_menu() +{ + char ch; + reload_money(); - move(19,0); + move(19, 0); prints("\033[44;37m ¿ú :\033[33m %-10d " " \033[m\n" "\033[33m(\033[37m1\033[33m)²M²z (\033[37m2\033[33m)¦Y¶º " @@ -683,13 +730,15 @@ static int select_menu() { "(\033[37ms\033[33m)½æ±¼ (\033[37mn\033[33m)§ï¦W " "(\033[37mq\033[33m)Â÷¶}:\033[m", cuser.money, - /*chicken_food[(int)mychicken->type], - chicken_type[(int)mychicken->type], - chicken_type[(int)mychicken->type],*/ + /* + * chicken_food[(int)mychicken->type], + * chicken_type[(int)mychicken->type], + * chicken_type[(int)mychicken->type], + */ chicken_food[(int)mychicken->type], food_price[(int)mychicken->type]); do { - switch(ch = igetch()) { + switch (ch = igetch()) { case '1': ch_clean(); check_sick(); @@ -741,21 +790,23 @@ static int select_menu() { return 0; case 'S': case 's': - if(!ch_sell()) break; + if (!ch_sell()) + break; case 'Q': case 'q': return 0; - } - } while(ch < ' ' || ch>'z'); + } + } while (ch < ' ' || ch > 'z'); return 1; } -static int recover_chicken(chicken_t *thechicken) { - char buf[200]; - int price = egg_price[(int)thechicken->type], - money = price + (rand() % price); - - if(now - thechicken->lastvisit > (60 * 60 * 24 * 7)) +static int +recover_chicken(chicken_t * thechicken) +{ + char buf[200]; + int price = egg_price[(int)thechicken->type], money = price + (rand() % price); + + if (now - thechicken->lastvisit > (60 * 60 * 24 * 7)) return 0; outmsg("\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m §O®`©È §Ú¬O¨ÓÀ°§Aªº \033[m"); bell(); @@ -765,31 +816,31 @@ static int recover_chicken(chicken_t *thechicken) { bell(); igetch(); sprintf(buf, "\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m " - "§A¦³¤@Ó訫¤£¤[ªº%sn©Û´«¦^¨Ó¶Ü? ¥un%d¤¸ò \033[m", - chicken_type[(int)thechicken->type], price*2); + "§A¦³¤@Ó訫¤£¤[ªº%sn©Û´«¦^¨Ó¶Ü? ¥un%d¤¸ò \033[m", + chicken_type[(int)thechicken->type], price * 2); outmsg(buf); bell(); getdata_str(21, 0, " ¿ï¾Ü¡G(N:§|¤H¹À/y:½ÐÀ°À°§Ú)", buf, 3, LCECHO, "N"); - if(buf[0] == 'y' || buf[0] == 'Y') { - reload_money(); - if(cuser.money < price*2) { + if (buf[0] == 'y' || buf[0] == 'Y') { + reload_money(); + if (cuser.money < price * 2) { outmsg("\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m ¤°»ò ¿ú¨S±a°÷ " "¨S¿úªº¤p° §Ö¥hÄw¿ú§a \033[m"); bell(); igetch(); return 0; - } - strcpy(thechicken->name, "[¾ß¦^¨Óªº]"); - thechicken->hp = thechicken->hp_max; - thechicken->sick = 0; - thechicken->satis = 2; - vice(money,"ÆF¬É¦u½Ã"); - sprintf(buf, "\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m OK¤F °O±oÁý¥LÂIªF¦è " + } + strcpy(thechicken->name, "[¾ß¦^¨Óªº]"); + thechicken->hp = thechicken->hp_max; + thechicken->sick = 0; + thechicken->satis = 2; + vice(money, "ÆF¬É¦u½Ã"); + sprintf(buf, "\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m OK¤F °O±oÁý¥LÂIªF¦è " "¤£µM¥i¯à¥¢®Ä ©À¦b§Ú¤]¦³ª±Ptt ®³§A%d´N¦n \033[m", money); - outmsg(buf); - bell(); - igetch(); - return 1; + outmsg(buf); + bell(); + igetch(); + return 1; } outmsg("\033[33;44m¡¹ÆF¬É¦u½Ã\033[37;45m ³ºµM»¡§Ú§|¤H! ³o¦~ÀY©R¯u¤£È¿ú " "°£«D§Ú¦A¨Ó§ä§A §A¦A¤]¨S¾÷·|¤F \033[m"); @@ -802,46 +853,50 @@ static int recover_chicken(chicken_t *thechicken) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int chicken_main() { +int +chicken_main() +{ lockreturn0(CHICKEN, LOCK_MULTI); - + reload_chicken(); - age = ((now - mychicken->cbirth)/ (60*60*24)); - if(!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { + age = ((now - mychicken->cbirth) / (60 * 60 * 24)); + if (!mychicken->name[0] && !recover_chicken(mychicken) && !new_chicken()) { unlockutmpmode(); return 0; } - do { time_diff(mychicken); - if(isdeadth(mychicken)) + if (isdeadth(mychicken)) break; show_chicken_data(mychicken, NULL); - } while(select_menu()); + } while (select_menu()); reload_money(); passwd_update(usernum, &cuser); unlockutmpmode(); return 0; } -int chickenpk(int fd) { - char mateid[IDLEN + 1], data[200], buf[200]; - int ch = 0; +int +chickenpk(int fd) +{ + char mateid[IDLEN + 1], data[200], buf[200]; + int ch = 0; - userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; - userec_t ouser; - chicken_t *ochicken = &ouser.mychicken; - int r, attmax, i, datac, duid = currutmp->destuid, catched=0, count=0; + userinfo_t *uin = &SHM->uinfo[currutmp->destuip]; + userec_t ouser; + chicken_t *ochicken = &ouser.mychicken; + int r, attmax, i, datac, duid = currutmp->destuid, catched = 0, + count = 0; lockreturn0(CHICKEN, LOCK_MULTI); - - strcpy(mateid, currutmp->mateid); /*§â¹ï¤âªºid¥Îlocal buffer°O¦í*/ - - getuser(mateid) ; + + strcpy(mateid, currutmp->mateid); /* §â¹ï¤âªºid¥Îlocal buffer°O¦í */ + + getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); - if(!ochicken->name[0] || !mychicken->name[0]) { - outmsg("¦³¤@¤è¨S¦³Ãdª«"); /* Ptt:§«¤îpage®É§âÃdª«½æ±¼ */ + if (!ochicken->name[0] || !mychicken->name[0]) { + outmsg("¦³¤@¤è¨S¦³Ãdª«"); /* Ptt:§«¤îpage®É§âÃdª«½æ±¼ */ bell(); refresh(); add_io(0, 0); @@ -850,114 +905,113 @@ int chickenpk(int fd) { sleep(1); return 0; } - show_chicken_data(ochicken, mychicken); - add_io(fd, 3); /* §âfd¥[¨ìigetchºÊµø */ - while(1) { + add_io(fd, 3); /* §âfd¥[¨ìigetchºÊµø */ + while (1) { r = rand(); ch = igetkey(); - getuser(mateid) ; + getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); - show_chicken_data(ochicken, mychicken); + show_chicken_data(ochicken, mychicken); time_diff(mychicken); - - i = mychicken->attack* mychicken->hp / mychicken->hp_max; - for(attmax=2; (i = i*9/10); attmax++); - if(ch == I_OTHERDATA) { - count =0; + i = mychicken->attack * mychicken->hp / mychicken->hp_max; + for (attmax = 2; (i = i * 9 / 10); attmax++); + + if (ch == I_OTHERDATA) { + count = 0; datac = recv(fd, data, sizeof(data), 0); - if(datac <= 1) + if (datac <= 1) break; - move(17,0); - outs(data+1); - switch(data[0]) { + move(17, 0); + outs(data + 1); + switch (data[0]) { case 'c': - catched=1; - move(16,0); + catched = 1; + move(16, 0); outs("n©ñ¥L¨«¶Ü?(y/N)"); break; case 'd': - move(16,0); + move(16, 0); outs("ªü~ˤU¤F!!"); break; } - if(data[0] == 'd' || data[0]=='q' || data[0]=='l') + if (data[0] == 'd' || data[0] == 'q' || data[0] == 'l') break; continue; - } else if(currutmp->turn) { + } else if (currutmp->turn) { count = 0; currutmp->turn = 0; uin->turn = 1; - mychicken->tiredstrong ++; - switch(ch) { + mychicken->tiredstrong++; + switch (ch) { case 'y': - if(catched == 1) { + if (catched == 1) { sprintf(data, "lÅý %s ¸¨¶]¤F\n", ochicken->name); } - break; + break; case 'n': - catched =0; + catched = 0; default: case 'k': - r = r % (attmax + 2); - if(r) { + r = r % (attmax + 2); + if (r) { sprintf(data, "M%s %s%s %s ¶Ë¤F %d ÂI\n", mychicken->name, - damage_degree[r/3>15 ? 15:r/3], + damage_degree[r / 3 > 15 ? 15 : r / 3], attack_type[(int)mychicken->type], ochicken->name, r); - ochicken->hp-=r; + ochicken->hp -= r; } else sprintf(data, "M%s ı±o¤â³n¥XÀ»µL®Ä\n", mychicken->name); - break; + break; case 'o': - if(mychicken->oo > 0) { + if (mychicken->oo > 0) { mychicken->oo--; mychicken->hp += 300; - if(mychicken->hp > mychicken->hp_max) - mychicken->hp = mychicken->hp_max; + if (mychicken->hp > mychicken->hp_max) + mychicken->hp = mychicken->hp_max; mychicken->tiredstrong = 0; sprintf(data, "M%s ¦Y¤FÁû¤j¸É¤Y¸É¥RÅé¤O\n", mychicken->name); - } else + } else sprintf(data, "M%s ·Q¦Y¤j¸É¤Y, ¥i¬O¨S¦³¤j¸É¤Y¥i¦Y\n", mychicken->name); - break; + break; case 'q': - if(r % (mychicken->run+1) > r % (ochicken->run+1)) + if (r % (mychicken->run + 1) > r % (ochicken->run + 1)) sprintf(data, "q%s ¸¨¶]¤F\n", mychicken->name); - else + else sprintf(data, "c%s ·Q¸¨¶], ¦ý³Q %s §ì¨ì¤F\n", mychicken->name, ochicken->name); - break; + break; } - if(deadtype(ochicken)) { - strtok(data,"\n"); + if (deadtype(ochicken)) { + strtok(data, "\n"); strcpy(buf, data); - sprintf(data, "d%s , %s ³Q %s ¥´¦º¤F\n", - buf + 1, ochicken->name, mychicken->name); + sprintf(data, "d%s , %s ³Q %s ¥´¦º¤F\n", + buf + 1, ochicken->name, mychicken->name); } - move(17,0); - outs(data+1); - i = strlen(data) +1; + move(17, 0); + outs(data + 1); + i = strlen(data) + 1; passwd_update(duid, &ouser); passwd_update(usernum, &cuser); - send(fd, data, i, 0); - if(data[0]=='q' || data[0]=='d') + send(fd, data, i, 0); + if (data[0] == 'q' || data[0] == 'd') break; } else { move(17, 0); - if(count++ > 30) + if (count++ > 30) break; } } - add_io(0, 0); /* §âigetch«ìÅ@¦^ */ + add_io(0, 0); /* §âigetch«ìÅ@¦^ */ pressanykey(); close(fd); - if(!showdeadth(deadtype(mychicken))); + if (!showdeadth(deadtype(mychicken))); unlockutmpmode(); return 0; } diff --git a/mbbsd/dark.c b/mbbsd/dark.c index 9cf99aab..19e17444 100644 --- a/mbbsd/dark.c +++ b/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.4 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: dark.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define RED 1 @@ -6,439 +6,550 @@ typedef short int sint; typedef struct item { - short int color,value,die,out; -} item; + short int color, value, die, out; +} item; -typedef struct cur{ - short int y,x,end; -} cur; +typedef struct cur { + short int y, x, end; +} cur; -static item brd[4][8]; -static cur curr; /* 6 Ó bytes */ +static item brd[4][8]; +static cur curr; /* 6 Ó bytes */ -static char *rname[]={"§L","¬¶","ØX","¨®","¬Û","¥K","«Ó"}; -static char *bname[]={"¨ò","¥]","°¨","¨®","¶H","¤h","±N"}; +static char *rname[] = {"§L", "¬¶", "ØX", "¨®", "¬Û", "¥K", "«Ó"}; +static char *bname[] = {"¨ò", "¥]", "°¨", "¨®", "¶H", "¤h", "±N"}; -static sint cury[]={3,5,7,9}, curx[]={5,9,13,17,21,25,29,33}; -static sint rcount,bcount,cont,fix; /* cont:¬O§_¥i³s¦Y */ -static sint my=0,mx=0,mly=-1,mlx=-1; /* ²¾°Êªº®y¼Ð ¸ò ¿ï¤lªº®y¼Ð */ +static sint cury[] = {3, 5, 7, 9}, curx[] = {5, 9, 13, 17, 21, 25, 29, 33}; +static sint rcount, bcount, cont, fix; /* cont:¬O§_¥i³s¦Y */ +static sint my = 0, mx = 0, mly = -1, mlx = -1; /* ²¾°Êªº®y¼Ð + * ¼Ð */ -static sint cur_eaty,cur_eatx; /* ¦Y±¼¹ï¤è¨ä¤lªº¨q¥X®y¼Ð */ -static void brdswap(sint y,sint x,sint ly,sint lx) { - memcpy(&brd[y][x],&brd[ly][lx],sizeof(item)); - brd[ly][lx].die=1; - brd[ly][lx].color=-1; /* ¨S³oÓcolor */ - brd[ly][lx].value=-1; +static sint cur_eaty, cur_eatx; /* ¦Y±¼¹ï¤è¨ä¤lªº¨q¥X®y¼Ð */ +static void +brdswap(sint y, sint x, sint ly, sint lx) +{ + memcpy(&brd[y][x], &brd[ly][lx], sizeof(item)); + brd[ly][lx].die = 1; + brd[ly][lx].color = -1; /* ¨S³oÓcolor */ + brd[ly][lx].value = -1; } -static void pprints(sint y,sint x,char* s) { - move(y,x); +static void +pprints(sint y, sint x, char *s) +{ + move(y, x); clrtoeol(); - prints("%s",s); + prints("%s", s); } -static sint Is_win(item att, item det, sint y, sint x, sint ly, sint lx) { - sint i,c=0,min,max; - if(att.value == 1) /* ¯¥ */ - { - if(y!=ly && x!=lx) return 0; - if((abs(ly-y)==1 && brd[y][x].die==0)|| - (abs(lx-x)==1 && brd[y][x].die==0)) +static sint +Is_win(item att, item det, sint y, sint x, sint ly, sint lx) +{ + sint i, c = 0, min, max; + if (att.value == 1) { /* ¯¥ */ + if (y != ly && x != lx) return 0; - if(y==ly){ - if(x>lx) {max=x;min=lx;} - else {max=lx;min=x;} - for(i=min+1;i<max;i++) - if(brd[y][i].die==0) c++; - }else if(x==lx){ - if(y>ly) {max=y;min=ly;} - else {max=ly;min=y;} - for(i=min+1;i<max;i++) - if(brd[i][x].die==0) c++; + if ((abs(ly - y) == 1 && brd[y][x].die == 0) || + (abs(lx - x) == 1 && brd[y][x].die == 0)) + return 0; + if (y == ly) { + if (x > lx) { + max = x; + min = lx; + } else { + max = lx; + min = x; + } + for (i = min + 1; i < max; i++) + if (brd[y][i].die == 0) + c++; + } else if (x == lx) { + if (y > ly) { + max = y; + min = ly; + } else { + max = ly; + min = y; + } + for (i = min + 1; i < max; i++) + if (brd[i][x].die == 0) + c++; } - if(c != 1) return 0; - if(det.die == 1) return 0; + if (c != 1) + return 0; + if (det.die == 1) + return 0; return 1; } /* «D¯¥ */ - if( ((abs(ly-y)==1&&x==lx) || (abs(lx-x)==1&&ly==y)) && brd[y][x].out==1 ) - { - if(att.value == 0 && det.value == 6) return 1; - else if(att.value == 6 && det.value == 0) return 0; - else if(att.value >= det.value) return 1; - else return 0; + if (((abs(ly - y) == 1 && x == lx) || (abs(lx - x) == 1 && ly == y)) && brd[y][x].out == 1) { + if (att.value == 0 && det.value == 6) + return 1; + else if (att.value == 6 && det.value == 0) + return 0; + else if (att.value >= det.value) + return 1; + else + return 0; } return 0; } -static sint Is_move(sint y,sint x, sint ly, sint lx) { - if(brd[y][x].die==1 && ((abs(ly-y)==1&&x==lx) || (abs(lx-x)==1&&ly==y))) +static sint +Is_move(sint y, sint x, sint ly, sint lx) +{ + if (brd[y][x].die == 1 && ((abs(ly - y) == 1 && x == lx) || (abs(lx - x) == 1 && ly == y))) return 1; return 0; } -static void brd_rand() { - sint y,x,index; - sint tem[32]; - sint value[32]={0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6, - 0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6}; +static void +brd_rand() +{ + sint y, x, index; + sint tem[32]; + sint value[32] = {0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, + 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6}; bzero(brd, sizeof(brd)); bzero(tem, sizeof(tem)); bzero(&curr, sizeof(curr)); - srand(getpid()%2731+now%3219); - for(y=0;y<4;y++) - for(x=0;x<8;x++) - while(1) { - index=rand()%32; - if(tem[index]) continue; - brd[y][x].color=(index>15)?0:1; - brd[y][x].value=value[index]; - tem[index]=1; + srand(getpid() % 2731 + now % 3219); + for (y = 0; y < 4; y++) + for (x = 0; x < 8; x++) + while (1) { + index = rand() % 32; + if (tem[index]) + continue; + brd[y][x].color = (index > 15) ? 0 : 1; + brd[y][x].value = value[index]; + tem[index] = 1; break; } } -static void brd_prints() { +static void +brd_prints() +{ clear(); - move(1,0); + move(1, 0); outs("\n" -" [43;30m¢~¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢¡[m\n" -" [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" -" [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" -" [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" -" [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" -" [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" -" [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" -" [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" -" [43;30m¢¢¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢£[m\n" -" "); + " [43;30m¢~¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢¡[m\n" + " [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" + " [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" + " [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" + " [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" + " [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" + " [43;30m¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t[m\n" + " [43;30m¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x¡´¢x[m\n" + " [43;30m¢¢¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢r¢w¢£[m\n" + " "); } -static void draw_line(sint y, sint f) { - sint i; - char buf[1024],tmp[256]; +static void +draw_line(sint y, sint f) +{ + sint i; + char buf[1024], tmp[256]; *buf = 0; *tmp = 0; - strcpy(buf,"\033[43;30m"); - for(i=0; i<8; i++) - { - if(brd[y][i].die==1) - sprintf(tmp,"¢x "); - else if(brd[y][i].out==0) - sprintf(tmp,"¢x¡´"); + strcpy(buf, "\033[43;30m"); + for (i = 0; i < 8; i++) { + if (brd[y][i].die == 1) + sprintf(tmp, "¢x "); + else if (brd[y][i].out == 0) + sprintf(tmp, "¢x¡´"); else { sprintf(tmp, "¢x\033[%s1;%dm%s\033[m\033[43;30m", - (f==i)?"1;47;":"",(brd[y][i].color)?31:34, - (brd[y][i].color)?rname[brd[y][i].value]: + (f == i) ? "1;47;" : "", (brd[y][i].color) ? 31 : 34, + (brd[y][i].color) ? rname[brd[y][i].value] : bname[brd[y][i].value]); } - strcat(buf,tmp); + strcat(buf, tmp); } - strcat(buf,"¢x\033[m"); + strcat(buf, "¢x\033[m"); - move(cury[y],3); + move(cury[y], 3); clrtoeol(); - prints("%s",buf); + prints("%s", buf); } -static void redraw() { - sint i=0; - for(;i<4;i++) - draw_line(i,-1); +static void +redraw() +{ + sint i = 0; + for (; i < 4; i++) + draw_line(i, -1); } -static sint playing(sint fd, sint color,sint ch,sint *b, userinfo_t *uin) { +static sint +playing(sint fd, sint color, sint ch, sint * b, userinfo_t * uin) +{ curr.end = 0; - move(cury[my],curx[mx]); + move(cury[my], curx[mx]); - if(fix) { - if(ch=='s') { - fix=0; *b=0; return 0; + if (fix) { + if (ch == 's') { + fix = 0; + *b = 0; + return 0; } else { - draw_line(mly,-1); + draw_line(mly, -1); } } - - switch(ch) { + switch (ch) { case KEY_LEFT: - if(mx == 0) mx=7; - else mx--; - move(cury[my],curx[mx]); - *b=-1; + if (mx == 0) + mx = 7; + else + mx--; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_RIGHT: - if(mx==7) mx=0; - else mx++; - move(cury[my],curx[mx]); - *b=-1; + if (mx == 7) + mx = 0; + else + mx++; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_UP: - if(my==0) my=3; - else my--; - move(cury[my],curx[mx]); - *b=-1; + if (my == 0) + my = 3; + else + my--; + move(cury[my], curx[mx]); + *b = -1; break; case KEY_DOWN: - if(my==3) my=0; - else my++; - move(cury[my],curx[mx]); - *b=-1; + if (my == 3) + my = 0; + else + my++; + move(cury[my], curx[mx]); + *b = -1; break; - case 'q':case 'Q': - if(!color) bcount=0; - else rcount=0; - *b=0; + case 'q': + case 'Q': + if (!color) + bcount = 0; + else + rcount = 0; + *b = 0; return -2; - case 'p':case 'P': + case 'p': + case 'P': return -3; case 'c': return -4; case 'g': return -5; - case 's': /* ½¶}´Ñ¤l ©Î¬O¿ï¾Ü´Ñ¤l */ + case 's': /* ½¶}´Ñ¤l ©Î¬O¿ï¾Ü´Ñ¤l */ /* ¿ï¾Ü´Ñ¤l */ - if(brd[my][mx].out==1) - { - if(brd[my][mx].color != color) - { - *b=-1; + if (brd[my][mx].out == 1) { + if (brd[my][mx].color != color) { + *b = -1; break; } - if(mly<0) /*¥i¥H¿ï¾Ü*/ - { - mly=my;mlx=mx; - draw_line(my,mx); - *b=-1; + if (mly < 0) { /* ¥i¥H¿ï¾Ü */ + mly = my; + mlx = mx; + draw_line(my, mx); + *b = -1; break; + } else if (mly == my && mlx == mx) { /* ¤£¿ï¤F */ + mly = -1; + mlx = -1; + draw_line(my, -1); + } else { + draw_line(mly, -1); + mly = my; + mlx = mx; + if (brd[mly][mlx].value == 1) + fix = 1; + draw_line(my, mx); } - else if(mly == my && mlx == mx) /*¤£¿ï¤F*/ - { - mly=-1;mlx=-1; - draw_line(my,-1); - }else - { - draw_line(mly,-1); - mly=my;mlx=mx; - if(brd[mly][mlx].value == 1) fix=1; - draw_line(my,mx); - } - *b=-1; + *b = -1; break; } /* ½¶}´Ñ¤l */ - if(mly >=0 ){ *b=-1; break;} /*¥»¨Ó´N¬O½¶}ªº*/ + if (mly >= 0) { + *b = -1; + break; + } /* ¥»¨Ó´N¬O½¶}ªº */ /* ¨M©w¤@¶}©lªºÃC¦â */ - if(currutmp->color=='.'){ - if(uin->color!='1' && uin->color!='0') - currutmp->color=(brd[my][mx].color)?'1':'0'; + if (currutmp->color == '.') { + if (uin->color != '1' && uin->color != '0') + currutmp->color = (brd[my][mx].color) ? '1' : '0'; else - currutmp->color=(uin->color=='0')?'1':'0';} - brd[my][mx].out=1; - draw_line(my,-1); - move(cury[my],curx[mx]); - *b=0; + currutmp->color = (uin->color == '0') ? '1' : '0'; + } + brd[my][mx].out = 1; + draw_line(my, -1); + move(cury[my], curx[mx]); + *b = 0; break; case 'u': - move(0,0);clrtoeol(); - prints("%s¦â%s cont=%d",(brd[my][mx].color == RED)?"¬õ":"¶Â",rname[brd[my][mx].value],cont); - *b=-1; + move(0, 0); + clrtoeol(); + prints("%s¦â%s cont=%d", (brd[my][mx].color == RED) ? "¬õ" : "¶Â", rname[brd[my][mx].value], cont); + *b = -1; break; - case '\r': /* ¦Y or ²¾°Ê ly¸òlx¥²¶·¤j©ó0*/ + case '\r': /* ¦Y or ²¾°Ê ly¸òlx¥²¶·¤j©ó0 */ case '\n': - if( - mly >= 0 /* n¥ý¿ï¤l */ + if ( + mly >= 0 /* n¥ý¿ï¤l */ && - brd[mly][mlx].color != brd[my][mx].color /* ¦P¦â¤£¯à²¾°Ê¤]¤£¯à¦Y */ + brd[mly][mlx].color != brd[my][mx].color /* ¦P¦â¤£¯à²¾°Ê¤]¤£¯à¦Y */ && - (Is_move(my,mx,mly,mlx) || Is_win(brd[mly][mlx],brd[my][mx],my,mx,mly,mlx)) - ) - { - if(fix && brd[my][mx].value<0) - { - *b=-1;return 0; + (Is_move(my, mx, mly, mlx) || Is_win(brd[mly][mlx], brd[my][mx], my, mx, mly, mlx)) + ) { + if (fix && brd[my][mx].value < 0) { + *b = -1; + return 0; } - if(brd[my][mx].value>=0&&brd[my][mx].die==0) - { - if(!color) bcount--; - else rcount--; - move(cur_eaty,cur_eatx); - prints("%s",(color)?bname[brd[my][mx].value]:rname[brd[my][mx].value]); - if(cur_eatx>=26) - { cur_eatx=5;cur_eaty++; } + if (brd[my][mx].value >= 0 && brd[my][mx].die == 0) { + if (!color) + bcount--; else - cur_eatx+=3; + rcount--; + move(cur_eaty, cur_eatx); + prints("%s", (color) ? bname[brd[my][mx].value] : rname[brd[my][mx].value]); + if (cur_eatx >= 26) { + cur_eatx = 5; + cur_eaty++; + } else + cur_eatx += 3; } - brdswap(my,mx,mly,mlx); - draw_line(mly,-1); - draw_line( my,-1); - if(fix==1) *b=-1; - else { mly=-1;mlx=-1;*b=0; } - } - else *b=-1; + brdswap(my, mx, mly, mlx); + draw_line(mly, -1); + draw_line(my, -1); + if (fix == 1) + *b = -1; + else { + mly = -1; + mlx = -1; + *b = 0; + } + } else + *b = -1; break; default: - *b=-1; + *b = -1; } - - if(!rcount) + + if (!rcount) return -1; - else if(!bcount) + else if (!bcount) return -1; - if(*b == -1) return 0; - curr.y = my;curr.x = mx; curr.end=(!*b)?1:0; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(brd),0); + if (*b == -1) + return 0; + curr.y = my; + curr.x = mx; + curr.end = (!*b) ? 1 : 0; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(brd), 0); return 0; } -int main_dark(int fd,userinfo_t *uin) { - sint end=0,ch=1,go_on,i=0,cont=0; - char buf[16]; - *buf=0;fix=0; - currutmp->color='.'; // '.' ªí¥ÜÁÙ¨S¨M©wÃC¦â - rcount=16;bcount=16; // initialize - cur_eaty=18,cur_eatx=5; +int +main_dark(int fd, userinfo_t * uin) +{ + sint end = 0, ch = 1, go_on, i = 0, cont = 0; + char buf[16]; + *buf = 0; + fix = 0; + currutmp->color = '.'; + //'.' ª í¥ÜÁÙ¨S ¨ M © w à C ¦ â + rcount = 16; + bcount = 16; + //initialize + cur_eaty = 18, cur_eatx = 5; brd_prints(); - if(currutmp->turn) - { + if (currutmp->turn) { brd_rand(); - send(fd,&brd,sizeof(brd),0); - pprints(21,0," [1;37m[1;33m¡»[1;37m§A¬O¥ý¤â[m"); - pprints(22,0," [1;33m¡»[5;35m½ü¨ì§A¤U¤F[m"); - }else - { - recv(fd,&brd,sizeof(brd),0); - pprints(21,0," [1;33m¡»[1;37m§A¬O«á¤â[m"); + send(fd, &brd, sizeof(brd), 0); + pprints(21, 0, " [1;37m[1;33m¡»[1;37m§A¬O¥ý¤â[m"); + pprints(22, 0, " [1;33m¡»[5;35m½ü¨ì§A¤U¤F[m"); + } else { + recv(fd, &brd, sizeof(brd), 0); + pprints(21, 0, " [1;33m¡»[1;37m§A¬O«á¤â[m"); } - move(12,3); - prints("%s[0³Ó0±Ñ][5;31m¢þ¢û[1;37m.[m%s[0³Ó0±Ñ]",currutmp->userid,currutmp->mateid); + move(12, 3); + prints("%s[0³Ó0±Ñ][5;31m¢þ¢û[1;37m.[m%s[0³Ó0±Ñ]", currutmp->userid, currutmp->mateid); outs("\n" -" [1;36m¢®¢¬[1;31m¥\\¯àªí[1;36m¢¢®¢¢¬¢®¢[m\n" -" [1;36m¢¬[1;33m ¡ô¡ö¡õ¡÷[1;37m: [1;35m²¾°Ê[m\n" -" [1;36m¢®[1;33m ¢û[1;37m: [1;35m ¿ï¤l,½¤l[m\n" -" [1;36m¢¬[1;33m enter[1;37m: [1;35m ¦Y´Ñ,©ñ´Ñ[m\n" -"¡@[1;33m¤w¸g¸Ñ¨Mªº[1;37m:[1;36m¡@¡@ ¢®[1;33m ¢ø[1;37m: [1;35m ¦X´Ñ[m\n" -" ¡@¡@ [1;36m¢¬[1;33m ¢ù[1;37m: [1;35m »{¿é[m\n" -" [1;36m¢®[1;33m ¢ë[1;37m: [1;35m ´«Ãä[m"); + " [1;36m¢®¢¬[1;31m¥\\¯àªí[1;36m¢¢®¢¢¬¢®¢[m\n" + " [1;36m¢¬[1;33m ¡ô¡ö¡õ¡÷[1;37m: [1;35m²¾°Ê[m\n" + " [1;36m¢®[1;33m ¢û[1;37m: [1;35m ¿ï¤l,½¤l[m\n" + " [1;36m¢¬[1;33m enter[1;37m: [1;35m ¦Y´Ñ,©ñ´Ñ[m\n" + "¡@[1;33m¤w¸g¸Ñ¨Mªº[1;37m:[1;36m¡@¡@ ¢®[1;33m ¢ø[1;37m: [1;35m ¦X´Ñ[m\n" + " ¡@¡@ [1;36m¢¬[1;33m ¢ù[1;37m: [1;35m »{¿é[m\n" + " [1;36m¢®[1;33m ¢ë[1;37m: [1;35m ´«Ãä[m"); - if(currutmp->turn) move(cury[0],curx[0]); + if (currutmp->turn) + move(cury[0], curx[0]); add_io(fd, 0); - while(end<=0) - { - if(uin->turn=='w' || currutmp->turn=='w') { end=-1; break; } - + while (end <= 0) { + if (uin->turn == 'w' || currutmp->turn == 'w') { + end = -1; + break; + } ch = igetkey(); - if(ch == I_OTHERDATA) - { - ch=recv(fd,&curr,sizeof(curr),0); - if(ch!=sizeof(curr)) - { - if(uin->turn=='e') { end=-3;break; } - else if(uin->turn!='w') { end=-1; currutmp->turn='w'; break; } - end=-1; break; + if (ch == I_OTHERDATA) { + ch = recv(fd, &curr, sizeof(curr), 0); + if (ch != sizeof(curr)) { + if (uin->turn == 'e') { + end = -3; + break; + } else if (uin->turn != 'w') { + end = -1; + currutmp->turn = 'w'; + break; + } + end = -1; + break; } + if (curr.end == -3) + pprints(23, 30, "\033[33mn¨D¦X´Ñ\033[m"); + else if (curr.end == -4) + pprints(23, 30, "\033[33mn¨D´«Ãä\033[m"); + else if (curr.end == -5) + pprints(23, 30, "\033[33mn¨D³s¦Y\033[m"); + else + pprints(23, 30, ""); - if(curr.end==-3) pprints(23,30,"\033[33mn¨D¦X´Ñ\033[m"); - else if(curr.end==-4) pprints(23,30,"\033[33mn¨D´«Ãä\033[m"); - else if(curr.end==-5) pprints(23,30,"\033[33mn¨D³s¦Y\033[m"); - else pprints(23,30,""); - - recv(fd,&brd,sizeof(brd),0); - my=curr.y;mx=curr.x; + recv(fd, &brd, sizeof(brd), 0); + my = curr.y; + mx = curr.x; redraw(); - if(curr.end) - pprints(22,0," [1;33m¡»[5;35m½ü¨ì§A¤U¤F[m"); - move(cury[my],curx[mx]); - }else - { - if(currutmp->turn=='p') - { - if(ch=='y') { end=-3; currutmp->turn='e'; break; } - else { pprints(23,30,""); *buf=0; currutmp->turn=(uin->turn)?0:1; } - }else if(currutmp->turn=='c') - { - if(ch=='y') { currutmp->color=(currutmp->color=='1')?'0':'1'; - uin->color=(uin->color=='1')?'0':'1'; - pprints(21,0,(currutmp->color=='1')?" \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m":" \033[1;33m¡»[1;36m§A«ù¶Â¦â´Ñ\033[m"); + if (curr.end) + pprints(22, 0, " [1;33m¡»[5;35m½ü¨ì§A¤U¤F[m"); + move(cury[my], curx[mx]); + } else { + if (currutmp->turn == 'p') { + if (ch == 'y') { + end = -3; + currutmp->turn = 'e'; + break; + } else { + pprints(23, 30, ""); + *buf = 0; + currutmp->turn = (uin->turn) ? 0 : 1; } - else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } - }else if(currutmp->turn=='g') - { - if(ch=='y') { - cont=1; - pprints(21,0," \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m ¥i³s¦Y"); + } else if (currutmp->turn == 'c') { + if (ch == 'y') { + currutmp->color = (currutmp->color == '1') ? '0' : '1'; + uin->color = (uin->color == '1') ? '0' : '1'; + pprints(21, 0, (currutmp->color == '1') ? " \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m" : " \033[1;33m¡»[1;36m§A«ù¶Â¦â´Ñ\033[m"); + } else { + pprints(23, 30, ""); + currutmp->turn = (uin->turn) ? 0 : 1; + } + } else if (currutmp->turn == 'g') { + if (ch == 'y') { + cont = 1; + pprints(21, 0, " \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m ¥i³s¦Y"); + } else { + pprints(23, 30, ""); + currutmp->turn = (uin->turn) ? 0 : 1; } - else { pprints(23,30,""); currutmp->turn=(uin->turn)?0:1; } } + if (currutmp->turn == 1) { + if (uin->turn == 'g') { + cont = 1; + uin->turn = (currutmp->turn) ? 0 : 1; + pprints(21, 10, "¥i³s¦Y"); + } + end = playing(fd, currutmp->color - '0', ch, &go_on, uin); - if(currutmp->turn==1) - { - if(uin->turn=='g') { cont=1;uin->turn=(currutmp->turn)?0:1; pprints(21,10,"¥i³s¦Y"); } - end=playing(fd,currutmp->color-'0',ch,&go_on,uin); - - if(end == -1) { currutmp->turn='w';break; } - else if(end == -2) { uin->turn='w';break; } - else if(end == -3) { - uin->turn='p';curr.end=-3; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + if (end == -1) { + currutmp->turn = 'w'; + break; + } else if (end == -2) { + uin->turn = 'w'; + break; + } else if (end == -3) { + uin->turn = 'p'; + curr.end = -3; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; - } - else if(end == -4) { - if(currutmp->color!='1'&&currutmp->color!='0') + } else if (end == -4) { + if (currutmp->color != '1' && currutmp->color != '0') continue; - uin->turn='c';i=0;curr.end=-4; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + uin->turn = 'c'; + i = 0; + curr.end = -4; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; - } - else if(end == -5) { - uin->turn='g';curr.end=-5; - send(fd,&curr,sizeof(curr),0); - send(fd,&brd,sizeof(buf),0); + } else if (end == -5) { + uin->turn = 'g'; + curr.end = -5; + send(fd, &curr, sizeof(curr), 0); + send(fd, &brd, sizeof(buf), 0); continue; } - if(!i && currutmp->color=='1') - { pprints(21,0," \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m");i++;move(cury[my],curx[mx]); } - if(!i && currutmp->color=='0') - { pprints(21,0," \033[1;33m¡»[1;36m§A«ù¶Â¦â´Ñ\033[m");i++;move(cury[my],curx[mx]); } - - if(uin->turn == 'e') { end=-3; break; } - if(go_on < 0) continue; + if (!i && currutmp->color == '1') { + pprints(21, 0, " \033[1;33m¡»[1;31m§A«ù¬õ¦â´Ñ\033[m"); + i++; + move(cury[my], curx[mx]); + } + if (!i && currutmp->color == '0') { + pprints(21, 0, " \033[1;33m¡»[1;36m§A«ù¶Â¦â´Ñ\033[m"); + i++; + move(cury[my], curx[mx]); + } + if (uin->turn == 'e') { + end = -3; + break; + } + if (go_on < 0) + continue; - move(22,0);clrtoeol(); - prints(" [1;33m¡»[1;37m½ü¨ì%s¤U §O©È§O©È ¥LºâÔ£¦Ì[m",currutmp->mateid); + move(22, 0); + clrtoeol(); + prints(" [1;33m¡»[1;37m½ü¨ì%s¤U §O©È§O©È ¥LºâÔ£¦Ì[m", currutmp->mateid); currutmp->turn = 0; uin->turn = 1; - }else - { - if(ch == 'q'){uin->turn='w';break;} - move(22,0);clrtoeol(); - prints(" [1;33m¡»[1;37m½ü¨ì%s¤U §O©È§O©È ¥LºâÔ£¦Ì[m",currutmp->mateid); + } else { + if (ch == 'q') { + uin->turn = 'w'; + break; + } + move(22, 0); + clrtoeol(); + prints(" [1;33m¡»[1;37m½ü¨ì%s¤U §O©È§O©È ¥LºâÔ£¦Ì[m", currutmp->mateid); } } } - switch(end) - { + switch (end) { case -1: case -2: - if(currutmp->turn=='w'){ move(22,0);clrtoeol();prints("[1;31m§AŤF.. ¯u¬O®¥³ß~~[m");} - else {move(22,0);clrtoeol();prints("[1;31m¿é±¼¤F°Õ.....¤U¦¸Åý¥L¦n¬Ý!![m");} - break; + if (currutmp->turn == 'w') { + move(22, 0); + clrtoeol(); + prints("[1;31m§AŤF.. ¯u¬O®¥³ß~~[m"); + } else { + move(22, 0); + clrtoeol(); + prints("[1;31m¿é±¼¤F°Õ.....¤U¦¸Åý¥L¦n¬Ý!![m"); + } + break; case -3: - pprints(22,0,"[1;31m¦X´Ñò!! ¤U¦¸¦b¤À°ª¤U§a ^_^[m"); - break; + pprints(22, 0, "[1;31m¦X´Ñò!! ¤U¦¸¦b¤À°ª¤U§a ^_^[m"); + break; default: - add_io(0,0); - close(fd); - pressanykey(); - return 0; + add_io(0, 0); + close(fd); + pressanykey(); + return 0; } - add_io(0,0); + add_io(0, 0); close(fd); pressanykey(); return 0; diff --git a/mbbsd/descrypt.c b/mbbsd/descrypt.c index 1d246670..ede4f9f3 100644 --- a/mbbsd/descrypt.c +++ b/mbbsd/descrypt.c @@ -1,61 +1,58 @@ -/* $Id: descrypt.c,v 1.2 2002/04/27 15:50:17 in2 Exp $ */ +/* $Id: descrypt.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ /* * FreeSec: libcrypt for NetBSD - * - * Copyright (c) 1994 David Burren - * All rights reserved. - * - * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet - * crypt.c should now *only* export crypt(), in order to make - * binaries of libcrypt exportable from the USA - * + * + * Copyright (c) 1994 David Burren All rights reserved. + * + * Adapted for FreeBSD-2.0 by Geoffrey M. Rehmet crypt.c should now *only* + * export crypt(), in order to make binaries of libcrypt exportable from the + * USA + * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the author nor the names of other contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * modification, are permitted provided that the following conditions are + * met: 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. 2. + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. 4. Neither the name + * of the author nor the names of other contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter Exp $ - * - * This is an original implementation of the DES and the crypt(3) interfaces - * by David Burren <davidb@werj.com.au>. - * - * An excellent reference on the underlying algorithm (and related - * algorithms) is: - * - * B. Schneier, Applied Cryptography: protocols, algorithms, - * and source code in C, John Wiley & Sons, 1994. - * + * + * $FreeBSD: src/secure/lib/libcrypt/crypt.c,v 1.11 1999/08/28 01:30:24 peter + * Exp $ + * + * This is an original implementation of the DES and the crypt(3) interfaces by + * David Burren <davidb@werj.com.au>. + * + * An excellent reference on the underlying algorithm (and related algorithms) + * is: + * + * B. Schneier, Applied Cryptography: protocols, algorithms, and source code in + * C, John Wiley & Sons, 1994. + * * Note that in that book's description of DES the lookups for the initial, * pbox, and final permutations are inverted (this has been brought to the - * attention of the author). A list of errata for this book has been - * posted to the sci.crypt newsgroup by the author and is available for FTP. - * - * ARCHITECTURE ASSUMPTIONS: - * This code assumes that u_longs are 32 bits. It will probably not - * operate on 64-bit machines without modifications. - * It is assumed that the 8-byte arrays passed by reference can be - * addressed as arrays of u_longs (ie. the CPU is not picky about - * alignment). + * attention of the author). A list of errata for this book has been posted + * to the sci.crypt newsgroup by the author and is available for FTP. + * + * ARCHITECTURE ASSUMPTIONS: This code assumes that u_longs are 32 bits. It + * will probably not operate on 64-bit machines without modifications. It is + * assumed that the 8-byte arrays passed by reference can be addressed as + * arrays of u_longs (ie. the CPU is not picky about alignment). */ #ifndef HAVE_DES_CRYPT @@ -66,19 +63,19 @@ #include <string.h> static unsigned char IP[64] = { - 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, - 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, - 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, - 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 + 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, + 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, + 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, + 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7 }; static unsigned char inv_key_perm[64]; static unsigned char u_key_perm[56]; static unsigned char key_perm[56] = { - 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, - 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, - 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, - 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 + 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, + 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, + 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, + 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4 }; static unsigned char key_shifts[16] = { @@ -87,72 +84,72 @@ static unsigned char key_shifts[16] = { static unsigned char inv_comp_perm[56]; static unsigned char comp_perm[48] = { - 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, - 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, + 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32 }; /* - * No E box is used, as it's replaced by some ANDs, shifts, and ORs. + * No E box is used, as it's replaced by some ANDs, shifts, and ORs. */ static unsigned char u_sbox[8][64]; static unsigned char sbox[8][64] = { { - 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, - 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, - 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, - 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 + 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7, + 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8, + 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0, + 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 }, { - 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, - 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, - 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, - 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 + 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10, + 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5, + 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15, + 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 }, { - 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, - 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, - 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, - 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 + 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1, + 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7, + 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 }, { - 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, - 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, - 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, - 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 + 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15, + 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9, + 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4, + 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 }, { - 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, - 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, - 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, - 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 + 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9, + 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6, + 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14, + 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 }, { - 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, - 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, - 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, - 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 + 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11, + 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8, + 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6, + 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 }, { - 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, - 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, - 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, - 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 + 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1, + 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6, + 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2, + 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 }, { - 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, - 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, - 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, - 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 + 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7, + 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2, + 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8, + 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } }; static unsigned char un_pbox[32]; static unsigned char pbox[32] = { - 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, - 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 + 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, + 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25 }; static unsigned long bits32[32] = { @@ -166,15 +163,15 @@ static unsigned long bits32[32] = { 0x00000008, 0x00000004, 0x00000002, 0x00000001 }; -static unsigned char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; +static unsigned char bits8[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; static unsigned long saltbits; -static long old_salt; +static long old_salt; static unsigned long *bits28, *bits24; static unsigned char init_perm[64], final_perm[64]; static unsigned long en_keysl[16], en_keysr[16]; static unsigned long de_keysl[16], de_keysr[16]; -static int des_initialised = 0; +static int des_initialised = 0; static unsigned char m_sbox[4][4096]; static unsigned long psbox[4][256]; static unsigned long ip_maskl[8][256], ip_maskr[8][256]; @@ -183,52 +180,56 @@ static unsigned long key_perm_maskl[8][128], key_perm_maskr[8][128]; static unsigned long comp_maskl[8][128], comp_maskr[8][128]; static unsigned long old_rawkey0, old_rawkey1; -static unsigned char ascii64[] = +static unsigned char ascii64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -/* 0000000000111111111122222222223333333333444444444455555555556666 */ -/* 0123456789012345678901234567890123456789012345678901234567890123 */ +/* 0000000000111111111122222222223333333333444444444455555555556666 */ +/* 0123456789012345678901234567890123456789012345678901234567890123 */ -static int ascii_to_bin(char ch) { - if(ch > 'z') +static int +ascii_to_bin(char ch) +{ + if (ch > 'z') return 0; - if(ch >= 'a') + if (ch >= 'a') return ch - 'a' + 38; - if(ch > 'Z') + if (ch > 'Z') return 0; - if(ch >= 'A') + if (ch >= 'A') return ch - 'A' + 12; - if(ch > '9') + if (ch > '9') return 0; - if(ch >= '.') + if (ch >= '.') return ch - '.'; return 0; } -static void des_init() { - int i, j, b, k, inbit, obit; - unsigned long *p, *il, *ir, *fl, *fr; - +static void +des_init() +{ + int i, j, b, k, inbit, obit; + unsigned long *p, *il, *ir, *fl, *fr; + old_rawkey0 = old_rawkey1 = 0L; saltbits = 0L; old_salt = 0L; bits24 = (bits28 = bits32 + 4) + 4; - + /* * Invert the S-boxes, reordering the input bits. */ - for(i = 0; i < 8; i++) - for(j = 0; j < 64; j++) { + for (i = 0; i < 8; i++) + for (j = 0; j < 64; j++) { b = (j & 0x20) | ((j & 1) << 4) | ((j >> 1) & 0xf); u_sbox[i][j] = sbox[i][b]; } - + /* - * Convert the inverted S-boxes into 4 arrays of 8 bits. - * Each will handle 12 bits of the S-box input. + * Convert the inverted S-boxes into 4 arrays of 8 bits. Each will handle + * 12 bits of the S-box input. */ - for(b = 0; b < 4; b++) - for(i = 0; i < 64; i++) - for(j = 0; j < 64; j++) + for (b = 0; b < 4; b++) + for (i = 0; i < 64; i++) + for (j = 0; j < 64; j++) m_sbox[b][(i << 6) | j] = (u_sbox[(b << 1)][i] << 4) | u_sbox[(b << 1) + 1][j]; @@ -237,16 +238,16 @@ static void des_init() { * Set up the initial & final permutations into a useful form, and * initialise the inverted key permutation. */ - for(i = 0; i < 64; i++) { + for (i = 0; i < 64; i++) { init_perm[final_perm[i] = IP[i] - 1] = i; inv_key_perm[i] = 255; } /* - * Invert the key permutation and initialise the inverted key - * compression permutation. + * Invert the key permutation and initialise the inverted key compression + * permutation. */ - for(i = 0; i < 56; i++) { + for (i = 0; i < 56; i++) { u_key_perm[i] = key_perm[i] - 1; inv_key_perm[key_perm[i] - 1] = i; inv_comp_perm[i] = 255; @@ -255,27 +256,27 @@ static void des_init() { /* * Invert the key compression permutation. */ - for(i = 0; i < 48; i++) { + for (i = 0; i < 48; i++) { inv_comp_perm[comp_perm[i] - 1] = i; } /* - * Set up the OR-mask arrays for the initial and final permutations, - * and for the key initial and compression permutations. + * Set up the OR-mask arrays for the initial and final permutations, and + * for the key initial and compression permutations. */ - for(k = 0; k < 8; k++) { - for(i = 0; i < 256; i++) { + for (k = 0; k < 8; k++) { + for (i = 0; i < 256; i++) { *(il = &ip_maskl[k][i]) = 0L; *(ir = &ip_maskr[k][i]) = 0L; *(fl = &fp_maskl[k][i]) = 0L; *(fr = &fp_maskr[k][i]) = 0L; - for(j = 0; j < 8; j++) { + for (j = 0; j < 8; j++) { inbit = 8 * k + j; - if(i & bits8[j]) { - if((obit = init_perm[inbit]) < 32) + if (i & bits8[j]) { + if ((obit = init_perm[inbit]) < 32) *il |= bits32[obit]; else - *ir |= bits32[obit-32]; + *ir |= bits32[obit - 32]; if ((obit = final_perm[inbit]) < 32) *fl |= bits32[obit]; else @@ -283,15 +284,15 @@ static void des_init() { } } } - for(i = 0; i < 128; i++) { + for (i = 0; i < 128; i++) { *(il = &key_perm_maskl[k][i]) = 0L; *(ir = &key_perm_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) { + for (j = 0; j < 7; j++) { inbit = 8 * k + j; - if(i & bits8[j + 1]) { - if((obit = inv_key_perm[inbit]) == 255) + if (i & bits8[j + 1]) { + if ((obit = inv_key_perm[inbit]) == 255) continue; - if(obit < 28) + if (obit < 28) *il |= bits28[obit]; else *ir |= bits28[obit - 28]; @@ -299,12 +300,12 @@ static void des_init() { } *(il = &comp_maskl[k][i]) = 0L; *(ir = &comp_maskr[k][i]) = 0L; - for(j = 0; j < 7; j++) { + for (j = 0; j < 7; j++) { inbit = 7 * k + j; - if(i & bits8[j + 1]) { - if((obit=inv_comp_perm[inbit]) == 255) + if (i & bits8[j + 1]) { + if ((obit = inv_comp_perm[inbit]) == 255) continue; - if(obit < 24) + if (obit < 24) *il |= bits24[obit]; else *ir |= bits24[obit - 24]; @@ -312,34 +313,36 @@ static void des_init() { } } } - + /* - * Invert the P-box permutation, and convert into OR-masks for - * handling the output of the S-box arrays setup above. + * Invert the P-box permutation, and convert into OR-masks for handling + * the output of the S-box arrays setup above. */ - for(i = 0; i < 32; i++) + for (i = 0; i < 32; i++) un_pbox[pbox[i] - 1] = i; - for(b = 0; b < 4; b++) - for(i = 0; i < 256; i++) { + for (b = 0; b < 4; b++) + for (i = 0; i < 256; i++) { *(p = &psbox[b][i]) = 0L; for (j = 0; j < 8; j++) { if (i & bits8[j]) *p |= bits32[un_pbox[8 * b + j]]; } } - + des_initialised = 1; } -static void setup_salt(long salt) { - unsigned long obit, saltbit; - int i; - +static void +setup_salt(long salt) +{ + unsigned long obit, saltbit; + int i; + if (salt == old_salt) return; old_salt = salt; - + saltbits = 0L; saltbit = 1; obit = 0x800000; @@ -351,32 +354,33 @@ static void setup_salt(long salt) { } } -static int des_setkey(const char *key) { - unsigned long k0, k1, rawkey0, rawkey1; - int shifts, round; +static int +des_setkey(const char *key) +{ + unsigned long k0, k1, rawkey0, rawkey1; + int shifts, round; - if(!des_initialised) + if (!des_initialised) des_init(); - - rawkey0 = ntohl(*(unsigned long *) key); - rawkey1 = ntohl(*(unsigned long *) (key + 4)); - - if((rawkey0 | rawkey1) - && rawkey0 == old_rawkey0 - && rawkey1 == old_rawkey1) { + + rawkey0 = ntohl(*(unsigned long *)key); + rawkey1 = ntohl(*(unsigned long *)(key + 4)); + + if ((rawkey0 | rawkey1) + && rawkey0 == old_rawkey0 + && rawkey1 == old_rawkey1) { /* - * Already setup for this key. - * This optimisation fails on a zero key (which is weak and - * has bad parity anyway) in order to simplify the starting - * conditions. + * Already setup for this key. This optimisation fails on a zero key + * (which is weak and has bad parity anyway) in order to simplify the + * starting conditions. */ return 0; } old_rawkey0 = rawkey0; old_rawkey1 = rawkey1; - + /* - * Do key permutation and split into two 28-bit subkeys. + * Do key permutation and split into two 28-bit subkeys. */ k0 = key_perm_maskl[0][rawkey0 >> 25] | key_perm_maskl[1][(rawkey0 >> 17) & 0x7f] @@ -395,17 +399,17 @@ static int des_setkey(const char *key) { | key_perm_maskr[6][(rawkey1 >> 9) & 0x7f] | key_perm_maskr[7][(rawkey1 >> 1) & 0x7f]; /* - * Rotate subkeys and do compression permutation. + * Rotate subkeys and do compression permutation. */ shifts = 0; - for(round = 0; round < 16; round++) { - unsigned long t0, t1; - + for (round = 0; round < 16; round++) { + unsigned long t0, t1; + shifts += key_shifts[round]; - + t0 = (k0 << shifts) | (k0 >> (28 - shifts)); t1 = (k1 << shifts) | (k1 >> (28 - shifts)); - + de_keysl[15 - round] = en_keysl[round] = comp_maskl[0][(t0 >> 21) & 0x7f] | comp_maskl[1][(t0 >> 14) & 0x7f] @@ -415,7 +419,7 @@ static int des_setkey(const char *key) { | comp_maskl[5][(t1 >> 14) & 0x7f] | comp_maskl[6][(t1 >> 7) & 0x7f] | comp_maskl[7][t1 & 0x7f]; - + de_keysr[15 - round] = en_keysr[round] = comp_maskr[0][(t0 >> 21) & 0x7f] | comp_maskr[1][(t0 >> 14) & 0x7f] @@ -429,35 +433,37 @@ static int des_setkey(const char *key) { return 0; } -static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, - unsigned long *r_out, int count) { +static int +do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, + unsigned long *r_out, int count) +{ /* - * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. - */ - unsigned long l, r, *kl, *kr, *kl1, *kr1; - unsigned long f, r48l, r48r; - int round; + * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. + */ + unsigned long l, r, *kl, *kr, *kl1, *kr1; + unsigned long f, r48l, r48r; + int round; - if(count == 0) { + if (count == 0) { return 1; - } else if(count > 0) { + } else if (count > 0) { /* - * Encrypting - */ + * Encrypting + */ kl1 = en_keysl; kr1 = en_keysr; } else { /* - * Decrypting - */ + * Decrypting + */ count = -count; kl1 = de_keysl; kr1 = de_keysr; } - + /* - * Do initial permutation (IP). - */ + * Do initial permutation (IP). + */ l = ip_maskl[0][l_in >> 24] | ip_maskl[1][(l_in >> 16) & 0xff] | ip_maskl[2][(l_in >> 8) & 0xff] @@ -474,15 +480,15 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, | ip_maskr[5][(r_in >> 16) & 0xff] | ip_maskr[6][(r_in >> 8) & 0xff] | ip_maskr[7][r_in & 0xff]; - - while(count--) { + + while (count--) { /* * Do each round. */ kl = kl1; kr = kr1; round = 16; - while(round--) { + while (round--) { /* * Expand R to 48 bits (simulate the E-box). */ @@ -498,15 +504,15 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, | ((r & 0x0000001f) << 1) | ((r & 0x80000000) >> 31); /* - * Do salting for crypt() and friends, and - * XOR with the permuted key. + * Do salting for crypt() and friends, and XOR with the permuted + * key. */ f = (r48l ^ r48r) & saltbits; r48l ^= f ^ *kl++; r48r ^= f ^ *kr++; /* - * Do sbox lookups (which shrink it back to 32 bits) - * and do the pbox permutation at the same time. + * Do sbox lookups (which shrink it back to 32 bits) and do the + * pbox permutation at the same time. */ f = psbox[0][m_sbox[0][r48l >> 12]] | psbox[1][m_sbox[1][r48l & 0xfff]] @@ -523,8 +529,8 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, l = f; } /* - * Do final permutation (inverse of IP). - */ + * Do final permutation (inverse of IP). + */ *l_out = fp_maskl[0][l >> 24] | fp_maskl[1][(l >> 16) & 0xff] | fp_maskl[2][(l >> 8) & 0xff] @@ -544,41 +550,40 @@ static int do_des(unsigned long l_in, unsigned long r_in, unsigned long *l_out, return 0; } -char *crypt(char *key, char *setting) { - unsigned long count, salt, l, r0, r1, keybuf[2]; - unsigned char *p, *q; +char * +crypt(char *key, char *setting) +{ + unsigned long count, salt, l, r0, r1, keybuf[2]; + unsigned char *p, *q; static unsigned char output[21]; - - if(!des_initialised) + + if (!des_initialised) des_init(); /* - * Copy the key, shifting each character up by one bit - * and padding with zeros. + * Copy the key, shifting each character up by one bit and padding with + * zeros. */ q = (unsigned char *)keybuf; - while(q - (unsigned char *)keybuf - 8) { - if((*q++ = *key << 1)) + while (q - (unsigned char *)keybuf - 8) { + if ((*q++ = *key << 1)) key++; } - if(des_setkey((char *)keybuf)) + if (des_setkey((char *)keybuf)) return NULL; - + /* - * "old"-style: - * setting - 2 bytes of salt - * key - up to 8 characters + * "old"-style: setting - 2 bytes of salt key - up to 8 characters */ count = 25; salt = (ascii_to_bin(setting[1]) << 6) - | ascii_to_bin(setting[0]); + | ascii_to_bin(setting[0]); output[0] = setting[0]; /* - * If the encrypted password that the salt was extracted from - * is only 1 character long, the salt will be corrupted. We - * need to ensure that the output string doesn't have an extra - * NUL in it! + * If the encrypted password that the salt was extracted from is only 1 + * character long, the salt will be corrupted. We need to ensure that + * the output string doesn't have an extra NUL in it! */ output[1] = setting[1] ? setting[1] : output[0]; @@ -588,7 +593,7 @@ char *crypt(char *key, char *setting) { /* * Do it. */ - if(do_des(0L, 0L, &r0, &r1, count)) + if (do_des(0L, 0L, &r0, &r1, count)) return NULL; /* * Now encode the result... diff --git a/mbbsd/dice.c b/mbbsd/dice.c index 32ef7f5b..62aeba16 100644 --- a/mbbsd/dice.c +++ b/mbbsd/dice.c @@ -1,4 +1,4 @@ -/* $Id: dice.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: dice.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define DICE_TXT BBSHOME "/etc/dice.txt" @@ -12,85 +12,94 @@ #define B_TIMES 5 #define B_THIRD 3 -static int flag[100], value[100]; +static int flag[100], value[100]; typedef struct dicedata_t { - int mybet; - int mymoney; -} dicedata_t; - -static void set_bingo(int bet[]) { - int i, j = 0, k = 0, m = 0; - - for(i = 0; i < 3; i++) - for(j = 2; j > i; j--) - if(bet[j] < bet[j - 1]) { + int mybet; + int mymoney; +} dicedata_t; + +static void +set_bingo(int bet[]) +{ + int i, j = 0, k = 0, m = 0; + + for (i = 0; i < 3; i++) + for (j = 2; j > i; j--) + if (bet[j] < bet[j - 1]) { m = bet[j]; bet[j] = bet[j - 1]; - bet[j - 1]=m; + bet[j - 1] = m; } - - for(i = 0; i < 100; i++) + for (i = 0; i < 100; i++) flag[i] = 0; - - for(i = 0; i < 3; i++) + + for (i = 0; i < 3; i++) flag[bet[i]]++; j = bet[0] + bet[1] + bet[2]; - if((abs(bet[1] - bet[0]) == 1 && abs(bet[2] - bet[0]) == 2) || - (abs(bet[2] - bet[0]) == 1 && abs(bet[1] - bet[0]) == 2)) + if ((abs(bet[1] - bet[0]) == 1 && abs(bet[2] - bet[0]) == 2) || + (abs(bet[2] - bet[0]) == 1 && abs(bet[1] - bet[0]) == 2)) flag[66] = B_TIMES; - - if(j < 10){ + + if (j < 10) { flag[7] = B_COMMON; - for(i = 0; i < 3; i++) - if(bet[i] == 4) + for (i = 0; i < 3; i++) + if (bet[i] == 4) flag[74] = B_TIMES; - } else if(j > 11) { + } else if (j > 11) { flag[8] = B_COMMON; - for(i = 0; i < 3; i++) - if(bet[i] == 3) - flag[83]=B_TIMES; + for (i = 0; i < 3; i++) + if (bet[i] == 3) + flag[83] = B_TIMES; } else flag[11] = B_THIRD; - - for(i = 0; i < 3; i++) - for(j = i; j < 3; j++) { + + for (i = 0; i < 3; i++) + for (j = i; j < 3; j++) { m = bet[i]; k = bet[j]; - if(m != k) + if (m != k) flag[m * 10 + k] = B_TIMES; } } -static int bingo(int mybet) { +static int +bingo(int mybet) +{ return flag[mybet]; } -int IsNum(char *a, int n) { - int i; +int +IsNum(char *a, int n) +{ + int i; - for(i = 0; i < n; i++) - if (a[i] > '9' || a[i] < '0' ) + for (i = 0; i < n; i++) + if (a[i] > '9' || a[i] < '0') return 0; return 1; } -int IsSNum(char *a) { - int i; - - for(i = 0; a[i]; i++) - if(a[i] > '9' || a[i] < '0') +int +IsSNum(char *a) +{ + int i; + + for (i = 0; a[i]; i++) + if (a[i] > '9' || a[i] < '0') return 0; return 1; } -static void show_data(void) { +static void +show_data(void) +{ move(0, 0); prints("\033[31m ¢z¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢{\033[m\n"); prints("\033[45;37m¿²v¤@\033[m\033[31m ¢x \033[33m[1]©ã¤@ÂI [2]©ã¤GÂI " - "[3]©ã¤TÂI [4]©ã¥|ÂI [5]©ã¤ÂI [6]©ã¤»ÂI \033[31m ¢x\033[m\n"); + "[3]©ã¤TÂI [4]©ã¥|ÂI [5]©ã¤ÂI [6]©ã¤»ÂI \033[31m ¢x\033[m\n"); prints("\033[31m ¢x \033[33m[7]©ã¤p [8]©ã¤j " " \033[31m ¢x\033[m\n"); prints("\033[31m ¢x " @@ -113,87 +122,93 @@ static void show_data(void) { "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢}\033[m\n"); } -static void show_count(int index, int money) { - int i = 0, count = 2, j, k; - +static void +show_count(int index, int money) +{ + int i = 0, count = 2, j, k; + value[index] += money; - move(14,0); + move(14, 0); clrtoline(18); - for(i = 1, j = 13; i <= 8; i++, count += 12) { - if(i == 6) { + for (i = 1, j = 13; i <= 8; i++, count += 12) { + if (i == 6) { j = 14; count = 2; } - move(j,count); + move(j, count); prints("[%2d]:%d ", i, value[i]); } - + count = 2; i = 15; - for(j = 1; j <= 5; j++) - for(k = j + 1; k <= 6; k++, count += 12) { - if(j == 2 && k == 4) { + for (j = 1; j <= 5; j++) + for (k = j + 1; k <= 6; k++, count += 12) { + if (j == 2 && k == 4) { i = 16; count = 2; - } else if(j==4 && k==5) { + } else if (j == 4 && k == 5) { i = 17; count = 2; } - move(i,count); + move(i, count); prints("[%d%d]:%d ", j, k, value[j * 10 + k]); } - - move(18,2); - prints("[11]:%d",value[11]); - move(18,14); - prints("[66]:%d",value[66]); - move(18,26); - prints("[74]:%d",value[74]); - move(18,38); - prints("[83]:%d",value[83]); + + move(18, 2); + prints("[11]:%d", value[11]); + move(18, 14); + prints("[66]:%d", value[66]); + move(18, 26); + prints("[74]:%d", value[74]); + move(18, 38); + prints("[83]:%d", value[83]); } -static int check_index(int index) { - int i,tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, - 26, 34, 35, 36, 45, 46, 56, 66, 74, 83}; - if(index < 0 || index > 100) +static int +check_index(int index) +{ + int i, tp[] = {1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 23, 24, 25, + 26, 34, 35, 36, 45, 46, 56, 66, 74, 83}; + if (index < 0 || index > 100) return 0; - for(i = 0; i < 27; i++) - if(index == tp[i]) + for (i = 0; i < 27; i++) + if (index == tp[i]) return 1; return 0; } -static int del(int total, dicedata_t *table) { - int index, money; - char data[10]; - int i; - - while(1) { +static int +del(int total, dicedata_t * table) +{ + int index, money; + char data[10]; + int i; + + while (1) { do { - move(22,0); + move(22, 0); clrtoeol(); getdata(21, 0, "¿é¤J°h¿ïªº¼Æ¦r(¥´qÂ÷¶}): ", data, 3, LCECHO); - if(data[0] == 'q' || data[0] == 'Q') + if (data[0] == 'q' || data[0] == 'Q') return 0; - } while(!IsNum(data,strlen(data))); - + } while (!IsNum(data, strlen(data))); + index = atoi(data); - for(i = 0; i < total; i++) { - if(table[i].mybet == index){ + for (i = 0; i < total; i++) { + if (table[i].mybet == index) { do { getdata(21, 0, "¦h¤Ö¿ú: ", data, 10, LCECHO); - } while(!IsNum(data,strlen(data))); + } while (!IsNum(data, strlen(data))); money = atoi(data); - if(money>table[i].mymoney) { - move(22,0); + if (money > table[i].mymoney) { + move(22, 0); clrtoeol(); prints("¤£°÷¦©°Õ"); i--; continue; } demoney(money); - move(19,0); + move(19, 0); clrtoeol(); prints("§A²{¦b¦³ %u Ptt$¼Ú", cuser.money); table[i].mymoney -= money; @@ -205,71 +220,105 @@ static int del(int total, dicedata_t *table) { return 0; } -static int IsLegal(char *data) { - int money = atoi(data); - if(IsNum(data,strlen(data)) && money<=B_MAX && money>=B_MIN) +static int +IsLegal(char *data) +{ + int money = atoi(data); + if (IsNum(data, strlen(data)) && money <= B_MAX && money >= B_MIN) return money; return 0; } -static void show_output(int bet[]) { - int i, j = 10; - - move(12,0); +static void +show_output(int bet[]) +{ + int i, j = 10; + + move(12, 0); clrtoline(17); /* ¼È®É°°Õ ¦]¬°¨º¦Uclrtoline©Ç©Çªº */ - for(i = 13; i <= 18; i++) { - move(i,0); + for (i = 13; i <= 18; i++) { + move(i, 0); prints(" "); } - move(12,0); + move(12, 0); prints("\033[1;31m ¢z¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢{\033[m\n\n\n\n\n\n"); prints("\033[1;31m ¢|¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢}\033[m"); - for(i = 0; i < 3; i++, j += 25) { - switch(bet[i]) { + for (i = 0; i < 3; i++, j += 25) { + switch (bet[i]) { case 1: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x ¢x\033[m"); - move(15, j);prints("\033[37m¢x ¡´ ¢x\033[m"); - move(16, j);prints("\033[37m¢x ¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x ¢x\033[m"); + move(15, j); + prints("\033[37m¢x ¡´ ¢x\033[m"); + move(16, j); + prints("\033[37m¢x ¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; case 2: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x ¡´¢x\033[m"); - move(15, j);prints("\033[37m¢x ¢x\033[m"); - move(16, j);prints("\033[37m¢x¡´ ¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x ¡´¢x\033[m"); + move(15, j); + prints("\033[37m¢x ¢x\033[m"); + move(16, j); + prints("\033[37m¢x¡´ ¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; case 3: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x ¡´¢x\033[m"); - move(15, j);prints("\033[37m¢x ¡´ ¢x\033[m"); - move(16, j);prints("\033[37m¢x¡´ ¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x ¡´¢x\033[m"); + move(15, j); + prints("\033[37m¢x ¡´ ¢x\033[m"); + move(16, j); + prints("\033[37m¢x¡´ ¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; case 4: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(15, j);prints("\033[37m¢x ¢x\033[m"); - move(16, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(15, j); + prints("\033[37m¢x ¢x\033[m"); + move(16, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; case 5: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(15, j);prints("\033[37m¢x ¡´ ¢x\033[m"); - move(16, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(15, j); + prints("\033[37m¢x ¡´ ¢x\033[m"); + move(16, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; case 6: - move(13, j);prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); - move(14, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(15, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(16, j);prints("\033[37m¢x¡´ ¡´¢x\033[m"); - move(17, j);prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); + move(13, j); + prints("\033[37m¢~¢w¢w¢w¢w¢¡\033[m"); + move(14, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(15, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(16, j); + prints("\033[37m¢x¡´ ¡´¢x\033[m"); + move(17, j); + prints("\033[37m¢¢¢w¢w¢w¢w¢£\033[m"); break; } } @@ -277,160 +326,162 @@ static void show_output(int bet[]) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int dice_main(void) { - char input[10],data[256], ch; - dicedata_t table[256]; - int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; - FILE *winfp/* , *lostfp */; - +int +dice_main(void) +{ + char input[10], data[256], ch; + dicedata_t table[256]; + int bet[3], index, money = 0, i, ya = 0, j, total, sig = 0; + FILE *winfp /* , *lostfp */ ; + more(DICE_TXT, NA); reload_money(); - if(cuser.money < 10){ - move(19,0); + if (cuser.money < 10) { + move(19, 0); prints("\033[1;37m¶W¹L¤Q¤¸¦A¨Óª±§a~~\033[m"); pressanykey(); return 0; } - lockreturn0(DICE, LOCK_MULTI); - winfp = fopen(DICE_WIN,"a"); - /*lostfp = fopen(DICE_LOST,"a");*/ - if(!winfp /*|| !lostfp*/) + winfp = fopen(DICE_WIN, "a"); + /* lostfp = fopen(DICE_LOST,"a"); */ + if (!winfp /* || !lostfp */ ) return 0; do { - total = 0; i = 0; + total = 0; + i = 0; ch = 'y'; clear(); show_data(); - for(j = 0; j < 3; j++) + for (j = 0; j < 3; j++) bet[j] = rand() % 6 + 1; - - for(j = 0; j < 100; j++) + + for (j = 0; j < 100; j++) value[j] = 0; - while(1) { - move(19,0); + while (1) { + move(19, 0); prints("\033[1;32m§A²{¦b¦³\033[1;31m %u \033[1;32mPtt$¼Ú\033[m", cuser.money); getdata(20, 0, "\033[1;37m¼Æ¦r:¥[¿ï d:°h¿ï s:¶}©l©ÎÂ÷¶}\033[m: ", input, 5, LCECHO); reload_money(); - if(input[0] != 's' && input[0] != 'd' && cuser.money < 10) { + if (input[0] != 's' && input[0] != 'd' && cuser.money < 10) { move(21, 0); clrtoeol(); prints("\033[1;37m¶W¹L¤Q¤¸¤~¯à½ä~\033[m"); continue; } - if(input[0] == 'd' || input[0] == 'D') { + if (input[0] == 'd' || input[0] == 'D') { del(i, table); continue; } - if(input[0] == 's' || input[0] == 'S') + if (input[0] == 's' || input[0] == 'S') break; - - if(!IsNum(input,strlen(input))) + + if (!IsNum(input, strlen(input))) continue; - - index=atoi(input); - if(check_index(index) == 0) + + index = atoi(input); + if (check_index(index) == 0) continue; -/*¿é¤J¿úªºloop*/ - while(1) { - if(cuser.money < 10) + /* ¿é¤J¿úªºloop */ + while (1) { + if (cuser.money < 10) break; getdata(21, 0, "\033[1;32m½ä¦h¤Ö¿ú©O\033[1;37m(¤j©ó10 ¤p©ó500)" "\033[m: ", input, sizeof(input), LCECHO); - if(!(money = IsLegal(input))||input[0] == '0') + if (!(money = IsLegal(input)) || input[0] == '0') continue; - reload_money(); - if(money > cuser.money) + reload_money(); + if (money > cuser.money) continue; - for(j = 0, sig = 0; j < i; j++) - if(table[j].mybet == index) { - if(table[j].mymoney == B_MAX) + for (j = 0, sig = 0; j < i; j++) + if (table[j].mybet == index) { + if (table[j].mymoney == B_MAX) sig = 2; - else if(table[j].mymoney+money>B_MAX) { + else if (table[j].mymoney + money > B_MAX) { sig = 1; break; } else { - vice(money,"»ë¤l"); + vice(money, "»ë¤l"); table[j].mymoney += money; j = -1; break; } } - if(sig == 2) + if (sig == 2) break; - if(sig == 1) + if (sig == 1) continue; - if(j != -1) { - bzero((char*)&table[i], sizeof(dicedata_t)); + if (j != -1) { + bzero((char *)&table[i], sizeof(dicedata_t)); table[i].mybet = index; table[i++].mymoney = money; - vice(money,"»ë¤l"); + vice(money, "»ë¤l"); } break; } - reload_money(); - move(19,0); + reload_money(); + move(19, 0); prints("\033[1;32m§A²{¦b¦³ \033[1;31m%u\033[1;32m Ptt$¼Ú", cuser.money); - if(sig != 2) + if (sig != 2) show_count(index, money); } - - if(i == 0) { + + if (i == 0) { fclose(winfp); - /*fclose(lostfp);*/ + /* fclose(lostfp); */ unlockutmpmode(); return 0; } - show_output(bet); set_bingo(bet); - for(j = 0; j < i; j++) { - if(table[j].mymoney <= 0) + for (j = 0; j < i; j++) { + if (table[j].mymoney <= 0) continue; ya = bingo(table[j].mybet); - if(ya == 0) { - /*sprintf(data, "%-15s ¿é¤F %-8d $", cuser.userid, - table[j].mymoney); - fprintf(lostfp, "%s\n", data);*/ + if (ya == 0) { + /* + * sprintf(data, "%-15s ¿é¤F %-8d $", cuser.userid, + * table[j].mymoney); fprintf(lostfp, "%s\n", data); + */ continue; } demoney(table[j].mymoney * ya + table[j].mymoney); total += table[j].mymoney * ya; - if (table[j].mymoney * ya > 500){ /* ¶W¹L500¶ô¿ú¤~°µlog ´î¤Öio */ - sprintf(data, "%-15s ©ã%-2d¿ï¶µ%-8d¶ô¿ú ¤¤¤F%d¿ ²bÁÈ:%-8d\n", - cuser.userid,table[j].mybet, - table[j].mymoney, ya, table[j].mymoney * ya); - fputs(data,winfp); + if (table[j].mymoney * ya > 500) { /* ¶W¹L500¶ô¿ú¤~°µlog ´î¤Öio */ + sprintf(data, "%-15s ©ã%-2d¿ï¶µ%-8d¶ô¿ú ¤¤¤F%d¿ ²bÁÈ:%-8d\n", + cuser.userid, table[j].mybet, + table[j].mymoney, ya, table[j].mymoney * ya); + fputs(data, winfp); } ya = 0; } - if(total > 0) { - move(21,0); + if (total > 0) { + move(21, 0); prints("\033[1;32m§AŤF \033[1;31m%d\033[1;32m Ptt$ ò~~" " \033[m", total); } else { - move(21,0); + move(21, 0); clrtoeol(); prints("\033[1;32m¯u¥i±¤ ¤U¦¸¦A¨Ó¸I¸I¹B®ð§a\033[m"); } - - move(19,0); + + move(19, 0); clrtoeol(); prints("\033[1;32m§A²{¦b¦³ \033[1;31m%u\033[1;32m Ptt$¼Ú\033[m", cuser.money); - + getdata(23, 0, "\033[1;32mÄ~Äò¾Ä°«[\033[1;37my/n\033[1;32m]\033[m: ", input, 2, LCECHO); - } while(input[0] != 'n' && input[0] != 'N'); + } while (input[0] != 'n' && input[0] != 'N'); fclose(winfp); - /*fclose(lostfp);*/ + /* fclose(lostfp); */ unlockutmpmode(); return 0; } diff --git a/mbbsd/edit.c b/mbbsd/edit.c index b9dc41ba..c210ba8f 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1,15 +1,15 @@ -/* $Id: edit.c,v 1.11 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: edit.c,v 1.12 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" typedef struct textline_t { struct textline_t *prev; struct textline_t *next; - int len; - char data[WRAPMARGIN + 1]; -} textline_t; + int len; + char data[WRAPMARGIN + 1]; +} textline_t; #define KEEP_EDITING -2 #define BACKUP_LIMIT 100 -#define SCR_WIDTH 80 +#define SCR_WIDTH 80 enum { NOBODY, MANAGER, SYSOP @@ -22,46 +22,50 @@ static textline_t *blockline = NULL; static textline_t *top_of_win = NULL; static textline_t *deleted_lines = NULL; -static char line[WRAPMARGIN + 2]; -static int ifuseanony=0; -static int currpnt, currln, totaln; -static int curr_window_line; -static int redraw_everything; -static int insert_character; -static int my_ansimode; -static int raw_mode; -static int edit_margin; -static int blockln = -1; -static int blockpnt; -static int prevln = -1; -static int prevpnt; -static int line_dirty; -static int indent_mode; -static int insert_c = ' '; - -static char fp_bak[] = "bak"; +static char line[WRAPMARGIN + 2]; +static int ifuseanony = 0; +static int currpnt, currln, totaln; +static int curr_window_line; +static int redraw_everything; +static int insert_character; +static int my_ansimode; +static int raw_mode; +static int edit_margin; +static int blockln = -1; +static int blockpnt; +static int prevln = -1; +static int prevpnt; +static int line_dirty; +static int indent_mode; +static int insert_c = ' '; + +static char fp_bak[] = "bak"; /* °O¾ÐÅéºÞ²z»P½s¿è³B²z */ -static void indigestion(i) { +static void +indigestion(i) +{ fprintf(stderr, "ÄY«¤º¶Ë %d\n", i); } /* Thor: ansi ®y¼ÐÂà´« for color ½s¿è¼Ò¦¡ */ -static int ansi2n(int ansix, textline_t * line) { - register char *data, *tmp; - register char ch; - +static int +ansi2n(int ansix, textline_t * line) +{ + register char *data, *tmp; + register char ch; + data = tmp = line->data; - - while(*tmp) { - if(*tmp == KEY_ESC) { - while((ch = *tmp) && !isalpha(ch)) + + while (*tmp) { + if (*tmp == KEY_ESC) { + while ((ch = *tmp) && !isalpha(ch)) tmp++; - if(ch) + if (ch) tmp++; continue; } - if(ansix <= 0) + if (ansix <= 0) break; tmp++; ansix--; @@ -69,23 +73,25 @@ static int ansi2n(int ansix, textline_t * line) { return tmp - data; } -static int n2ansi(int nx, textline_t * line) { - register int ansix = 0; - register char *tmp,*nxp; - register char ch; - +static int +n2ansi(int nx, textline_t * line) +{ + register int ansix = 0; + register char *tmp, *nxp; + register char ch; + tmp = nxp = line->data; nxp += nx; - - while(*tmp) { - if(*tmp == KEY_ESC) { - while((ch = *tmp) && !isalpha(ch)) + + while (*tmp) { + if (*tmp == KEY_ESC) { + while ((ch = *tmp) && !isalpha(ch)) tmp++; - if(ch) + if (ch) tmp++; continue; } - if(tmp >= nxp) + if (tmp >= nxp) break; tmp++; ansix++; @@ -94,11 +100,13 @@ static int n2ansi(int nx, textline_t * line) { } /* ¿Ã¹õ³B²z¡G»²§U°T®§¡BÅã¥Ü½s¿è¤º®e */ -static void edit_msg() { - static char *edit_mode[2] = {"¨ú¥N", "´¡¤J"}; - register int n = currpnt; - - if(my_ansimode) /* Thor: §@ ansi ½s¿è */ +static void +edit_msg() +{ + static char *edit_mode[2] = {"¨ú¥N", "´¡¤J"}; + register int n = currpnt; + + if (my_ansimode) /* Thor: §@ ansi ½s¿è */ n = n2ansi(n, currline); n++; move(b_lines, 0); @@ -109,15 +117,17 @@ static void edit_msg() { "37;44", edit_mode[insert_character], my_ansimode ? 'A' : 'a', indent_mode ? 'I' : 'i', - 'P' , raw_mode ? 'R' : 'r', + 'P', raw_mode ? 'R' : 'r', currln + 1, n); } -static textline_t *back_line(textline_t *pos, int num) { - while(num-- > 0) { +static textline_t * +back_line(textline_t * pos, int num) +{ + while (num-- > 0) { register textline_t *item; - - if(pos && (item = pos->prev)) { + + if (pos && (item = pos->prev)) { pos = item; currln--; } @@ -125,11 +135,13 @@ static textline_t *back_line(textline_t *pos, int num) { return pos; } -static textline_t *forward_line(textline_t *pos, int num) { - while(num-- > 0) { +static textline_t * +forward_line(textline_t * pos, int num) +{ + while (num-- > 0) { register textline_t *item; - if(pos && (item = pos->next)) { + if (pos && (item = pos->next)) { pos = item; currln++; } @@ -137,41 +149,48 @@ static textline_t *forward_line(textline_t *pos, int num) { return pos; } -static int getlineno() { - int cnt = 0; - textline_t *p = currline; +static int +getlineno() +{ + int cnt = 0; + textline_t *p = currline; - while(p && (p != top_of_win)) { + while (p && (p != top_of_win)) { cnt++; p = p->prev; } return cnt; } -static char *killsp(char *s) { - while(*s == ' ') +static char * +killsp(char *s) +{ + while (*s == ' ') s++; return s; } -static textline_t *alloc_line() { +static textline_t * +alloc_line() +{ register textline_t *p; - - if((p = (textline_t *)malloc(sizeof(textline_t)))) { + + if ((p = (textline_t *) malloc(sizeof(textline_t)))) { memset(p, 0, sizeof(textline_t)); return p; } - indigestion(13); abort_bbs(0); return NULL; } /* append p after line in list. keeps up with last line */ -static void append(textline_t *p, textline_t *line) { +static void +append(textline_t * p, textline_t * line) +{ register textline_t *n; - - if((p->next = n = line->next)) + + if ((p->next = n = line->next)) n->prev = p; else lastline = p; @@ -180,23 +199,25 @@ static void append(textline_t *p, textline_t *line) { } /* - delete_line deletes 'line' from the list, - and maintains the lastline, and firstline pointers. -*/ + * delete_line deletes 'line' from the list, and maintains the lastline, and + * firstline pointers. + */ -static void delete_line(textline_t *line) { +static void +delete_line(textline_t * line) +{ register textline_t *p = line->prev; register textline_t *n = line->next; - - if(!p && !n) { + + if (!p && !n) { line->data[0] = line->len = 0; return; } - if(n) + if (n) n->prev = p; else lastline = p; - if(p) + if (p) p->next = n; else firstline = n; @@ -206,29 +227,33 @@ static void delete_line(textline_t *line) { totaln--; } -static int ask(char *prompt) { - int ch; - - move (0, 0); - clrtoeol (); - standout (); - prints ("%s", prompt); - standend (); - ch = igetkey (); - move (0, 0); - clrtoeol (); +static int +ask(char *prompt) +{ + int ch; + + move(0, 0); + clrtoeol(); + standout(); + prints("%s", prompt); + standend(); + ch = igetkey(); + move(0, 0); + clrtoeol(); return (ch); } -static int indent_spcs() { - textline_t* p; - int spcs; - - if(!indent_mode) +static int +indent_spcs() +{ + textline_t *p; + int spcs; + + if (!indent_mode) return 0; - - for(p = currline; p; p = p->prev) { - for(spcs = 0; p->data[spcs] == ' '; ++spcs); + + for (p = currline; p; p = p->prev) { + for (spcs = 0; p->data[spcs] == ' '; ++spcs); if (p->data[spcs]) return spcs; } @@ -236,25 +261,27 @@ static int indent_spcs() { } /* split 'line' right before the character pos */ -static void split(textline_t *line, int pos) { - if(pos <= line->len) { +static void +split(textline_t * line, int pos) +{ + if (pos <= line->len) { register textline_t *p = alloc_line(); - register char *ptr; - int spcs = indent_spcs(); - + register char *ptr; + int spcs = indent_spcs(); + totaln++; - + p->len = line->len - pos + spcs; line->len = pos; - + memset(p->data, ' ', spcs); p->data[spcs] = 0; strcat(p->data, (ptr = line->data + pos)); ptr[0] = '\0'; append(p, line); - if(line == currline && pos <= currpnt) { + if (line == currline && pos <= currpnt) { currline = p; - if(pos == currpnt) + if (pos == currpnt) currpnt = spcs; else currpnt -= pos; @@ -265,45 +292,47 @@ static void split(textline_t *line, int pos) { } } -static void insert_char(int ch) { +static void +insert_char(int ch) +{ register textline_t *p = currline; - register int i = p->len; - register char *s; - int wordwrap = YEA; - - if(currpnt > i) { + register int i = p->len; + register char *s; + int wordwrap = YEA; + + if (currpnt > i) { indigestion(1); return; } - if(currpnt < i && !insert_character) { + if (currpnt < i && !insert_character) { p->data[currpnt++] = ch; /* Thor: ansi ½s¿è, ¥i¥Hoverwrite, ¤£»\¨ì ansi code */ - if(my_ansimode) - currpnt = ansi2n(n2ansi(currpnt, p),p); + if (my_ansimode) + currpnt = ansi2n(n2ansi(currpnt, p), p); } else { - while(i >= currpnt) { + while (i >= currpnt) { p->data[i + 1] = p->data[i]; i--; } p->data[currpnt++] = ch; i = ++(p->len); } - if(i < WRAPMARGIN) + if (i < WRAPMARGIN) return; s = p->data + (i - 1); - while(s != p->data && *s == ' ') + while (s != p->data && *s == ' ') s--; - while(s != p->data && *s != ' ') + while (s != p->data && *s != ' ') s--; - if(s == p->data) { + if (s == p->data) { wordwrap = NA; s = p->data + (i - 2); } split(p, (s - p->data) + 1); p = p->next; i = p->len; - if(wordwrap && i >= 1) { - if(p->data[i - 1] != ' ') { + if (wordwrap && i >= 1) { + if (p->data[i - 1] != ' ') { p->data[i] = ' '; p->data[i + 1] = '\0'; p->len++; @@ -311,39 +340,43 @@ static void insert_char(int ch) { } } -static void insert_string(char *str) { - int ch; - - while((ch = *str++)) { - if(isprint2(ch) || ch == '\033') +static void +insert_string(char *str) +{ + int ch; + + while ((ch = *str++)) { + if (isprint2(ch) || ch == '\033') insert_char(ch); - else if(ch == '\t') { + else if (ch == '\t') { do { insert_char(' '); - } while(currpnt & 0x7); - } else if(ch == '\n') + } while (currpnt & 0x7); + } else if (ch == '\n') split(currline, currpnt); } } -static int undelete_line() { - textline_t* p = deleted_lines; - textline_t* currline0 = currline; - textline_t* top_of_win0 = top_of_win; - int currpnt0 = currpnt; - int currln0 = currln; - int curr_window_line0 = curr_window_line; - int indent_mode0 = indent_mode; - - if(!deleted_lines) +static int +undelete_line() +{ + textline_t *p = deleted_lines; + textline_t *currline0 = currline; + textline_t *top_of_win0 = top_of_win; + int currpnt0 = currpnt; + int currln0 = currln; + int curr_window_line0 = curr_window_line; + int indent_mode0 = indent_mode; + + if (!deleted_lines) return 0; - + indent_mode = 0; insert_string(deleted_lines->data); indent_mode = indent_mode0; deleted_lines = deleted_lines->prev; free(p); - + currline = currline0; top_of_win = top_of_win0; currpnt = currpnt0; @@ -353,48 +386,47 @@ static int undelete_line() { } /* - 1) lines were joined and one was deleted - 2) lines could not be joined - 3) next line is empty - returns false if: - 1) Some of the joined line wrapped -*/ -static int join(textline_t *line) { + * 1) lines were joined and one was deleted 2) lines could not be joined 3) + * next line is empty returns false if: 1) Some of the joined line wrapped + */ +static int +join(textline_t * line) +{ register textline_t *n; - register int ovfl; - - if(!(n = line->next)) + register int ovfl; + + if (!(n = line->next)) return YEA; - if(!*killsp(n->data)) + if (!*killsp(n->data)) return YEA; - + ovfl = line->len + n->len - WRAPMARGIN; - if(ovfl < 0) { + if (ovfl < 0) { strcat(line->data, n->data); line->len += n->len; delete_line(n); return YEA; } else { - register char *s; - + register char *s; + s = n->data + n->len - ovfl - 1; - while(s != n->data && *s == ' ') + while (s != n->data && *s == ' ') s--; - while(s != n->data && *s != ' ') + while (s != n->data && *s != ' ') s--; - if(s == n->data) + if (s == n->data) return YEA; split(n, (s - n->data) + 1); - if(line->len + n->len >= WRAPMARGIN) { + if (line->len + n->len >= WRAPMARGIN) { indigestion(0); return YEA; } join(line); n = line->next; ovfl = n->len - 1; - if(ovfl >= 0 && ovfl < WRAPMARGIN - 2) { + if (ovfl >= 0 && ovfl < WRAPMARGIN - 2) { s = &(n->data[ovfl]); - if(*s != ' ') { + if (*s != ' ') { strcpy(s, " "); n->len++; } @@ -403,122 +435,135 @@ static int join(textline_t *line) { } } -static void delete_char() { - register int len; - - if((len = currline->len)) { - register int i; - register char *s; - - if(currpnt >= len) { +static void +delete_char() +{ + register int len; + + if ((len = currline->len)) { + register int i; + register char *s; + + if (currpnt >= len) { indigestion(1); return; } - for(i = currpnt, s = currline->data + i; i != len; i++, s++) + for (i = currpnt, s = currline->data + i; i != len; i++, s++) s[0] = s[1]; currline->len--; } } -static void load_file(FILE *fp) { - int indent_mode0 = indent_mode; +static void +load_file(FILE * fp) +{ + int indent_mode0 = indent_mode; indent_mode = 0; - while(fgets(line, WRAPMARGIN + 2, fp)) + while (fgets(line, WRAPMARGIN + 2, fp)) insert_string(line); fclose(fp); indent_mode = indent_mode0; } /* ¼È¦sÀÉ */ -char *ask_tmpbuf(int y) { - static char fp_buf[10] = "buf.0"; - static char msg[] = "½Ð¿ï¾Ü¼È¦sÀÉ (0-9)[0]: "; - +char * +ask_tmpbuf(int y) +{ + static char fp_buf[10] = "buf.0"; + static char msg[] = "½Ð¿ï¾Ü¼È¦sÀÉ (0-9)[0]: "; + msg[19] = fp_buf[4]; do { - if(!getdata(y, 0, msg, fp_buf + 4, 4, DOECHO)) + if (!getdata(y, 0, msg, fp_buf + 4, 4, DOECHO)) fp_buf[4] = msg[19]; - } while(fp_buf[4] < '0' || fp_buf[4] > '9'); + } while (fp_buf[4] < '0' || fp_buf[4] > '9'); return fp_buf; } -static void read_tmpbuf(int n) { - FILE *fp; - char fp_tmpbuf[80]; - char tmpfname[] = "buf.0"; - char *tmpf; - char ans[4] = "y"; - - if(0 <= n && n <= 9) { +static void +read_tmpbuf(int n) +{ + FILE *fp; + char fp_tmpbuf[80]; + char tmpfname[] = "buf.0"; + char *tmpf; + char ans[4] = "y"; + + if (0 <= n && n <= 9) { tmpfname[4] = '0' + n; tmpf = tmpfname; } else { tmpf = ask_tmpbuf(3); n = tmpf[4] - '0'; } - + setuserfile(fp_tmpbuf, tmpf); - if(n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) + if (n != 0 && n != 5 && more(fp_tmpbuf, NA) != -1) getdata(b_lines - 1, 0, "½T©wŪ¤J¶Ü(Y/N)?[Y]", ans, sizeof(ans), LCECHO); - if(*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { + if (*ans != 'n' && (fp = fopen(fp_tmpbuf, "r"))) { prevln = currln; prevpnt = currpnt; load_file(fp); - while(curr_window_line >= b_lines) { + while (curr_window_line >= b_lines) { curr_window_line--; top_of_win = top_of_win->next; } } } -static void write_tmpbuf() { - FILE *fp; - char fp_tmpbuf[80], ans[4]; - textline_t *p; +static void +write_tmpbuf() +{ + FILE *fp; + char fp_tmpbuf[80], ans[4]; + textline_t *p; setuserfile(fp_tmpbuf, ask_tmpbuf(3)); - if(dashf(fp_tmpbuf)) { + if (dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "¼È¦sÀɤw¦³¸ê®Æ (A)ªþ¥[ (W)Âмg (Q)¨ú®ø¡H[A] ", ans, sizeof(ans), LCECHO); - - if(ans[0] == 'q') + + if (ans[0] == 'q') return; } - - if((fp = fopen(fp_tmpbuf, (ans[0] == 'w' ? "w" : "a+")))) { - for(p = firstline; p; p = p->next) { - if(p->next || p->data[0]) + if ((fp = fopen(fp_tmpbuf, (ans[0] == 'w' ? "w" : "a+")))) { + for (p = firstline; p; p = p->next) { + if (p->next || p->data[0]) fprintf(fp, "%s\n", p->data); } fclose(fp); } } -static void erase_tmpbuf() { - char fp_tmpbuf[80]; - char ans[4] = "n"; - +static void +erase_tmpbuf() +{ + char fp_tmpbuf[80]; + char ans[4] = "n"; + setuserfile(fp_tmpbuf, ask_tmpbuf(3)); - if(more(fp_tmpbuf, NA) != -1) + if (more(fp_tmpbuf, NA) != -1) getdata(b_lines - 1, 0, "½T©w§R°£¶Ü(Y/N)?[N]", ans, sizeof(ans), LCECHO); - if(*ans == 'y') + if (*ans == 'y') unlink(fp_tmpbuf); } /* ½s¿è¾¹¦Û°Ê³Æ¥÷ */ -void auto_backup() { - if(currline) { - FILE *fp; - textline_t *p, *v; - char bakfile[64]; - int count = 0; - +void +auto_backup() +{ + if (currline) { + FILE *fp; + textline_t *p, *v; + char bakfile[64]; + int count = 0; + setuserfile(bakfile, fp_bak); - if((fp = fopen(bakfile, "w"))) { - for(p = firstline; p != NULL && count < 512; p = v,count++) { + if ((fp = fopen(bakfile, "w"))) { + for (p = firstline; p != NULL && count < 512; p = v, count++) { v = p->next; fprintf(fp, "%s\n", p->data); free(p); @@ -529,15 +574,17 @@ void auto_backup() { } } -void restore_backup() { - char bakfile[80], buf[80]; - +void +restore_backup() +{ + char bakfile[80], buf[80]; + setuserfile(bakfile, fp_bak); - if(dashf(bakfile)) { + if (dashf(bakfile)) { stand_title("½s¿è¾¹¦Û°Ê´_ì"); getdata(1, 0, "±z¦³¤@½g¤å³¹©|¥¼§¹¦¨¡A(S)¼g¤J¼È¦sÀÉ (Q)ºâ¤F¡H[S] ", buf, 4, LCECHO); - if(buf[0] != 'q') { + if (buf[0] != 'q') { setuserfile(buf, ask_tmpbuf(3)); Rename(bakfile, buf); } else @@ -546,87 +593,91 @@ void restore_backup() { } /* ¤Þ¥Î¤å³¹ */ -static int garbage_line(char *str) { - int qlevel = 0; - - while(*str == ':' || *str == '>') { - if(*(++str) == ' ') +static int +garbage_line(char *str) +{ + int qlevel = 0; + + while (*str == ':' || *str == '>') { + if (*(++str) == ' ') str++; - if(qlevel++ >= 1) + if (qlevel++ >= 1) return 1; } - while(*str == ' ' || *str == '\t') + while (*str == ' ' || *str == '\t') str++; - if(qlevel >= 1) { - if(!strncmp(str, "¡° ", 3) || !strncmp(str, "==>", 3) || - strstr(str, ") ´£¨ì:\n")) + if (qlevel >= 1) { + if (!strncmp(str, "¡° ", 3) || !strncmp(str, "==>", 3) || + strstr(str, ") ´£¨ì:\n")) return 1; } return (*str == '\n'); } -static void do_quote() { - int op; - char buf[256]; +static void +do_quote() +{ + int op; + char buf[256]; getdata(b_lines - 1, 0, "½Ð°Ýn¤Þ¥Îì¤å¶Ü(Y/N/All/Repost)¡H[Y] ", buf, 3, LCECHO); op = buf[0]; - - if(op != 'n') { - FILE *inf; - - if((inf = fopen(quote_file, "r"))) { - char *ptr; - int indent_mode0 = indent_mode; - + + if (op != 'n') { + FILE *inf; + + if ((inf = fopen(quote_file, "r"))) { + char *ptr; + int indent_mode0 = indent_mode; + fgets(buf, 256, inf); - if((ptr = strrchr(buf, ')'))) + if ((ptr = strrchr(buf, ')'))) ptr[1] = '\0'; - else if((ptr = strrchr(buf, '\n'))) + else if ((ptr = strrchr(buf, '\n'))) ptr[0] = '\0'; - - if((ptr = strchr(buf, ':'))) { - char *str; - - while(*(++ptr) == ' '); + + if ((ptr = strchr(buf, ':'))) { + char *str; + + while (*(++ptr) == ' '); /* ¶¶¤â²o¦Ï¡A¨ú±o author's address */ - if((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) { + if ((curredit & EDIT_BOTH) && (str = strchr(quote_user, '.'))) { strcpy(++str, ptr); str = strchr(str, ' '); str[0] = '\0'; } } else ptr = quote_user; - + indent_mode = 0; insert_string("¡° ¤Þz¡m"); insert_string(ptr); insert_string("¡n¤§»Ê¨¥¡G\n"); - - if(op != 'a') /* ¥h±¼ header */ - while(fgets(buf, 256, inf) && buf[0] != '\n'); - if(op == 'a') - while(fgets(buf, 256, inf)) { + if (op != 'a') /* ¥h±¼ header */ + while (fgets(buf, 256, inf) && buf[0] != '\n'); + + if (op == 'a') + while (fgets(buf, 256, inf)) { insert_char(':'); insert_char(' '); - insert_string(Ptt_prints(buf,STRIP_ALL)); + insert_string(Ptt_prints(buf, STRIP_ALL)); } - else if(op == 'r') - while(fgets(buf, 256, inf)) - insert_string(Ptt_prints(buf,NO_RELOAD)); + else if (op == 'r') + while (fgets(buf, 256, inf)) + insert_string(Ptt_prints(buf, NO_RELOAD)); else { - if(curredit & EDIT_LIST) /* ¥h±¼ mail list ¤§ header */ + if (curredit & EDIT_LIST) /* ¥h±¼ mail list ¤§ header */ while (fgets(buf, 256, inf) && (!strncmp(buf, "¡° ", 3))); - while(fgets(buf, 256, inf)) { - if(!strcmp(buf, "--\n")) + while (fgets(buf, 256, inf)) { + if (!strcmp(buf, "--\n")) break; - if(!garbage_line(buf)) { + if (!garbage_line(buf)) { insert_char(':'); insert_char(' '); - insert_string(Ptt_prints(buf,STRIP_ALL)); + insert_string(Ptt_prints(buf, STRIP_ALL)); } } } @@ -637,37 +688,39 @@ static void do_quote() { } /* ¼f¬d user ¤Þ¨¥ªº¨Ï¥Î */ -static int check_quote() { +static int +check_quote() +{ register textline_t *p = firstline; - register char *str; - int post_line; - int included_line; - + register char *str; + int post_line; + int included_line; + post_line = included_line = 0; - while(p) { - if(!strcmp(str = p->data, "--")) + while (p) { + if (!strcmp(str = p->data, "--")) break; - if(str[1] == ' ' && ((str[0] == ':') || (str[0] == '>'))) + if (str[1] == ' ' && ((str[0] == ':') || (str[0] == '>'))) included_line++; else { - while(*str == ' ' || *str == '\t') + while (*str == ' ' || *str == '\t') str++; - if(*str) + if (*str) post_line++; } p = p->next; } - - if((included_line >> 2) > post_line) { + + if ((included_line >> 2) > post_line) { move(4, 0); outs("¥»½g¤å³¹ªº¤Þ¨¥¤ñ¨Ò¶W¹L 80%¡A½Ð±z°µ¨Ç·Lªº×¥¿¡G\n\n" "\033[1;33m1) ¼W¥[¤@¨Ç¤å³¹ ©Î 2) §R°£¤£¥²n¤§¤Þ¨¥\033[m"); { - char ans[4]; - + char ans[4]; + getdata(12, 12, "(E)Ä~Äò½s¿è (W)±j¨î¼g¤J¡H[E] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'w') + if (ans[0] == 'w') return 0; } return 1; @@ -676,11 +729,13 @@ static int check_quote() { } /* Àɮ׳B²z¡GŪÀÉ¡B¦sÀÉ¡B¼ÐÃD¡Bñ¦WÀÉ */ -static void read_file(char *fpath) { - FILE *fp; - - if((fp = fopen(fpath, "r")) == NULL) { - if((fp = fopen(fpath, "w+"))) { +static void +read_file(char *fpath) +{ + FILE *fp; + + if ((fp = fopen(fpath, "r")) == NULL) { + if ((fp = fopen(fpath, "w+"))) { fclose(fp); return; } @@ -690,67 +745,69 @@ static void read_file(char *fpath) { load_file(fp); } -void write_header(FILE *fp) { +void +write_header(FILE * fp) +{ - if(curredit & EDIT_MAIL || curredit & EDIT_LIST) { + if (curredit & EDIT_MAIL || curredit & EDIT_LIST) { fprintf(fp, "%s %s (%s)\n", str_author1, cuser.userid, #if defined(REALINFO) && defined(MAIL_REALNAMES) cuser.realname #else cuser.username #endif - ); + ); } else { - char *ptr; + char *ptr; struct { - char author[IDLEN + 1]; - char board[IDLEN + 1]; - char title[66]; - time_t date; /* last post's date */ - int number; /* post number */ - } postlog; - + char author[IDLEN + 1]; + char board[IDLEN + 1]; + char title[66]; + time_t date; /* last post's date */ + int number; /* post number */ + } postlog; + strcpy(postlog.author, cuser.userid); - ifuseanony=0; + ifuseanony = 0; #ifdef HAVE_ANONYMOUS - if(currbrdattr& BRD_ANONYMOUS) { - int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); - if(defanony) + if (currbrdattr & BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + if (defanony) getdata(3, 0, "½Ð¿é¤J§A·Q¥ÎªºID¡A¤]¥iª½±µ«ö[Enter]¡A" - "©Î¬O«ö[r]¥Î¯u¦W¡G", real_name, sizeof(real_name), DOECHO); + "©Î¬O«ö[r]¥Î¯u¦W¡G", real_name, sizeof(real_name), DOECHO); else getdata(3, 0, "½Ð¿é¤J§A·Q¥ÎªºID¡A¤]¥iª½±µ«ö[Enter]¨Ï¥ÎìID¡G", real_name, sizeof(real_name), DOECHO); - if(!real_name[0] && defanony) { + if (!real_name[0] && defanony) { strcpy(real_name, "Anonymous"); strcpy(postlog.author, real_name); ifuseanony = 1; } else { - if(!strcmp("r",real_name) || (!defanony && !real_name[0])) - sprintf(postlog.author,"%s",cuser.userid); + if (!strcmp("r", real_name) || (!defanony && !real_name[0])) + sprintf(postlog.author, "%s", cuser.userid); else { - sprintf(postlog.author,"%s.",real_name); - ifuseanony=1; + sprintf(postlog.author, "%s.", real_name); + ifuseanony = 1; } } } #endif strcpy(postlog.board, currboard); ptr = save_title; - if(!strncmp(ptr, str_reply, 4)) + if (!strncmp(ptr, str_reply, 4)) ptr += 4; strncpy(postlog.title, ptr, 65); postlog.date = now; postlog.number = 1; - append_record(".post", (fileheader_t *)&postlog, sizeof(postlog)); + append_record(".post", (fileheader_t *) & postlog, sizeof(postlog)); #ifdef HAVE_ANONYMOUS - if(currbrdattr & BRD_ANONYMOUS) { - int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); - - fprintf(fp, "%s %s (%s) %s %s\n", str_author1, postlog.author , - (((!strcmp(real_name,"r") && defanony) || + if (currbrdattr & BRD_ANONYMOUS) { + int defanony = (currbrdattr & BRD_DEFAULTANONYMOUS); + + fprintf(fp, "%s %s (%s) %s %s\n", str_author1, postlog.author, + (((!strcmp(real_name, "r") && defanony) || (!real_name[0] && (!defanony))) ? cuser.username : - "²q²q§Ú¬O½Ö ? ^o^"), + "²q²q§Ú¬O½Ö ? ^o^"), local_article ? str_post2 : str_post1, currboard); } else { fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, @@ -761,7 +818,7 @@ void write_header(FILE *fp) { #endif local_article ? str_post2 : str_post1, currboard); } -#else /* HAVE_ANONYMOUS */ +#else /* HAVE_ANONYMOUS */ fprintf(fp, "%s %s (%s) %s %s\n", str_author1, cuser.userid, #if defined(REALINFO) && defined(POSTS_REALNAMES) cuser.realname, @@ -769,43 +826,44 @@ void write_header(FILE *fp) { cuser.username, #endif local_article ? str_post2 : str_post1, currboard); -#endif /* HAVE_ANONYMOUS */ +#endif /* HAVE_ANONYMOUS */ } save_title[72] = '\0'; fprintf(fp, "¼ÐÃD: %s\n®É¶¡: %s\n", save_title, ctime(&now)); } -void addsignature(FILE *fp, int ifuseanony) { - FILE *fs; - int i; - char buf[WRAPMARGIN + 1]; - char fpath[STRLEN]; +void +addsignature(FILE * fp, int ifuseanony) +{ + FILE *fs; + int i; + char buf[WRAPMARGIN + 1]; + char fpath[STRLEN]; - static char msg[] = "½Ð¿ï¾Üñ¦WÀÉ (1-9, 0=¤£¥[)[0]: "; - char ch; + static char msg[] = "½Ð¿ï¾Üñ¦WÀÉ (1-9, 0=¤£¥[)[0]: "; + char ch; - if(!strcmp(cuser.userid,STR_GUEST)) { + if (!strcmp(cuser.userid, STR_GUEST)) { fprintf(fp, "\n--\n¡° µo«H¯¸ :" BBSNAME "(" MYHOSTNAME ") \n¡» From: %s\n", fromhost); return; } - if(!ifuseanony) { + if (!ifuseanony) { i = showsignature(fpath); msg[27] = ch = '0' | (cuser.uflag & SIG_FLAG); getdata(0, 0, msg, buf, 4, DOECHO); - - if(ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { + + if (ch != buf[0] && buf[0] >= '0' && buf[0] <= '9') { ch = buf[0]; cuser.uflag = (cuser.uflag & ~SIG_FLAG) | (ch & SIG_FLAG); } - - if(ch != '0') { + if (ch != '0') { fpath[i] = ch; - if((fs = fopen(fpath, "r"))) { + if ((fs = fopen(fpath, "r"))) { fputs("\n--\n", fp); - for(i = 0; i < MAX_SIGLINES && - fgets(buf, sizeof(buf), fs); i++) + for (i = 0; i < MAX_SIGLINES && + fgets(buf, sizeof(buf), fs); i++) fputs(buf, fp); fclose(fs); } @@ -813,19 +871,19 @@ void addsignature(FILE *fp, int ifuseanony) { } #ifdef HAVE_ORIGIN #ifdef HAVE_ANONYMOUS - if(ifuseanony) + if (ifuseanony) fprintf(fp, "\n--\n¡° µo«H¯¸: " BBSNAME "(" MYHOSTNAME ") \n¡» From: %s\n", "¼Ê¦W¤Ñ¨Ïªº®a"); else { - char temp[33]; - + char temp[33]; + strncpy(temp, fromhost, 31); temp[32] = '\0'; fprintf(fp, "\n--\n¡° µo«H¯¸: " BBSNAME "(" MYHOSTNAME ") \n¡» From: %s\n", temp); } #else - strncpy (temp,fromhost,15); + strncpy(temp, fromhost, 15); fprintf(fp, "\n--\n¡° µo«H¯¸: " BBSNAME "(" MYHOSTNAME ") \n¡» From: %s\n", temp); #endif @@ -833,30 +891,31 @@ void addsignature(FILE *fp, int ifuseanony) { } static int -write_file(char *fpath, int saveheader, int *islocal) { - struct tm *ptime; - FILE *fp = NULL; - textline_t *p, *v; - char ans[TTLEN], *msg; - int aborted = 0, line = 0, checksum[3], sum = 0, po = 1; +write_file(char *fpath, int saveheader, int *islocal) +{ + struct tm *ptime; + FILE *fp = NULL; + textline_t *p, *v; + char ans[TTLEN], *msg; + int aborted = 0, line = 0, checksum[3], sum = 0, po = 1; stand_title("Àɮ׳B²z"); - if(currstat == SMAIL) + if (currstat == SMAIL) msg = "[S]Àx¦s (A)©ñ±ó (T)§ï¼ÐÃD (E)Ä~Äò (R/W/D)Ū¼g§R¼È¦sÀÉ¡H"; - else if(local_article) + else if (local_article) msg = "[L]¯¸¤º«H¥ó (S)Àx¦s (A)©ñ±ó (T)§ï¼ÐÃD (E)Ä~Äò " "(R/W/D)Ū¼g§R¼È¦sÀÉ¡H"; else msg = "[S]Àx¦s (L)¯¸¤º«H¥ó (A)©ñ±ó (T)§ï¼ÐÃD (E)Ä~Äò " "(R/W/D)Ū¼g§R¼È¦sÀÉ¡H"; getdata(1, 0, msg, ans, 2, LCECHO); - - switch(ans[0]) { + + switch (ans[0]) { case 'a': outs("¤å³¹\033[1m ¨S¦³ \033[m¦s¤J"); safe_sleep(1); aborted = -1; - break; + break; case 'r': read_tmpbuf(-1); case 'e': @@ -870,12 +929,12 @@ write_file(char *fpath, int saveheader, int *islocal) { case 't': move(3, 0); prints("¼ÐÃD¡G%s", save_title); - strcpy(ans,save_title); - if(getdata_buf(4, 0, "·s¼ÐÃD¡G", ans, sizeof(ans), DOECHO)) + strcpy(ans, save_title); + if (getdata_buf(4, 0, "·s¼ÐÃD¡G", ans, sizeof(ans), DOECHO)) strcpy(save_title, ans); return KEEP_EDITING; case 's': - if(!HAS_PERM(PERM_LOGINOK)) { + if (!HAS_PERM(PERM_LOGINOK)) { local_article = 1; move(2, 0); prints("±z©|¥¼³q¹L¨¥÷½T»{¡A¥u¯à Local Save¡C\n"); @@ -887,93 +946,87 @@ write_file(char *fpath, int saveheader, int *islocal) { local_article = 1; } - if(!aborted) { - if(saveheader && !(curredit & EDIT_MAIL) && check_quote()) + if (!aborted) { + if (saveheader && !(curredit & EDIT_MAIL) && check_quote()) return KEEP_EDITING; - - if(!*fpath) { + + if (!*fpath) { sethomepath(fpath, cuser.userid); strcpy(fpath, tempnam(fpath, "ve_")); } - - if((fp = fopen(fpath, "w")) == NULL) { + if ((fp = fopen(fpath, "w")) == NULL) { indigestion(5); abort_bbs(0); } - if(saveheader) + if (saveheader) write_header(fp); } - - for(p = firstline; p; p = v) { + for (p = firstline; p; p = v) { v = p->next; - if(!aborted) { + if (!aborted) { msg = p->data; - if(v || msg[0]) { + if (v || msg[0]) { trim(msg); - + line++; - if(currstat == POSTING && po) { + if (currstat == POSTING && po) { saveheader = str_checksum(msg); - if(saveheader) { - if(postrecord.checksum[po] == saveheader) { + if (saveheader) { + if (postrecord.checksum[po] == saveheader) { po++; - if(po > 3) { + if (po > 3) { postrecord.times++; - po =0; + po = 0; } } else po = 1; - if(currstat == POSTING && line >= totaln/2 && - sum < 3) { + if (currstat == POSTING && line >= totaln / 2 && + sum < 3) { checksum[sum++] = saveheader; } } } #ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - { - fprintf(fp, "%s\n", hc_convert_str(msg, HC_GBtoBIG, HC_DO_SINGLE)); - } - else + if (current_font_type == TYPE_GB) { + fprintf(fp, "%s\n", hc_convert_str(msg, HC_GBtoBIG, HC_DO_SINGLE)); + } else #endif - fprintf(fp, "%s\n", msg); + fprintf(fp, "%s\n", msg); } } free(p); } currline = NULL; - - if(postrecord.times > MAX_CROSSNUM - 1) + + if (postrecord.times > MAX_CROSSNUM - 1) anticrosspost(); - - if(po && sum == 3) { + + if (po && sum == 3) { memcpy(&postrecord.checksum[1], checksum, sizeof(int) * 3); - postrecord.times =0; + postrecord.times = 0; } - if(!aborted) { - if(islocal) + if (!aborted) { + if (islocal) *islocal = (local_article == 1); - if(currstat == POSTING || currstat == SMAIL) - addsignature(fp,ifuseanony); - else if(currstat == REEDIT + if (currstat == POSTING || currstat == SMAIL) + addsignature(fp, ifuseanony); + else if (currstat == REEDIT #ifndef ALL_REEDIT_LOG - && strcmp(currboard, "SYSOP") == 0 + && strcmp(currboard, "SYSOP") == 0 #endif - ) - { + ) { ptime = localtime(&now); - fprintf(fp, - "¡° ½s¿è: %-15s ¨Ó¦Û: %-20s (%02d/%02d %02d:%02d)\n", - cuser.userid, fromhost, - ptime->tm_mon+1,ptime->tm_mday,ptime->tm_hour,ptime->tm_min); - } - + fprintf(fp, + "¡° ½s¿è: %-15s ¨Ó¦Û: %-20s (%02d/%02d %02d:%02d)\n", + cuser.userid, fromhost, + ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour, ptime->tm_min); + } fclose(fp); #ifdef MDCACHE close(updatemdcache(NULL, fpath)); #endif - if(local_article && (currstat == POSTING)) + if (local_article && (currstat == POSTING)) return 0; return 0; } @@ -981,14 +1034,16 @@ write_file(char *fpath, int saveheader, int *islocal) { } -static void display_buffer() { +static void +display_buffer() +{ register textline_t *p; - register int i; - int inblock; - char buf[WRAPMARGIN + 2]; - int min, max; - - if(currpnt > blockpnt) { + register int i; + int inblock; + char buf[WRAPMARGIN + 2]; + int min, max; + + if (currpnt > blockpnt) { min = blockpnt; max = currpnt; } else { @@ -996,21 +1051,21 @@ static void display_buffer() { max = blockpnt; } - for(p = top_of_win, i = 0; i < b_lines; i++) { + for (p = top_of_win, i = 0; i < b_lines; i++) { move(i, 0); clrtoeol(); - if(blockln >= 0 && - ((blockln <= currln && blockln <= (currln - curr_window_line + i) && - (currln - curr_window_line + i) <= currln) || - (currln <= (currln - curr_window_line + i) && - (currln - curr_window_line + i) <= blockln))) { + if (blockln >= 0 && + ((blockln <= currln && blockln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= currln) || + (currln <= (currln - curr_window_line + i) && + (currln - curr_window_line + i) <= blockln))) { outs("\033[7m"); inblock = 1; } else inblock = 0; - if(p) { - if(my_ansimode) - if(currln == blockln && p == currline && max > min) { + if (p) { + if (my_ansimode) + if (currln == blockln && p == currline && max > min) { outs("\033[m"); strncpy(buf, p->data, min); buf[min] = 0; @@ -1023,21 +1078,21 @@ static void display_buffer() { outs(p->data + max); } else outs(p->data); - else if(currln == blockln && p == currline && max > min) { + else if (currln == blockln && p == currline && max > min) { outs("\033[m"); - strncpy(buf, p->data, min); - buf[min] = 0; - edit_outs(buf); - outs("\033[7m"); - strncpy(buf, p->data + min, max - min); - buf[max - min] = 0; - edit_outs(buf); - outs("\033[m"); - edit_outs(p->data + max); - } else - edit_outs(&p->data[edit_margin]); + strncpy(buf, p->data, min); + buf[min] = 0; + edit_outs(buf); + outs("\033[7m"); + strncpy(buf, p->data + min, max - min); + buf[max - min] = 0; + edit_outs(buf); + outs("\033[m"); + edit_outs(p->data + max); + } else + edit_outs(&p->data[edit_margin]); p = p->next; - if(inblock) + if (inblock) outs("\033[m"); } else outch('~'); @@ -1045,51 +1100,55 @@ static void display_buffer() { edit_msg(); } -static void goto_line(int lino) { - char buf[10]; - - if(lino > 0 || - (getdata(b_lines - 1, 0, "¸õ¦Ü²Ä´X¦æ:", buf, sizeof(buf), DOECHO) && - sscanf(buf, "%d", &lino) && lino > 0)) { - textline_t* p; - +static void +goto_line(int lino) +{ + char buf[10]; + + if (lino > 0 || + (getdata(b_lines - 1, 0, "¸õ¦Ü²Ä´X¦æ:", buf, sizeof(buf), DOECHO) && + sscanf(buf, "%d", &lino) && lino > 0)) { + textline_t *p; + prevln = currln; prevpnt = currpnt; p = firstline; currln = lino - 1; - - while(--lino && p->next) + + while (--lino && p->next) p = p->next; - - if(p) + + if (p) currline = p; else { currln = totaln; currline = lastline; } currpnt = 0; - if(currln < 11) { + if (currln < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; - top_of_win = p; + top_of_win = p; } } redraw_everything = YEA; } -char *strcasestr(const char* big, const char* little) { - char* ans = (char*)big; - int len = strlen(little); - char* endptr = (char*)big + strlen(big) - len; - - while(ans <= endptr) - if(!strncasecmp(ans, little, len)) +char * +strcasestr(const char *big, const char *little) +{ + char *ans = (char *)big; + int len = strlen(little); + char *endptr = (char *)big + strlen(big) - len; + + while (ans <= endptr) + if (!strncasecmp(ans, little, len)) return ans; else ans++; @@ -1097,181 +1156,181 @@ char *strcasestr(const char* big, const char* little) { } /* - mode: - 0: prompt - 1: forward - -1: backward -*/ -static void search_str(int mode) { - static char str[65]; - typedef char* (*FPTR)(); - static FPTR fptr; - char ans[4] = "n"; - - if(!mode) { - if(getdata_buf(b_lines - 1, 0,"[·j´M]ÃöÁä¦r:", - str, sizeof(str), DOECHO)) - if(*str) { - if(getdata(b_lines - 1, 0, "°Ï¤À¤j¤p¼g(Y/N/Q)? [N] ", - ans, sizeof(ans), LCECHO) && *ans == 'y') + * mode: 0: prompt 1: forward -1: backward + */ +static void +search_str(int mode) +{ + static char str[65]; + typedef char *(*FPTR) (); + static FPTR fptr; + char ans[4] = "n"; + + if (!mode) { + if (getdata_buf(b_lines - 1, 0, "[·j´M]ÃöÁä¦r:", + str, sizeof(str), DOECHO)) + if (*str) { + if (getdata(b_lines - 1, 0, "°Ï¤À¤j¤p¼g(Y/N/Q)? [N] ", + ans, sizeof(ans), LCECHO) && *ans == 'y') fptr = strstr; else fptr = strcasestr; } } - - if(*str && *ans != 'q') { - textline_t* p; - char *pos = NULL; - int lino; - - if(mode >= 0) { - for(lino = currln, p = currline; p; p = p->next, lino++) - if((pos = fptr(p->data + (lino == currln ? currpnt + 1 : 0), - str)) && (lino != currln || - pos - p->data != currpnt)) + if (*str && *ans != 'q') { + textline_t *p; + char *pos = NULL; + int lino; + + if (mode >= 0) { + for (lino = currln, p = currline; p; p = p->next, lino++) + if ((pos = fptr(p->data + (lino == currln ? currpnt + 1 : 0), + str)) && (lino != currln || + pos - p->data != currpnt)) break; } else { - for(lino = currln, p = currline; p; p = p->prev, lino--) - if((pos = fptr(p->data, str)) && - (lino != currln || pos - p->data != currpnt)) + for (lino = currln, p = currline; p; p = p->prev, lino--) + if ((pos = fptr(p->data, str)) && + (lino != currln || pos - p->data != currpnt)) break; } - if(pos) { + if (pos) { prevln = currln; prevpnt = currpnt; currline = p; currln = lino; currpnt = pos - p->data; - if(lino < 11) { + if (lino < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; top_of_win = p; } redraw_everything = YEA; } } - if(!mode) + if (!mode) redraw_everything = YEA; } -static void match_paren() { - static char parens[] = "()[]{}"; - int type; - int parenum = 0; - char *ptype; - textline_t* p; - int lino; - int c, i = 0; - - if(!(ptype = strchr(parens, currline->data[currpnt]))) +static void +match_paren() +{ + static char parens[] = "()[]{}"; + int type; + int parenum = 0; + char *ptype; + textline_t *p; + int lino; + int c, i = 0; + + if (!(ptype = strchr(parens, currline->data[currpnt]))) return; - + type = (ptype - parens) / 2; parenum += ((ptype - parens) % 2) ? -1 : 1; - - if(parenum > 0) { - for(lino = currln, p = currline; p; p = p->next, lino++) { + + if (parenum > 0) { + for (lino = currln, p = currline; p; p = p->next, lino++) { lino = lino; - for(i = (lino == currln) ? currpnt + 1 : 0; - i < strlen(p->data); i++) - if(p->data[i] == '/' && p->data[++i] == '*') { + for (i = (lino == currln) ? currpnt + 1 : 0; + i < strlen(p->data); i++) + if (p->data[i] == '/' && p->data[++i] == '*') { ++i; - while(1) { - while(i < strlen(p->data) - 1 && - !(p->data[i] == '*' && p->data[i + 1] == '/')) + while (1) { + while (i < strlen(p->data) - 1 && + !(p->data[i] == '*' && p->data[i + 1] == '/')) i++; - if(i >= strlen(p->data) - 1 && p->next) { + if (i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = 0; } else break; } - } else if((c = p->data[i]) == '\'' || c == '"') { - while(1) { - while(i < (int)(strlen(p->data) - 1)) - if(p->data[++i] == '\\' && i < strlen(p->data) - 2) + } else if ((c = p->data[i]) == '\'' || c == '"') { + while (1) { + while (i < (int)(strlen(p->data) - 1)) + if (p->data[++i] == '\\' && i < strlen(p->data) - 2) ++i; - else if(p->data[i] == c) + else if (p->data[i] == c) goto end_quote; - if(i >= strlen(p->data) - 1 && p->next) { + if (i >= strlen(p->data) - 1 && p->next) { p = p->next; ++lino; i = -1; } else break; } -end_quote: + end_quote: ; - } else if((ptype = strchr(parens, p->data[i])) && - (ptype - parens) / 2 == type) - if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + } else if ((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if (!(parenum += ((ptype - parens) % 2) ? -1 : 1)) goto p_outscan; } } else { - for(lino = currln, p = currline; p; p = p->prev, lino--) - for(i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; + for (lino = currln, p = currline; p; p = p->prev, lino--) + for (i = (lino == currln) ? currpnt - 1 : strlen(p->data) - 1; i >= 0; i--) - if(p->data[i] == '/' && p->data[--i] == '*' && i > 0) { + if (p->data[i] == '/' && p->data[--i] == '*' && i > 0) { --i; - while(1) { - while(i > 0 && - !(p->data[i] == '*' && p->data[i - 1] == '/')) + while (1) { + while (i > 0 && + !(p->data[i] == '*' && p->data[i - 1] == '/')) i--; - if(i <= 0 && p->prev) { + if (i <= 0 && p->prev) { p = p->prev; --lino; i = strlen(p->data) - 1; } else break; } - } else if((c = p->data[i]) == '\'' || c == '"') { - while(1) { - while(i > 0) - if(i > 1 && p->data[i - 2] == '\\') + } else if ((c = p->data[i]) == '\'' || c == '"') { + while (1) { + while (i > 0) + if (i > 1 && p->data[i - 2] == '\\') i -= 2; - else if((p->data[--i]) == c) + else if ((p->data[--i]) == c) goto begin_quote; - if(i <= 0 && p->prev) { + if (i <= 0 && p->prev) { p = p->prev; --lino; i = strlen(p->data); } else break; } -begin_quote: + begin_quote: ; - } else if((ptype = strchr(parens, p->data[i])) && - (ptype - parens) / 2 == type) - if(!(parenum += ((ptype - parens) % 2) ? -1 : 1)) + } else if ((ptype = strchr(parens, p->data[i])) && + (ptype - parens) / 2 == type) + if (!(parenum += ((ptype - parens) % 2) ? -1 : 1)) goto p_outscan; } p_outscan: - if(!parenum) { - int top = currln - curr_window_line; - int bottom = currln - curr_window_line + b_lines - 1; - + if (!parenum) { + int top = currln - curr_window_line; + int bottom = currln - curr_window_line + b_lines - 1; + currpnt = i; currline = p; curr_window_line += lino - currln; currln = lino; - - if(lino < top || lino > bottom) { - if(lino < 11) { + + if (lino < top || lino > bottom) { + if (lino < 11) { top_of_win = firstline; curr_window_line = currln; } else { - int i; + int i; curr_window_line = 11; - for(i = curr_window_line; i; i--) + for (i = curr_window_line; i; i--) p = p->prev; top_of_win = p; } @@ -1280,58 +1339,60 @@ p_outscan: } } -static void block_del(int hide) { - if(blockln < 0) { +static void +block_del(int hide) +{ + if (blockln < 0) { blockln = currln; blockpnt = currpnt; blockline = currline; } else { - char fp_tmpbuf[80]; - FILE* fp; - textline_t *begin, *end, *p; - char tmpfname[10] = "buf.0"; - char ans[6] = "w+n"; + char fp_tmpbuf[80]; + FILE *fp; + textline_t *begin, *end, *p; + char tmpfname[10] = "buf.0"; + char ans[6] = "w+n"; move(b_lines - 1, 0); clrtoeol(); - if(hide == 1) + if (hide == 1) tmpfname[4] = 'q'; - else if(!hide && !getdata(b_lines - 1, 0, "§â°Ï¶ô²¾¦Ü¼È¦sÀÉ " - "(0:Cut, 5:Copy, 6-9, q: Cancel)[0] ", - tmpfname + 4, 4, LCECHO)) + else if (!hide && !getdata(b_lines - 1, 0, "§â°Ï¶ô²¾¦Ü¼È¦sÀÉ " + "(0:Cut, 5:Copy, 6-9, q: Cancel)[0] ", + tmpfname + 4, 4, LCECHO)) tmpfname[4] = '0'; - if(tmpfname[4] < '0' || tmpfname[4] > '9') + if (tmpfname[4] < '0' || tmpfname[4] > '9') tmpfname[4] = 'q'; - if('1' <= tmpfname[4] && tmpfname[4] <= '9') { + if ('1' <= tmpfname[4] && tmpfname[4] <= '9') { setuserfile(fp_tmpbuf, tmpfname); - if(tmpfname[4] != '5' && dashf(fp_tmpbuf)) { + if (tmpfname[4] != '5' && dashf(fp_tmpbuf)) { more(fp_tmpbuf, NA); getdata(b_lines - 1, 0, "¼È¦sÀɤw¦³¸ê®Æ (A)ªþ¥[ (W)Âмg " "(Q)¨ú®ø¡H[W] ", ans, 2, LCECHO); - if(*ans == 'q') + if (*ans == 'q') tmpfname[4] = 'q'; - else if(*ans != 'a') + else if (*ans != 'a') *ans = 'w'; } - if(tmpfname[4] != '5') { + if (tmpfname[4] != '5') { getdata(b_lines - 1, 0, "§R°£°Ï¶ô(Y/N)?[N] ", ans + 2, 4, LCECHO); - if(ans[2] != 'y') + if (ans[2] != 'y') ans[2] = 'n'; } - } else if(hide != 3) + } else if (hide != 3) ans[2] = 'y'; - + tmpfname[5] = ans[1] = ans[3] = 0; - if(tmpfname[4] != 'q') { - if(currln >= blockln) { + if (tmpfname[4] != 'q') { + if (currln >= blockln) { begin = blockline; end = currline; - if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + if (ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { curr_window_line -= (currln - blockln); - if(curr_window_line < 0) { + if (curr_window_line < 0) { curr_window_line = 0; - if(end->next) + if (end->next) (top_of_win = end->next)->prev = begin->prev; else top_of_win = (lastline = begin->prev); @@ -1342,33 +1403,32 @@ static void block_del(int hide) { begin = currline; end = blockline; } - if(ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { - if(begin->prev) + if (ans[2] == 'y' && !(begin == end && currpnt != blockpnt)) { + if (begin->prev) begin->prev->next = end->next; - else if(end->next) + else if (end->next) top_of_win = firstline = end->next; else { currline = top_of_win = firstline = lastline = alloc_line(); currln = curr_window_line = edit_margin = 0; } - - if(end->next) + + if (end->next) (currline = end->next)->prev = begin->prev; - else if(begin->prev) { + else if (begin->prev) { currline = (lastline = begin->prev); currln--; - if(curr_window_line > 0) + if (curr_window_line > 0) curr_window_line--; } } - setuserfile(fp_tmpbuf, tmpfname); - if((fp = fopen(fp_tmpbuf, ans))) { - if(begin == end && currpnt != blockpnt) { - char buf[WRAPMARGIN + 2]; - - if(currpnt > blockpnt) { + if ((fp = fopen(fp_tmpbuf, ans))) { + if (begin == end && currpnt != blockpnt) { + char buf[WRAPMARGIN + 2]; + + if (currpnt > blockpnt) { strcpy(buf, begin->data + blockpnt); buf[currpnt - blockpnt] = 0; } else { @@ -1377,18 +1437,17 @@ static void block_del(int hide) { } fputs(buf, fp); } else { - for(p = begin; p != end; p = p->next) + for (p = begin; p != end; p = p->next) fprintf(fp, "%s\n", p->data); fprintf(fp, "%s\n", end->data); } fclose(fp); } - - if(ans[2] == 'y') { - if(begin == end && currpnt != blockpnt) { - int min, max; - - if(currpnt > blockpnt) { + if (ans[2] == 'y') { + if (begin == end && currpnt != blockpnt) { + int min, max; + + if (currpnt > blockpnt) { min = blockpnt; max = currpnt; } else { @@ -1399,7 +1458,7 @@ static void block_del(int hide) { begin->len -= max - min; currpnt = min; } else { - for(p = begin; p != end; totaln--) + for (p = begin; p != end; totaln--) free((p = p->next)->prev); free(end); totaln--; @@ -1412,10 +1471,12 @@ static void block_del(int hide) { } } -static void block_shift_left() { - textline_t *begin, *end, *p; - - if(currln >= blockln) { +static void +block_shift_left() +{ + textline_t *begin, *end, *p; + + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1423,25 +1484,27 @@ static void block_shift_left() { end = blockline; } p = begin; - while(1) { - if(p->len) { + while (1) { + if (p->len) { strcpy(p->data, p->data + 1); --p->len; } - if(p == end) + if (p == end) break; else p = p->next; } - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; } -static void block_shift_right() { - textline_t *begin, *end, *p; +static void +block_shift_right() +{ + textline_t *begin, *end, *p; - if(currln >= blockln) { + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1449,38 +1512,42 @@ static void block_shift_right() { end = blockline; } p = begin; - while(1) { - if(p->len < WRAPMARGIN) { - int i = p->len + 1; - - while(i--) + while (1) { + if (p->len < WRAPMARGIN) { + int i = p->len + 1; + + while (i--) p->data[i + 1] = p->data[i]; p->data[0] = insert_character ? ' ' : insert_c; ++p->len; } - if(p == end) + if (p == end) break; else p = p->next; } - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; } -static void transform_to_color(char* line) { - while(line[0] && line[1]) - if(line[0] == '*' && line[1] == '[') { +static void +transform_to_color(char *line) +{ + while (line[0] && line[1]) + if (line[0] == '*' && line[1] == '[') { line[0] = KEY_ESC; line += 2; } else ++line; } -static void block_color() { - textline_t *begin, *end, *p; - - if(currln >= blockln) { +static void +block_color() +{ + textline_t *begin, *end, *p; + + if (currln >= blockln) { begin = blockline; end = currline; } else { @@ -1488,9 +1555,9 @@ static void block_color() { end = blockline; } p = begin; - while(1) { + while (1) { transform_to_color(p->data); - if(p == end) + if (p == end) break; else p = p->next; @@ -1499,96 +1566,95 @@ static void block_color() { } /* ½s¿è³B²z¡G¥Dµ{¦¡¡BÁä½L³B²z */ -int vedit(char *fpath, int saveheader, int *islocal) { - FILE *fp1; - char last = 0, buf[200]; /* the last key you press */ - int ch, foo; - int lastindent = -1; - int last_margin; - int mode0 = currutmp->mode; - int destuid0 = currutmp->destuid; - unsigned int money=0; - int interval=0; - time_t th=now; - - textline_t* firstline0 = firstline; - textline_t* lastline0 = lastline; - textline_t* currline0 = currline; - textline_t* blockline0 = blockline; - textline_t* top_of_win0 = top_of_win; - int local_article0 = local_article; - int currpnt0 = currpnt; - int currln0 = currln; - int totaln0 = totaln; - int curr_window_line0 = curr_window_line; - int insert_character0 = insert_character; - int my_ansimode0 = my_ansimode; - int edit_margin0 = edit_margin; - int blockln0 = blockln, count=0, tin=0; - +int +vedit(char *fpath, int saveheader, int *islocal) +{ + FILE *fp1; + char last = 0, buf[200]; /* the last key you press */ + int ch, foo; + int lastindent = -1; + int last_margin; + int mode0 = currutmp->mode; + int destuid0 = currutmp->destuid; + unsigned int money = 0; + int interval = 0; + time_t th = now; + + textline_t *firstline0 = firstline; + textline_t *lastline0 = lastline; + textline_t *currline0 = currline; + textline_t *blockline0 = blockline; + textline_t *top_of_win0 = top_of_win; + int local_article0 = local_article; + int currpnt0 = currpnt; + int currln0 = currln; + int totaln0 = totaln; + int curr_window_line0 = curr_window_line; + int insert_character0 = insert_character; + int my_ansimode0 = my_ansimode; + int edit_margin0 = edit_margin; + int blockln0 = blockln, count = 0, tin = 0; + currutmp->mode = EDITING; currutmp->destuid = currstat; insert_character = redraw_everything = 1; prevln = blockln = -1; - + line_dirty = currpnt = totaln = my_ansimode = 0; currline = top_of_win = firstline = lastline = alloc_line(); - - if(*fpath) + + if (*fpath) read_file(fpath); - if(*quote_file) { + if (*quote_file) { do_quote(); *quote_file = '\0'; - if(quote_file[79] == 'L') + if (quote_file[79] == 'L') local_article = 1; } - currline = firstline; currpnt = currln = curr_window_line = edit_margin = last_margin = 0; - - while(1) { - if(redraw_everything || blockln >= 0) { + + while (1) { + if (redraw_everything || blockln >= 0) { display_buffer(); redraw_everything = NA; } - if(my_ansimode) + if (my_ansimode) ch = n2ansi(currpnt, currline); else ch = currpnt - edit_margin; move(curr_window_line, ch); - if(!line_dirty && strcmp(line, currline->data)) + if (!line_dirty && strcmp(line, currline->data)) strcpy(line, currline->data); ch = igetkey(); - /* jochang debug */ - if((interval = (now - th))) { - th=now; - if((char)ch != last) { + /* jochang debug */ + if ((interval = (now - th))) { + th = now; + if ((char)ch != last) { money++; last = (char)ch; } - } - if(interval && interval == tin) - count++; - else - { - count=0; - tin = interval; - } - /* ³sÄò240Óinterval¤@¼Ë , ¤À©ú¬O¦bÀÄ°] */ - if(count >= 240) { + } + if (interval && interval == tin) + count++; + else { + count = 0; + tin = interval; + } + /* ³sÄò240Óinterval¤@¼Ë , ¤À©ú¬O¦bÀÄ°] */ + if (count >= 240) { sprintf(buf, "\033[1;33;46m%s\033[37m¦b\033[37;45m%s" "\033[37mªO¹HªkÁÈ¿ú , %s\033[m", cuser.userid, - currboard,ctime(&now)); - log_file ("etc/illegal_money",buf); - money = 0 ; + currboard, ctime(&now)); + log_file("etc/illegal_money", buf); + money = 0; post_violatelaw(cuser.userid, "Ptt ¨t²Îĵ¹î", "¹HªkÁÈ¿ú", "¦©°£¤£ªk©Ò±o"); mail_violatelaw(cuser.userid, "Ptt ¨t²Îĵ¹î", "¹HªkÁÈ¿ú", "¦©°£¤£ªk©Ò±o"); -// demoney(10000); -// abort_bbs(0); + //demoney(10000); + //abort_bbs(0); } - - if(raw_mode) + if (raw_mode) switch (ch) { case Ctrl('S'): case Ctrl('Q'): @@ -1596,19 +1662,19 @@ int vedit(char *fpath, int saveheader, int *islocal) { continue; break; } - if(ch < 0x100 && isprint2(ch)) { + if (ch < 0x100 && isprint2(ch)) { insert_char(ch); lastindent = -1; line_dirty = 1; } else { - if(ch == Ctrl('P') || ch == KEY_UP || ch == KEY_DOWN || - ch == Ctrl('N')) { - if(lastindent == -1) + if (ch == Ctrl('P') || ch == KEY_UP || ch == KEY_DOWN || + ch == Ctrl('N')) { + if (lastindent == -1) lastindent = currpnt; } else lastindent = -1; - if(ch == KEY_ESC) - switch(KEY_ESC_arg) { + if (ch == KEY_ESC) + switch (KEY_ESC_arg) { case ',': ch = Ctrl(']'); break; @@ -1639,10 +1705,10 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; } - switch(ch) { - case Ctrl('X'): /* Save and exit */ + switch (ch) { + case Ctrl('X'): /* Save and exit */ foo = write_file(fpath, saveheader, islocal); - if(foo != KEEP_EDITING) { + if (foo != KEEP_EDITING) { currutmp->mode = mode0; currutmp->destuid = destuid0; firstline = firstline0; @@ -1659,7 +1725,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { my_ansimode = my_ansimode0; edit_margin = edit_margin0; blockln = blockln0; - if(!foo) + if (!foo) return money; else return foo; @@ -1668,13 +1734,13 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; break; case Ctrl('W'): - if(blockln >= 0) + if (blockln >= 0) block_del(2); line_dirty = 1; break; - case Ctrl('Q'): /* Quit without saving */ + case Ctrl('Q'): /* Quit without saving */ ch = ask("µ²§ô¦ý¤£Àx¦s (Y/N)? [N]: "); - if(ch == 'y' || ch == 'Y') { + if (ch == 'y' || ch == 'Y') { currutmp->mode = mode0; currutmp->destuid = destuid0; firstline = firstline0; @@ -1699,36 +1765,36 @@ int vedit(char *fpath, int saveheader, int *islocal) { case Ctrl('C'): ch = insert_character; insert_character = redraw_everything = YEA; - if(!my_ansimode) + if (!my_ansimode) insert_string(reset_color); else { - char ans[4]; + char ans[4]; move(b_lines - 2, 55); outs("\033[1;33;40mB\033[41mR\033[42mG\033[43mY\033[44mL" "\033[45mP\033[46mC\033[47mW\033[m"); - if(getdata(b_lines - 1, 0, - "½Ð¿é¤J «G«×/«e´º/I´º[¥¿±`¥Õ¦r¶Â©³][0wb]¡G", - ans, sizeof(ans), LCECHO)) { - char t[] = "BRGYLPCW"; - char color[15]; - char *tmp, *apos = ans; - int fg, bg; - + if (getdata(b_lines - 1, 0, + "½Ð¿é¤J «G«×/«e´º/I´º[¥¿±`¥Õ¦r¶Â©³][0wb]¡G", + ans, sizeof(ans), LCECHO)) { + char t[] = "BRGYLPCW"; + char color[15]; + char *tmp, *apos = ans; + int fg, bg; + strcpy(color, "\033["); - if(isdigit(*apos)) { + if (isdigit(*apos)) { sprintf(color, "%s%c", color, *(apos++)); - if(*apos) + if (*apos) sprintf(color, "%s;", color); } - if(*apos) { - if((tmp = strchr(t, toupper(*(apos++))))) + if (*apos) { + if ((tmp = strchr(t, toupper(*(apos++))))) fg = tmp - t + 30; else fg = 37; sprintf(color, "%s%d", color, fg); } - if(*apos) { - if((tmp = strchr(t, toupper(*(apos++))))) + if (*apos) { + if ((tmp = strchr(t, toupper(*(apos++))))) bg = tmp - t + 40; else bg = 40; @@ -1744,7 +1810,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; case KEY_ESC: line_dirty = 0; - switch(KEY_ESC_arg) { + switch (KEY_ESC_arg) { case 'U': t_users(); redraw_everything = YEA; @@ -1781,18 +1847,18 @@ int vedit(char *fpath, int saveheader, int *islocal) { read_tmpbuf(KEY_ESC_arg - '0'); redraw_everything = YEA; break; - case 'l': /* block delete */ + case 'l': /* block delete */ case ' ': block_del(0); line_dirty = 1; break; case 'u': - if(blockln >= 0) + if (blockln >= 0) block_del(1); line_dirty = 1; break; case 'c': - if(blockln >= 0) + if (blockln >= 0) block_del(3); line_dirty = 1; break; @@ -1808,26 +1874,26 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case 'j': - if(blockln >= 0) + if (blockln >= 0) block_shift_left(); - else if(currline->len) { - int currpnt0 = currpnt; + else if (currline->len) { + int currpnt0 = currpnt; currpnt = 0; delete_char(); - currpnt = (currpnt0 <= currline->len) ? currpnt0 : + currpnt = (currpnt0 <= currline->len) ? currpnt0 : currpnt0 - 1; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(n2ansi(currpnt, currline), currline); } line_dirty = 1; break; case 'k': - if(blockln >= 0) + if (blockln >= 0) block_shift_right(); else { - int currpnt0 = currpnt; - + int currpnt0 = currpnt; + currpnt = 0; insert_char(' '); currpnt = currpnt0; @@ -1835,26 +1901,26 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case 'f': - while(currpnt < currline->len && - isalnum(currline->data[++currpnt])); - while(currpnt < currline->len && - isspace(currline->data[++currpnt])); + while (currpnt < currline->len && + isalnum(currline->data[++currpnt])); + while (currpnt < currline->len && + isspace(currline->data[++currpnt])); line_dirty = 1; break; case 'b': - while(currpnt && isalnum(currline->data[--currpnt])); - while(currpnt && isspace(currline->data[--currpnt])); + while (currpnt && isalnum(currline->data[--currpnt])); + while (currpnt && isspace(currline->data[--currpnt])); line_dirty = 1; break; case 'd': - while(currpnt < currline->len) { + while (currpnt < currline->len) { delete_char(); - if(!isalnum(currline->data[currpnt])) + if (!isalnum(currline->data[currpnt])) break; } - while(currpnt < currline->len) { + while (currpnt < currline->len) { delete_char(); - if(!isspace(currline->data[currpnt])) + if (!isspace(currline->data[currpnt])) break; } line_dirty = 1; @@ -1864,9 +1930,9 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case Ctrl('_'): - if(strcmp(line, currline->data)) { - char buf[WRAPMARGIN]; - + if (strcmp(line, currline->data)) { + char buf[WRAPMARGIN]; + strcpy(buf, currline->data); strcpy(currline->data, line); strcpy(line, buf); @@ -1882,9 +1948,9 @@ int vedit(char *fpath, int saveheader, int *islocal) { insert_char('\033'); line_dirty = 1; break; - case Ctrl('V'): /* Toggle ANSI color */ + case Ctrl('V'): /* Toggle ANSI color */ my_ansimode ^= 1; - if(my_ansimode && blockln >= 0) + if (my_ansimode && blockln >= 0) block_color(); clear(); redraw_everything = YEA; @@ -1893,7 +1959,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { case Ctrl('I'): do { insert_char(' '); - } while(currpnt & 0x7); + } while (currpnt & 0x7); line_dirty = 1; break; case '\r': @@ -1902,40 +1968,40 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 0; break; case Ctrl('G'): - { - unsigned int currstat0 = currstat; - setutmpmode(EDITEXP); - a_menu("½s¿è»²§U¾¹", "etc/editexp", - (HAS_PERM(PERM_SYSOP) ? SYSOP : NOBODY)); - currstat = currstat0; - } - if(trans_buffer[0]) { - if((fp1 = fopen(trans_buffer, "r"))) { - int indent_mode0 = indent_mode; - - indent_mode = 0; - prevln = currln; - prevpnt = currpnt; - while(fgets(line, WRAPMARGIN + 2, fp1)) { - if(!strncmp(line,"§@ªÌ:",5) || - !strncmp(line,"¼ÐÃD:",5) || - !strncmp(line,"®É¶¡:",5)) - continue; - insert_string(line); - } - fclose(fp1); - indent_mode = indent_mode0; - while(curr_window_line >= b_lines) { - curr_window_line--; - top_of_win = top_of_win->next; + { + unsigned int currstat0 = currstat; + setutmpmode(EDITEXP); + a_menu("½s¿è»²§U¾¹", "etc/editexp", + (HAS_PERM(PERM_SYSOP) ? SYSOP : NOBODY)); + currstat = currstat0; + } + if (trans_buffer[0]) { + if ((fp1 = fopen(trans_buffer, "r"))) { + int indent_mode0 = indent_mode; + + indent_mode = 0; + prevln = currln; + prevpnt = currpnt; + while (fgets(line, WRAPMARGIN + 2, fp1)) { + if (!strncmp(line, "§@ªÌ:", 5) || + !strncmp(line, "¼ÐÃD:", 5) || + !strncmp(line, "®É¶¡:", 5)) + continue; + insert_string(line); + } + fclose(fp1); + indent_mode = indent_mode0; + while (curr_window_line >= b_lines) { + curr_window_line--; + top_of_win = top_of_win->next; + } } } - } - redraw_everything = YEA; - line_dirty = 1; - break; - case Ctrl('Z'): /* Help */ - more("etc/ve.hlp",YEA); + redraw_everything = YEA; + line_dirty = 1; + break; + case Ctrl('Z'): /* Help */ + more("etc/ve.hlp", YEA); redraw_everything = YEA; line_dirty = 1; break; @@ -1945,14 +2011,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case KEY_LEFT: - if(currpnt) { - if(my_ansimode) + if (currpnt) { + if (my_ansimode) currpnt = n2ansi(currpnt, currline); currpnt--; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(currpnt, currline); line_dirty = 1; - } else if(currline->prev) { + } else if (currline->prev) { curr_window_line--; currln--; currline = currline->prev; @@ -1961,14 +2027,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case KEY_RIGHT: - if(currline->len != currpnt) { - if(my_ansimode) + if (currline->len != currpnt) { + if (my_ansimode) currpnt = n2ansi(currpnt, currline); currpnt++; - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(currpnt, currline); line_dirty = 1; - } else if(currline->next) { + } else if (currline->next) { currpnt = 0; curr_window_line++; currln++; @@ -1978,33 +2044,33 @@ int vedit(char *fpath, int saveheader, int *islocal) { break; case KEY_UP: case Ctrl('P'): - if(currline->prev) { - if(my_ansimode) - ch = n2ansi(currpnt,currline); + if (currline->prev) { + if (my_ansimode) + ch = n2ansi(currpnt, currline); curr_window_line--; currln--; currline = currline->prev; - if(my_ansimode) - currpnt = ansi2n(ch , currline); + if (my_ansimode) + currpnt = ansi2n(ch, currline); else currpnt = (currline->len > lastindent) ? lastindent : - currline->len; + currline->len; line_dirty = 0; } break; case KEY_DOWN: case Ctrl('N'): - if(currline->next) { - if(my_ansimode) - ch = n2ansi(currpnt,currline); + if (currline->next) { + if (my_ansimode) + ch = n2ansi(currpnt, currline); currline = currline->next; curr_window_line++; currln++; - if(my_ansimode) - currpnt = ansi2n(ch , currline); + if (my_ansimode) + currpnt = ansi2n(ch, currline); else currpnt = (currline->len > lastindent) ? lastindent : - currline->len; + currline->len; line_dirty = 0; } break; @@ -2015,7 +2081,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currln = redraw_everything; currline = back_line(currline, 22); curr_window_line = getlineno(); - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; line_dirty = 0; @@ -2027,7 +2093,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currln = redraw_everything; currline = forward_line(currline, 22); curr_window_line = getlineno(); - if(currpnt > currline->len) + if (currpnt > currline->len) currpnt = currline->len; redraw_everything = YEA; line_dirty = 0; @@ -2037,7 +2103,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { currpnt = currline->len; line_dirty = 1; break; - case Ctrl(']'): /* start of file */ + case Ctrl(']'): /* start of file */ prevln = currln; prevpnt = currpnt; currline = top_of_win = firstline; @@ -2045,7 +2111,7 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; line_dirty = 0; break; - case Ctrl('T'): /* tail of file */ + case Ctrl('T'): /* tail of file */ prevln = currln; prevpnt = currpnt; top_of_win = back_line(lastline, 23); @@ -2061,10 +2127,10 @@ int vedit(char *fpath, int saveheader, int *islocal) { currpnt = 0; line_dirty = 1; break; - case KEY_INS: /* Toggle insert/overwrite */ + case KEY_INS: /* Toggle insert/overwrite */ case Ctrl('O'): - if(blockln >= 0 && insert_character) { - char ans[4]; + if (blockln >= 0 && insert_character) { + char ans[4]; getdata(b_lines - 1, 0, "°Ï¶ô·L½Õ¥k²¾´¡¤J¦r¤¸(¹w³]¬°ªÅ¥Õ¦r¤¸)", @@ -2075,17 +2141,17 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; case Ctrl('H'): - case '\177': /* backspace */ + case '\177': /* backspace */ line_dirty = 1; - if(my_ansimode) { + if (my_ansimode) { my_ansimode = 0; clear(); redraw_everything = YEA; } else { - if(currpnt == 0) { - textline_t *p; + if (currpnt == 0) { + textline_t *p; - if(!currline->prev) + if (!currline->prev) break; line_dirty = 0; curr_window_line--; @@ -2093,14 +2159,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { currline = currline->prev; currpnt = currline->len; redraw_everything = YEA; - if(*killsp(currline->next->data) == '\0') { + if (*killsp(currline->next->data) == '\0') { delete_line(currline->next); break; } p = currline; - while(!join(p)) { + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2112,14 +2178,14 @@ int vedit(char *fpath, int saveheader, int *islocal) { } break; case Ctrl('D'): - case KEY_DEL: /* delete current character */ + case KEY_DEL: /* delete current character */ line_dirty = 1; - if(currline->len == currpnt) { - textline_t *p = currline; - - while(!join(p)) { + if (currline->len == currpnt) { + textline_t *p = currline; + + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2128,25 +2194,25 @@ int vedit(char *fpath, int saveheader, int *islocal) { redraw_everything = YEA; } else { delete_char(); - if(my_ansimode) + if (my_ansimode) currpnt = ansi2n(n2ansi(currpnt, currline), currline); } break; - case Ctrl('Y'): /* delete current line */ + case Ctrl('Y'): /* delete current line */ currline->len = currpnt = 0; - case Ctrl('K'): /* delete to end of line */ - if(currline->len == 0) { - textline_t *p = currline->next; - if(!p) { + case Ctrl('K'): /* delete to end of line */ + if (currline->len == 0) { + textline_t *p = currline->next; + if (!p) { p = currline->prev; - if(!p) + if (!p) break; - if(curr_window_line > 0) { + if (curr_window_line > 0) { curr_window_line--; currln--; } } - if(currline == top_of_win) + if (currline == top_of_win) top_of_win = p; delete_line(currline); currline = p; @@ -2154,12 +2220,12 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 0; break; } - if(currline->len == currpnt) { - textline_t *p = currline; + if (currline->len == currpnt) { + textline_t *p = currline; - while(!join(p)) { + while (!join(p)) { p = p->next; - if(p == NULL) { + if (p == NULL) { indigestion(2); abort_bbs(0); } @@ -2173,20 +2239,20 @@ int vedit(char *fpath, int saveheader, int *islocal) { line_dirty = 1; break; } - if(currln < 0) + if (currln < 0) currln = 0; - if(curr_window_line < 0) { + if (curr_window_line < 0) { curr_window_line = 0; - if(!top_of_win->prev) + if (!top_of_win->prev) indigestion(6); else { top_of_win = top_of_win->prev; rscroll(); } } - if(curr_window_line == b_lines) { + if (curr_window_line == b_lines) { curr_window_line = t_lines - 2; - if(!top_of_win->next) + if (!top_of_win->next) indigestion(7); else { top_of_win = top_of_win->next; @@ -2197,15 +2263,15 @@ int vedit(char *fpath, int saveheader, int *islocal) { } } edit_margin = currpnt < SCR_WIDTH - 1 ? 0 : currpnt / 72 * 72; - - if(!redraw_everything) { - if(edit_margin != last_margin) { + + if (!redraw_everything) { + if (edit_margin != last_margin) { last_margin = edit_margin; redraw_everything = YEA; } else { move(curr_window_line, 0); clrtoeol(); - if(my_ansimode) + if (my_ansimode) outs(currline->data); else edit_outs(&currline->data[edit_margin]); diff --git a/mbbsd/friend.c b/mbbsd/friend.c index c24f6240..81abf097 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -1,4 +1,4 @@ -/* $Id: friend.c,v 1.8 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: friend.c,v 1.9 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" /* ------------------------------------- */ @@ -6,8 +6,8 @@ /* ------------------------------------- */ /* Ptt ¨ä¥L¯S§O¦W³æªºÀɦW */ -static char special_list[] = "list.0"; -static char special_des[] = "ldes.0"; +static char special_list[] = "list.0"; +static char special_des[] = "ldes.0"; /* ¯S§O¦W³æªº¤W */ static unsigned int friend_max[8] = { @@ -24,7 +24,7 @@ static unsigned int friend_max[8] = { /* Ptt ¦UºØ¯S§O¦W³æªº¸Éz */ -static char *friend_desc[8] = { +static char *friend_desc[8] = { "¤Í½Ë´yz¡G", "´c§Î´cª¬¡G", "", @@ -36,7 +36,7 @@ static char *friend_desc[8] = { }; /* Ptt ¦UºØ¯S§O¦W³æªº¤¤¤å±Ôz */ -static char *friend_list[8] = { +static char *friend_list[8] = { "¦n¤Í¦W³æ", "Ãa¤H¦W³æ", "¤W½u³qª¾", @@ -47,17 +47,21 @@ static char *friend_list[8] = { "¬ÝªO¦n¤Í¦W³æ" }; -static void setfriendfile(char *fpath, int type) { +static void +setfriendfile(char *fpath, int type) +{ if (type <= 4) /* user list Ptt */ setuserfile(fpath, friend_file[type]); else /* board list */ setbfile(fpath, currboard, friend_file[type]); } -static int friend_count(char *fname) { - FILE *fp; - int count = 0; - char buf[200]; +static int +friend_count(char *fname) +{ + FILE *fp; + int count = 0; + char buf[200]; #if 0 if ((fp = fopen(fname, "r"))) @@ -65,37 +69,36 @@ static int friend_count(char *fname) { count++; #endif -/*rocker.011018: §Ñ°OÃöÀɤF... */ - if ((fp = fopen(fname, "r"))) - { - while (fgets(buf, 200, fp)) count++; - fclose (fp); + /* rocker.011018: §Ñ°OÃöÀɤF... */ + if ((fp = fopen(fname, "r"))) { + while (fgets(buf, 200, fp)) + count++; + fclose(fp); } - return count; } -void friend_add(char *uident, int type) { - char fpath[80]; +void +friend_add(char *uident, int type) +{ + char fpath[80]; setfriendfile(fpath, type); if (friend_count(fpath) > friend_max[type]) return; - if ((uident[0] > ' ') && !belong(fpath, uident)) - { - FILE *fp; - char buf[40] = ""; - char t_uident[IDLEN + 1]; + if ((uident[0] > ' ') && !belong(fpath, uident)) { + FILE *fp; + char buf[40] = ""; + char t_uident[IDLEN + 1]; - /* Thor: avoid uident run away when get data */ + /* Thor: avoid uident run away when get data */ strcpy(t_uident, uident); if (type != FRIEND_ALOHA && type != FRIEND_POST) getdata(2, 0, friend_desc[type], buf, sizeof(buf), DOECHO); - if ((fp = fopen(fpath, "a"))) - { + if ((fp = fopen(fpath, "a"))) { flock(fileno(fp), LOCK_EX); fprintf(fp, "%-13s%s\n", t_uident, buf); flock(fileno(fp), LOCK_UN); @@ -104,19 +107,19 @@ void friend_add(char *uident, int type) { } } -static void friend_special() { - char genbuf[70], i, fname[70]; +static void +friend_special() +{ + char genbuf[70], i, fname[70]; friend_file[FRIEND_SPECIAL] = special_list; - for (i = 0; i <= 9; i++) - { + for (i = 0; i <= 9; i++) { sprintf(genbuf, " (\033[36m%d\033[m) .. ", i); special_des[5] = i + '0'; setuserfile(fname, special_des); - if (dashf(fname)) - { - /* no NULL check?? */ - FILE *fp = fopen(fname, "r"); + if (dashf(fname)) { + /* no NULL check?? */ + FILE *fp = fopen(fname, "r"); fgets(genbuf + 15, 40, fp); genbuf[47] = 0; @@ -126,45 +129,41 @@ static void friend_special() { outs(genbuf); } getdata(22, 0, "½Ð¿ï¾Ü²Ä´X¸¹¯S§O¦W³æ (0~9)[0]?", genbuf, 3, LCECHO); - if (genbuf[0] >= '0' && genbuf[0] <= '9') - { + if (genbuf[0] >= '0' && genbuf[0] <= '9') { special_list[5] = genbuf[0]; special_des[5] = genbuf[0]; - } - else - { + } else { special_list[5] = '0'; special_des[5] = '0'; } } -static void friend_append(int type, int count) { - char fpath[80], i, j, buf[80], sfile[80]; - FILE *fp, *fp1; +static void +friend_append(int type, int count) +{ + char fpath[80], i, j, buf[80], sfile[80]; + FILE *fp, *fp1; setfriendfile(fpath, type); - do - { + do { move(2, 0); clrtobot(); outs("n¤Þ¤Jþ¤@Ó¦W³æ?\n"); for (j = i = 0; i <= 4; i++) - if( i != type ){ + if (i != type) { ++j; - sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int) i]); + sprintf(buf, " (%d) %-s\n", i + 1, friend_list[(int)i]); outs(buf); } - - if( HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD ) - for( ; i < 8 ; ++i ) - if( i != type ){ + if (HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) + for (; i < 8; ++i) + if (i != type) { ++j; sprintf(buf, " (%d) %s ªOªº %s\n", j, currboard, - friend_list[(int) i]); + friend_list[(int)i]); outs(buf); } - outs(" (S) ¿ï¾Ü¨ä¥L¬ÝªOªº¯S§O¦W³æ"); getdata(11, 0, "½Ð¿ï¾Ü ©Î ª½±µ[Enter] ©ñ±ó:", buf, 3, LCECHO); if (!buf[0]) @@ -174,7 +173,7 @@ static void friend_append(int type, int count) { j = buf[0] - '1'; if (j >= type) j++; - if( !(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4 ) + if (!(HAVE_PERM(PERM_SYSOP) || currmode & MODE_BOARD) && j >= 4) return; } while (buf[0] < '1' || buf[0] > '9'); @@ -184,13 +183,13 @@ static void friend_append(int type, int count) { setfriendfile(sfile, j); - if( (fp = fopen(sfile, "r")) != NULL ){ - while (fgets(buf, 80, fp) && count <= friend_max[type]){ - char the_id[15]; - + if ((fp = fopen(sfile, "r")) != NULL) { + while (fgets(buf, 80, fp) && count <= friend_max[type]) { + char the_id[15]; + sscanf(buf, "%s", the_id); - if (!belong(fpath, the_id)){ - if ((fp1 = fopen(fpath, "a"))){ + if (!belong(fpath, the_id)) { + if ((fp1 = fopen(fpath, "a"))) { flock(fileno(fp1), LOCK_EX); fputs(buf, fp1); flock(fileno(fp1), LOCK_UN); @@ -202,17 +201,18 @@ static void friend_append(int type, int count) { } } -void friend_delete(char *uident, int type) { - FILE *fp, *nfp; - char fn[80], fnnew[80]; - char genbuf[200]; +void +friend_delete(char *uident, int type) +{ + FILE *fp, *nfp; + char fn[80], fnnew[80]; + char genbuf[200]; setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) - { - int length = strlen(uident); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + int length = strlen(uident); while (fgets(genbuf, STRLEN, fp)) if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) @@ -223,22 +223,21 @@ void friend_delete(char *uident, int type) { } } -static void friend_editdesc(char *uident, int type) { - FILE *fp, *nfp; - char fnnew[200], genbuf[200], fn[200]; +static void +friend_editdesc(char *uident, int type) +{ + FILE *fp, *nfp; + char fnnew[200], genbuf[200], fn[200]; setfriendfile(fn, type); sprintf(fnnew, "%s-", fn); - if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) - { - int length = strlen(uident); + if ((fp = fopen(fn, "r")) && (nfp = fopen(fnnew, "w"))) { + int length = strlen(uident); - while (fgets(genbuf, STRLEN, fp)) - { + while (fgets(genbuf, STRLEN, fp)) { if ((genbuf[0] > ' ') && strncmp(genbuf, uident, length)) fputs(genbuf, nfp); - else if (!strncmp(genbuf, uident, length)) - { - char buf[50] = ""; + else if (!strncmp(genbuf, uident, length)) { + char buf[50] = ""; getdata(2, 0, "קï´yz¡G", buf, 40, DOECHO); fprintf(nfp, "%-13s%s\n", uident, buf); } @@ -249,19 +248,20 @@ static void friend_editdesc(char *uident, int type) { } } -void friend_load() { - FILE *fp; - int myfriends[MAX_FRIEND]; - int myrejects[MAX_REJECT]; - int friendcount, rejectedcount; - char genbuf[200]; +void +friend_load() +{ + FILE *fp; + int myfriends[MAX_FRIEND]; + int myrejects[MAX_REJECT]; + int friendcount, rejectedcount; + char genbuf[200]; memset(myfriends, 0, sizeof(myfriends)); friendcount = 0; setuserfile(genbuf, fn_overrides); - if ((fp = fopen(genbuf, "r"))) - { - int unum; + if ((fp = fopen(genbuf, "r"))) { + int unum; while (fgets(genbuf, STRLEN, fp) && friendcount < MAX_FRIEND - 1) if (strtok(genbuf, str_space)) @@ -274,9 +274,8 @@ void friend_load() { memset(myrejects, 0, sizeof(myrejects)); rejectedcount = 0; setuserfile(genbuf, fn_reject); - if ((fp = fopen(genbuf, "r"))) - { - int unum; + if ((fp = fopen(genbuf, "r"))) { + int unum; while (fgets(genbuf, STRLEN, fp) && rejectedcount < MAX_REJECT - 1) if (strtok(genbuf, str_space)) @@ -285,52 +284,52 @@ void friend_load() { fclose(fp); } memcpy(currutmp->reject, myrejects, sizeof(myrejects)); - if(currutmp->friendtotal) + if (currutmp->friendtotal) logout_friend_online(currutmp); login_friend_online(); } -static void friend_water(char *message, int type) { /* ¸sÅé¤ô²y added by Ptt */ - char fpath[80], line[80], userid[IDLEN + 1]; - FILE *fp; +static void +friend_water(char *message, int type) +{ /* ¸sÅé¤ô²y added by Ptt */ + char fpath[80], line[80], userid[IDLEN + 1]; + FILE *fp; setfriendfile(fpath, type); if ((fp = fopen(fpath, "r"))) - while(fgets(line, 80, fp)) { - userinfo_t *uentp; - int tuid; - + while (fgets(line, 80, fp)) { + userinfo_t *uentp; + int tuid; + sscanf(line, "%s", userid); - if((tuid = searchuser(userid)) && tuid != usernum && - (uentp = (userinfo_t *) search_ulist(tuid)) && - isvisible_uid(tuid)) + if ((tuid = searchuser(userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist(tuid)) && + isvisible_uid(tuid)) my_write(uentp->pid, message, uentp->userid, 1, NULL); } fclose(fp); } -void friend_edit(int type) { - char fpath[80], line[80], uident[20]; - int count, column, dirty; - FILE *fp; - char genbuf[200]; +void +friend_edit(int type) +{ + char fpath[80], line[80], uident[20]; + int count, column, dirty; + FILE *fp; + char genbuf[200]; if (type == FRIEND_SPECIAL) friend_special(); setfriendfile(fpath, type); - if (type == FRIEND_ALOHA || type == FRIEND_POST) - { - if (dashf(fpath)) - { + if (type == FRIEND_ALOHA || type == FRIEND_POST) { + if (dashf(fpath)) { sprintf(genbuf, "/bin/cp %s %s.old", fpath, fpath); system(genbuf); } } - dirty = 0; - while (1) - { + while (1) { stand_title(friend_list[type]); move(0, 40); sprintf(line, "(¦W³æ¤W:%dÓ¤H)", friend_max[type]); @@ -338,20 +337,17 @@ void friend_edit(int type) { count = 0; CreateNameList(); - if ((fp = fopen(fpath, "r"))) - { + if ((fp = fopen(fpath, "r"))) { move(3, 0); column = 0; - while (fgets(genbuf, STRLEN, fp)) - { + while (fgets(genbuf, STRLEN, fp)) { if (genbuf[0] <= ' ') continue; strtok(genbuf, str_space); AddNameList(genbuf); prints("%-13s", genbuf); count++; - if (++column > 5) - { + if (++column > 5) { column = 0; outc('\n'); } @@ -363,108 +359,83 @@ void friend_edit(int type) { "(K)§R°£¾ãÓ¦W³æ(W)¥á¤ô²y(Q)µ²§ô¡H[Q]" : "(A)¼W¥[ (P)¤Þ¤J¨ä¥L¦W³æ (Q)µ²§ô¡H[Q]"), uident, 3, LCECHO); - if (*uident == 'a') - { + if (*uident == 'a') { move(1, 0); usercomplete(msg_uid, uident); - if (uident[0] && searchuser(uident) && !InNameList(uident)) - { + if (uident[0] && searchuser(uident) && !InNameList(uident)) { friend_add(uident, type); dirty = 1; } - } - else if (*uident == 'p') - { + } else if (*uident == 'p') { friend_append(type, count); dirty = 1; - } - else if (*uident == 'e' && count) - { + } else if (*uident == 'e' && count) { move(1, 0); namecomplete(msg_uid, uident); - if (uident[0] && InNameList(uident)) - { + if (uident[0] && InNameList(uident)) { friend_editdesc(uident, type); } - } - else if (*uident == 'd' && count) - { + } else if (*uident == 'd' && count) { move(1, 0); namecomplete(msg_uid, uident); - if (uident[0] && InNameList(uident)) - { + if (uident[0] && InNameList(uident)) { friend_delete(uident, type); dirty = 1; } - } - else if (*uident == 'l' && count) + } else if (*uident == 'l' && count) more(fpath, YEA); - else if (*uident == 'k' && count) - { + else if (*uident == 'k' && count) { getdata(2, 0, "¾ã¥÷¦W³æ±N·|³Q§R°£,±z½T©w¶Ü (a/N)?", uident, 3, LCECHO); if (*uident == 'a') unlink(fpath); dirty = 1; - } - else if (*uident == 'w' && count) - { - char wall[60]; + } else if (*uident == 'w' && count) { + char wall[60]; if (!getdata(0, 0, "¸sÅé¤ô²y:", uident, sizeof(wall), DOECHO)) continue; if (getdata(0, 0, "½T©w¥á¥X¸sÅé¤ô²y? [Y]", line, 4, LCECHO) && *line == 'n') continue; friend_water(wall, type); - } - else + } else break; } - if (dirty) - { + if (dirty) { move(2, 0); outs("§ó·s¸ê®Æ¤¤..½ÐµyÔ....."); refresh(); - if (type == FRIEND_ALOHA || type == FRIEND_POST) - { + if (type == FRIEND_ALOHA || type == FRIEND_POST) { sprintf(genbuf, "%s.old", fpath); - if ((fp = fopen(genbuf, "r"))) - { - while (fgets(line, 80, fp)) - { + if ((fp = fopen(genbuf, "r"))) { + while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); sethomefile(genbuf, uident, - type == FRIEND_ALOHA ? "aloha" : "postnotify"); + type == FRIEND_ALOHA ? "aloha" : "postnotify"); del_distinct(genbuf, cuser.userid); } fclose(fp); } sprintf(genbuf, "%s", fpath); - if ((fp = fopen(genbuf, "r"))) - { - while (fgets(line, 80, fp)) - { + if ((fp = fopen(genbuf, "r"))) { + while (fgets(line, 80, fp)) { sscanf(line, "%s", uident); sethomefile(genbuf, uident, - type == FRIEND_ALOHA ? "aloha" : "postnotify"); + type == FRIEND_ALOHA ? "aloha" : "postnotify"); add_distinct(genbuf, cuser.userid); } fclose(fp); } - } - else if (type == FRIEND_SPECIAL) - { + } else if (type == FRIEND_SPECIAL) { genbuf[0] = 0; setuserfile(line, special_des); - if ((fp = fopen(line, "r"))) - { + if ((fp = fopen(line, "r"))) { fgets(genbuf, 30, fp); fclose(fp); } getdata_buf(2, 0, " ½Ð¬°¦¹¯S§O¦W³æ¨ú¤@Ó²µu¦WºÙ:", genbuf, 30, DOECHO); - if ((fp = fopen(line, "w"))) - { + if ((fp = fopen(line, "w"))) { fprintf(fp, "%s", genbuf); fclose(fp); } @@ -473,12 +444,16 @@ void friend_edit(int type) { } } -int t_override() { +int +t_override() +{ friend_edit(FRIEND_OVERRIDE); return 0; } -int t_reject() { +int +t_reject() +{ friend_edit(FRIEND_REJECT); return 0; } diff --git a/mbbsd/gamble.c b/mbbsd/gamble.c index d7a96a53..5a93c275 100644 --- a/mbbsd/gamble.c +++ b/mbbsd/gamble.c @@ -1,394 +1,384 @@ -/* $Id: gamble.c,v 1.24 2002/06/29 13:16:50 ptt Exp $ */ +/* $Id: gamble.c,v 1.25 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #ifndef _BBS_UTIL_C_ #define MAX_ITEM 8 //³Ì¤j ½ä¶µ(item) Ó¼Æ #define MAX_ITEM_LEN 30 //³Ì¤j ¨C¤@½ä¶µ¦W¦rªø«× -#define MAX_SUBJECT_LEN 650 //8*81 = 648 ³Ì¤j ¥DÃDªø«× +#define MAX_SUBJECT_LEN 650 //8*81 = 648 ³Ì¤j ¥DÃDªø«× -static char betname[MAX_ITEM][MAX_ITEM_LEN]; -static int currbid; +static char betname[MAX_ITEM][MAX_ITEM_LEN]; +static int currbid; -int post_msg(char* bname, char* title, char *msg, char* author) +int +post_msg(char *bname, char *title, char *msg, char *author) { - FILE *fp; - int bid; - fileheader_t fhdr; - char genbuf[256]; - + FILE *fp; + int bid; + fileheader_t fhdr; + char genbuf[256]; + /* ¦b bname ªOµoªí·s¤å³¹ */ sprintf(genbuf, "boards/%c/%s", bname[0], bname); stampfile(genbuf, &fhdr); - fp = fopen(genbuf,"w"); - - if(!fp) - return -1; - - fprintf(fp, "§@ªÌ: %s ¬ÝªO: %s\n¼ÐÃD: %s \n",author,bname,title); + fp = fopen(genbuf, "w"); + + if (!fp) + return -1; + + fprintf(fp, "§@ªÌ: %s ¬ÝªO: %s\n¼ÐÃD: %s \n", author, bname, title); fprintf(fp, "®É¶¡: %s\n", ctime(&now)); - + /* ¤å³¹ªº¤º®e */ fprintf(fp, "%s", msg); fclose(fp); - + /* ±NÀÉ®×¥[¤J¦Cªí */ strcpy(fhdr.title, title); strcpy(fhdr.owner, author); - setbdir(genbuf,bname); - if(append_record(genbuf, &fhdr, sizeof(fhdr))!=-1) - if((bid = getbnum(bname)) > 0) - setbtotal(bid); + setbdir(genbuf, bname); + if (append_record(genbuf, &fhdr, sizeof(fhdr)) != -1) + if ((bid = getbnum(bname)) > 0) + setbtotal(bid); return 0; } -int post_file(char* bname, char* title, char *filename, char* author) +int +post_file(char *bname, char *title, char *filename, char *author) { - int size=dashs(filename); - char *msg; - FILE *fp; - - if(size<=0) return -1; - if(!(fp=fopen(filename,"r")) ) return -1; - msg= (char *)malloc(size+1); - size = fread(msg,1,size,fp); - msg[size]=0; - size= post_msg(bname, title, msg, author); - fclose(fp); - free(msg); - return size; + int size = dashs(filename); + char *msg; + FILE *fp; + + if (size <= 0) + return -1; + if (!(fp = fopen(filename, "r"))) + return -1; + msg = (char *)malloc(size + 1); + size = fread(msg, 1, size, fp); + msg[size] = 0; + size = post_msg(bname, title, msg, author); + fclose(fp); + free(msg); + return size; } -static int load_ticket_record(char *direct, int ticket[]) +static int +load_ticket_record(char *direct, int ticket[]) { - char buf[256]; - int i, total=0; - FILE *fp; - sprintf(buf,"%s/"FN_TICKET_RECORD,direct); - if(!(fp=fopen(buf,"r"))) return 0; - for(i=0;i<MAX_ITEM && fscanf(fp, "%9d ",&ticket[i]); i++) - total=total+ticket[i]; - fclose(fp); - return total; + char buf[256]; + int i, total = 0; + FILE *fp; + sprintf(buf, "%s/" FN_TICKET_RECORD, direct); + if (!(fp = fopen(buf, "r"))) + return 0; + for (i = 0; i < MAX_ITEM && fscanf(fp, "%9d ", &ticket[i]); i++) + total = total + ticket[i]; + fclose(fp); + return total; } -static int show_ticket_data(char *direct, int *price, boardheader_t *bh) { - int i,count, total = 0, end=0, - ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; - FILE *fp; - char genbuf[256], t[25]; +static int +show_ticket_data(char *direct, int *price, boardheader_t * bh) +{ + int i, count, total = 0, end = 0, ticket[MAX_ITEM] = {0, 0, 0, 0, 0, 0, 0, 0}; + FILE *fp; + char genbuf[256], t[25]; clear(); - if (bh) - { - sprintf(genbuf,"%s ½ä½L", bh->brdname); - if(bh->endgamble && now < bh->endgamble && bh->endgamble-now<3600) - { - sprintf(t,"«Ê½LË¼Æ %d ¬í", bh->endgamble-now); - showtitle(genbuf, t); - } - else showtitle(genbuf, BBSNAME); - } - else - showtitle("Ptt½ä½L", BBSNAME); + if (bh) { + sprintf(genbuf, "%s ½ä½L", bh->brdname); + if (bh->endgamble && now < bh->endgamble && bh->endgamble - now < 3600) { + sprintf(t, "«Ê½LË¼Æ %d ¬í", bh->endgamble - now); + showtitle(genbuf, t); + } else + showtitle(genbuf, BBSNAME); + } else + showtitle("Ptt½ä½L", BBSNAME); move(2, 0); - sprintf(genbuf, "%s/"FN_TICKET_ITEMS, direct); - if(!(fp = fopen(genbuf,"r"))) - { - prints("\n¥Ø«e¨Ã¨S¦³Á|¿ì½ä½L\n"); - sprintf(genbuf, "%s/"FN_TICKET_OUTCOME, direct); - if(more(genbuf, NA)); - return 0; + sprintf(genbuf, "%s/" FN_TICKET_ITEMS, direct); + if (!(fp = fopen(genbuf, "r"))) { + prints("\n¥Ø«e¨Ã¨S¦³Á|¿ì½ä½L\n"); + sprintf(genbuf, "%s/" FN_TICKET_OUTCOME, direct); + if (more(genbuf, NA)); + return 0; } - fgets(genbuf,MAX_ITEM_LEN,fp); - *price=atoi(genbuf); - for(count=0; fgets(betname[count],MAX_ITEM_LEN,fp)&&count<MAX_ITEM; count++) - strtok(betname[count],"\r\n"); + fgets(genbuf, MAX_ITEM_LEN, fp); + *price = atoi(genbuf); + for (count = 0; fgets(betname[count], MAX_ITEM_LEN, fp) && count < MAX_ITEM; count++) + strtok(betname[count], "\r\n"); fclose(fp); prints("\033[32m¯¸³W:\033[m 1.¥iÁʶR¥H¤U¤£¦PÃþ«¬ªº±m²¼¡C¨C±inªá \033[32m%d\033[m ¤¸¡C\n" - " 2.%s\n" - " 3.¶}¼ú®É¥u¦³¤@ºØ±m²¼¤¤¼ú, ¦³ÁʶR¸Ó±m²¼ªÌ, «h¥i¨ÌÁʶRªº±i¼Æ§¡¤À" - "Á`½äª÷¡C\n" - " 4.¨Cµ§¼úª÷¥Ñ¨t²Î©â¨ú 5% ¤§µ|ª÷%s¡C\n\n" - "\033[32m%s:\033[m", *price, - bh?"¦¹½ä½L¥ÑªO¥Dt³dÁ|¿ì¨Ã¥B¨M©w¶}¼ú®É¶¡µ²ªG, ¯¸ªø¤£ºÞ, Ä@½äªA¿é¡C": - "¨t²Î¨C¤Ñ 2:00 11:00 16:00 21:00 ¶}¼ú¡C", - bh?", ¨ä¤¤ 2% ¤Àµ¹¶}¼úªO¥D":"", - bh?"ªO¥D¦Ûq³W«h¤Î»¡©ú":"«e´X¦¸¶}¼úµ²ªG"); - - - sprintf(genbuf, "%s/"FN_TICKET, direct); - if(!dashf(genbuf)) - { - sprintf(genbuf, "%s/"FN_TICKET_END, direct); - end=1; - } + " 2.%s\n" + " 3.¶}¼ú®É¥u¦³¤@ºØ±m²¼¤¤¼ú, ¦³ÁʶR¸Ó±m²¼ªÌ, «h¥i¨ÌÁʶRªº±i¼Æ§¡¤À" + "Á`½äª÷¡C\n" + " 4.¨Cµ§¼úª÷¥Ñ¨t²Î©â¨ú 5% ¤§µ|ª÷%s¡C\n\n" + "\033[32m%s:\033[m", *price, + bh ? "¦¹½ä½L¥ÑªO¥Dt³dÁ|¿ì¨Ã¥B¨M©w¶}¼ú®É¶¡µ²ªG, ¯¸ªø¤£ºÞ, Ä@½äªA¿é¡C" : + "¨t²Î¨C¤Ñ 2:00 11:00 16:00 21:00 ¶}¼ú¡C", + bh ? ", ¨ä¤¤ 2% ¤Àµ¹¶}¼úªO¥D" : "", + bh ? "ªO¥D¦Ûq³W«h¤Î»¡©ú" : "«e´X¦¸¶}¼úµ²ªG"); + + + sprintf(genbuf, "%s/" FN_TICKET, direct); + if (!dashf(genbuf)) { + sprintf(genbuf, "%s/" FN_TICKET_END, direct); + end = 1; + } show_file(genbuf, 8, -1, NO_RELOAD); - move(15,0); + move(15, 0); prints("\033[1;32m¥Ø«e¤Uª`ª¬ªp:\033[m\n"); - total=load_ticket_record(direct, ticket); - + total = load_ticket_record(direct, ticket); + prints("\033[33m"); - for(i = 0 ; i<count; i++) - { - prints("%d.%-8s: %-7d", i+1, betname[i], ticket[i]); - if(i==3) prints("\n"); - } - prints("\033[m\n\033[42m ¤Uª`Á`ª÷ÃB:\033[31m %d ¤¸ \033[m",total*(*price)); - if(end) - { - prints("\n½ä½L¤w¸g°±¤î¤Uª`\n"); - return -count; - } + for (i = 0; i < count; i++) { + prints("%d.%-8s: %-7d", i + 1, betname[i], ticket[i]); + if (i == 3) + prints("\n"); + } + prints("\033[m\n\033[42m ¤Uª`Á`ª÷ÃB:\033[31m %d ¤¸ \033[m", total * (*price)); + if (end) { + prints("\n½ä½L¤w¸g°±¤î¤Uª`\n"); + return -count; + } return count; } -static void append_ticket_record(char *direct, int ch, int n, int count) { - FILE *fp; - int ticket[8] = {0,0,0,0,0,0,0,0}, i; - char genbuf[256]; - sprintf(genbuf, "%s/"FN_TICKET_USER, direct); - - if((fp = fopen(genbuf,"a"))) { +static void +append_ticket_record(char *direct, int ch, int n, int count) +{ + FILE *fp; + int ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}, i; + char genbuf[256]; + sprintf(genbuf, "%s/" FN_TICKET_USER, direct); + + if ((fp = fopen(genbuf, "a"))) { fprintf(fp, "%s %d %d\n", cuser.userid, ch, n); fclose(fp); } load_ticket_record(direct, ticket); ticket[ch] += n; sprintf(genbuf, "%s/" FN_TICKET_RECORD, direct); - if((fp = fopen(genbuf,"w"))) { - for(i=0; i<count; i++) - fprintf(fp,"%d ", ticket[i]); + if ((fp = fopen(genbuf, "w"))) { + for (i = 0; i < count; i++) + fprintf(fp, "%d ", ticket[i]); fclose(fp); } } #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int ticket(int bid) +int +ticket(int bid) { - int ch, n, price, count, end=0; - char path[128],fn_ticket[128]; - boardheader_t *bh=NULL; - - if(bid) - { - bh=getbcache(bid); - setbpath(path, bh->brdname); - setbfile(fn_ticket, bh->brdname, FN_TICKET); - currbid = bid; - } - else - strcpy(path,"etc/"); + int ch, n, price, count, end = 0; + char path[128], fn_ticket[128]; + boardheader_t *bh = NULL; + + if (bid) { + bh = getbcache(bid); + setbpath(path, bh->brdname); + setbfile(fn_ticket, bh->brdname, FN_TICKET); + currbid = bid; + } else + strcpy(path, "etc/"); lockreturn0(TICKET, LOCK_MULTI); - while(1) { - count=show_ticket_data(path, &price, bh); - if(count<=0) - { - pressanykey(); - break; - } - move(20, 0); - reload_money(); + while (1) { + count = show_ticket_data(path, &price, bh); + if (count <= 0) { + pressanykey(); + break; + } + move(20, 0); + reload_money(); prints("\033[44m¿ú: %-10d \033[m\n\033[1m½Ð¿ï¾ÜnÁʶRªººØÃþ(1~%d)" - "[Q:Â÷¶}]\033[m:", cuser.money,count); + "[Q:Â÷¶}]\033[m:", cuser.money, count); ch = igetch(); - /*-- + /*-- Tim011127 - ¬°¤F±±¨îCS°ÝÃD ¦ý¬O³oÃäÁÙ¤£¯à§¹¥þ¸Ñ¨M³o°ÝÃD, + ¬°¤F±±¨îCS°ÝÃD ¦ý¬O³oÃäÁÙ¤£¯à§¹¥þ¸Ñ¨M³o°ÝÃD, Yuser³q¹LÀˬd¤U¥h, è¦nªO¥D¶}¼ú, ÁÙ¬O·|³y¦¨userªº³o¦¸¬ö¿ý «Ü¦³¥i¯à¶]¨ì¤U¦¸½ä½Lªº¬ö¿ý¥h, ¤]«Ü¦³¥i¯à³QªO¥D·s¶}½ä½L®É¬~±¼ ¤£¹L³oÃä¦Ü¤Ö¥i¥H°µ¨ìªº¬O, ³»¦h¥u·|¦³¤@µ§¸ê®Æ¬O¿ùªº --*/ - if(bid && !dashf(fn_ticket)) - { - move(b_lines-1,0); - prints("«z!! @£«®º...ªO¥D¤w¸g°±¤î¤Uª`¤F ¤£¯à½äÂP"); - pressanykey(); - break; - } - - if(ch=='q' || ch == 'Q') + if (bid && !dashf(fn_ticket)) { + move(b_lines - 1, 0); + prints("«z!! @£«®º...ªO¥D¤w¸g°±¤î¤Uª`¤F ¤£¯à½äÂP"); + pressanykey(); break; - ch-='1'; - if(end || ch >= count || ch < 0) + } + if (ch == 'q' || ch == 'Q') + break; + ch -= '1'; + if (end || ch >= count || ch < 0) continue; - n=0; - ch_buyitem(price, "etc/buyticket", &n); - if(n > 0) - append_ticket_record(path,ch,n,count); - } + n = 0; + ch_buyitem(price, "etc/buyticket", &n); + if (n > 0) + append_ticket_record(path, ch, n, count); + } unlockutmpmode(); return 0; } -int openticket(int bid) { - char path[128],buf[256],outcome[128]; - int i, money=0, count, bet, price, total = 0, ticket[8]={0,0,0,0,0,0,0,0}; - boardheader_t *bh=getbcache(bid); - FILE *fp, *fp1; - - setbpath(path, bh->brdname); - count=-show_ticket_data(path, &price, bh); - if(count==0) - { - setbfile(buf,bh->brdname,FN_TICKET_END); - unlink(buf); //Ptt: ¦³bug - return 0; - } +int +openticket(int bid) +{ + char path[128], buf[256], outcome[128]; + int i, money = 0, count, bet, price, total = 0, ticket[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + boardheader_t *bh = getbcache(bid); + FILE *fp, *fp1; + + setbpath(path, bh->brdname); + count = -show_ticket_data(path, &price, bh); + if (count == 0) { + setbfile(buf, bh->brdname, FN_TICKET_END); + unlink(buf); +//Ptt: ¦³bug + return 0; + } lockreturn0(TICKET, LOCK_MULTI); - do - { - do - { - getdata(20, 0, - "\033[1m¿ï¾Ü¤¤¼úªº¸¹½X(0:¤£¶}¼ú 99:¨ú®ø°h¿ú)\033[m:", buf, 3, LCECHO); - bet=atoi(buf); - move(0,0); - clrtoeol(); - } while( (bet<0 || bet>count) && bet!=99); - if(bet==0) - {unlockutmpmode(); return 0;} - getdata(21, 0, "\033[1m¦A¦¸½T»{¿é¤J¸¹½X\033[m:", buf, 3, LCECHO); - }while(bet!=atoi(buf)); - - if(fork()) - { // Ptt ¥Îfork¨¾¤î¤£¥¿±`Â_½u¬~¿ú - move(22,0); - prints("¨t²Î±N©óµy«á¦Û°Ê§â¤¤¼úµ²ªG¤½§G©ó¬ÝªO Y°Ñ¥[ªÌ¦h·|»Ýn´X¤ÀÄÁ®É¶¡.."); - pressanykey(); - unlockutmpmode(); - return 0; - } + do { + do { + getdata(20, 0, + "\033[1m¿ï¾Ü¤¤¼úªº¸¹½X(0:¤£¶}¼ú 99:¨ú®ø°h¿ú)\033[m:", buf, 3, LCECHO); + bet = atoi(buf); + move(0, 0); + clrtoeol(); + } while ((bet < 0 || bet > count) && bet != 99); + if (bet == 0) { + unlockutmpmode(); + return 0; + } + getdata(21, 0, "\033[1m¦A¦¸½T»{¿é¤J¸¹½X\033[m:", buf, 3, LCECHO); + } while (bet != atoi(buf)); + + if (fork()) { + //Ptt ¥ Îfork ¨ ¾¤î¤£¥¿±`Â_ ½ u ¬ ~¿ú + move(22, 0); + prints("¨t²Î±N©óµy«á¦Û°Ê§â¤¤¼úµ²ªG¤½§G©ó¬ÝªO Y°Ñ¥[ªÌ¦h·|»Ýn´X¤ÀÄÁ®É¶¡.."); + pressanykey(); + unlockutmpmode(); + return 0; + } close(0); close(1); setproctitle("open ticket"); #ifdef CPULIMIT - { - struct rlimit rml; - rml.rlim_cur = RLIM_INFINITY; - rml.rlim_max = RLIM_INFINITY; - setrlimit(RLIMIT_CPU, &rml); - } -#endif - - - bet -= 1; //Âন¯x°}ªºindex - - total=load_ticket_record(path, ticket); - setbfile(buf,bh->brdname,FN_TICKET_END); - if(!(fp1 = fopen(buf,"r"))) - exit(1); - - // ÁÙ¨S¶}§¹¼ú¤£¯à½ä³Õ ¥unmv¤@¶µ´N¦n - if(bet!=98) - { - money=total*price; - demoney(money*0.02); - mail_redenvelop("[½ä³õ©âÀY]", cuser.userid, money*0.02, 'n'); - money = ticket[bet] ? money*0.95/ticket[bet]:9999999; - } - else - { - vice(price*10, "½ä½L°h¿ú¤âÄò¶O"); - money=price; - } - setbfile(outcome,bh->brdname,FN_TICKET_OUTCOME); - if((fp = fopen(outcome, "w"))) - { - fprintf(fp,"½ä½L»¡©ú\n"); - while(fgets(buf,256,fp1)) - { - buf[255]=0; - fprintf(fp,"%s",buf); - } - fprintf(fp,"¤Uª`±¡ªp\n"); - - fprintf(fp, "\033[33m"); - for(i = 0 ; i<count; i++) - { - fprintf(fp, "%d.%-8s: %-7d",i+1,betname[i], ticket[i]); - if(i==3) fprintf(fp,"\n"); - } - fprintf(fp, "\033[m\n"); - - if(bet!=98) - { - fprintf(fp, "\n\n¶}¼ú®É¶¡¡G %s \n\n" - "¶}¼úµ²ªG¡G %s \n\n" - "©Ò¦³ª÷ÃB¡G %d ¤¸ \n" - "¤¤¼ú¤ñ¨Ò¡G %d±i/%d±i (%f)\n" - "¨C±i¤¤¼ú±m²¼¥i±o %d ªT¢Þ¹ô \n\n", - Cdatelite(&now), betname[bet], total*price, ticket[bet], total, - (float) ticket[bet] / total, money); - - fprintf(fp, "%s ½ä½L¶}¥X:%s ©Ò¦³ª÷ÃB:%d ¤¸ ¼úª÷/±i:%d ¤¸ ¾÷²v:%1.2f\n\n", - Cdatelite(&now), betname[bet], total*price, money, - total? (float)ticket[bet] / total:0); - } - else - fprintf(fp, "\n\n½ä½L¨ú®ø°h¿ú¡G %s \n\n", Cdatelite(&now)); - + { + struct rlimit rml; + rml.rlim_cur = RLIM_INFINITY; + rml.rlim_max = RLIM_INFINITY; + setrlimit(RLIMIT_CPU, &rml); + } +#endif + + + bet -= 1; /* Âন¯x°}ªºindex */ + + total = load_ticket_record(path, ticket); + setbfile(buf, bh->brdname, FN_TICKET_END); + if (!(fp1 = fopen(buf, "r"))) + exit(1); + + /* ÁÙ¨S¶}§¹¼ú¤£¯à½ä³Õ ¥unmv¤@¶µ´N¦n */ + if (bet != 98) { + money = total * price; + demoney(money * 0.02); + mail_redenvelop("[½ä³õ©âÀY]", cuser.userid, money * 0.02, 'n'); + money = ticket[bet] ? money * 0.95 / ticket[bet] : 9999999; + } else { + vice(price * 10, "½ä½L°h¿ú¤âÄò¶O"); + money = price; + } + setbfile(outcome, bh->brdname, FN_TICKET_OUTCOME); + if ((fp = fopen(outcome, "w"))) { + fprintf(fp, "½ä½L»¡©ú\n"); + while (fgets(buf, 256, fp1)) { + buf[255] = 0; + fprintf(fp, "%s", buf); + } + fprintf(fp, "¤Uª`±¡ªp\n"); + + fprintf(fp, "\033[33m"); + for (i = 0; i < count; i++) { + fprintf(fp, "%d.%-8s: %-7d", i + 1, betname[i], ticket[i]); + if (i == 3) + fprintf(fp, "\n"); + } + fprintf(fp, "\033[m\n"); + + if (bet != 98) { + fprintf(fp, "\n\n¶}¼ú®É¶¡¡G %s \n\n" + "¶}¼úµ²ªG¡G %s \n\n" + "©Ò¦³ª÷ÃB¡G %d ¤¸ \n" + "¤¤¼ú¤ñ¨Ò¡G %d±i/%d±i (%f)\n" + "¨C±i¤¤¼ú±m²¼¥i±o %d ªT¢Þ¹ô \n\n", + Cdatelite(&now), betname[bet], total * price, ticket[bet], total, + (float)ticket[bet] / total, money); + + fprintf(fp, "%s ½ä½L¶}¥X:%s ©Ò¦³ª÷ÃB:%d ¤¸ ¼úª÷/±i:%d ¤¸ ¾÷²v:%1.2f\n\n", + Cdatelite(&now), betname[bet], total * price, money, + total ? (float)ticket[bet] / total : 0); + } else + fprintf(fp, "\n\n½ä½L¨ú®ø°h¿ú¡G %s \n\n", Cdatelite(&now)); + } - fclose(fp1); + fclose(fp1); setbfile(buf, bh->brdname, FN_TICKET_END); setbfile(path, bh->brdname, FN_TICKET_LOCK); - rename(buf, path); + rename(buf, path); /* - ¥H¤U¬Oµ¹¿ú°Ê§@ - */ + * ¥H¤U¬Oµ¹¿ú°Ê§@ + */ setbfile(buf, bh->brdname, FN_TICKET_USER); - if ((bet==98 || ticket[bet]) && (fp1 = fopen(buf, "r"))) - { - int mybet, uid; - char userid[IDLEN]; - - while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) - { - if (bet==98 && mybet>=0 && mybet<count ) - { - fprintf(fp,"%s ¶R¤F %d ±i %s, °h¦^ %d ªT¢Þ¹ô\n" - ,userid, i, betname[mybet], money); - sprintf(buf, "%s ½ä³õ°h¿ú! $ %d", bh->brdname, money * i); - } - else if (mybet == bet) - { - fprintf(fp,"®¥³ß %s ¶R¤F%d ±i %s, Àò±o %d ªT¢Þ¹ô\n" - ,userid, i, betname[mybet], money); - sprintf(buf, "%s ¤¤¼ú«¨! $ %d", bh->brdname, money * i); - } - else - continue; - if((uid=searchuser(userid))==0) continue; - deumoney(uid, money * i); - mail_id(userid, buf, "etc/ticket.win", "Ptt½ä³õ"); - } - fclose(fp1); - } + if ((bet == 98 || ticket[bet]) && (fp1 = fopen(buf, "r"))) { + int mybet, uid; + char userid[IDLEN]; + while (fscanf(fp1, "%s %d %d\n", userid, &mybet, &i) != EOF) { + if (bet == 98 && mybet >= 0 && mybet < count) { + fprintf(fp, "%s ¶R¤F %d ±i %s, °h¦^ %d ªT¢Þ¹ô\n" + ,userid, i, betname[mybet], money); + sprintf(buf, "%s ½ä³õ°h¿ú! $ %d", bh->brdname, money * i); + } else if (mybet == bet) { + fprintf(fp, "®¥³ß %s ¶R¤F%d ±i %s, Àò±o %d ªT¢Þ¹ô\n" + ,userid, i, betname[mybet], money); + sprintf(buf, "%s ¤¤¼ú«¨! $ %d", bh->brdname, money * i); + } else + continue; + if ((uid = searchuser(userid)) == 0) + continue; + deumoney(uid, money * i); + mail_id(userid, buf, "etc/ticket.win", "Ptt½ä³õ"); + } + fclose(fp1); + } fclose(fp); - if(bet!=98) - sprintf(buf, "[¤½§i] %s ½ä½L¶}¼ú", bh->brdname); + if (bet != 98) + sprintf(buf, "[¤½§i] %s ½ä½L¶}¼ú", bh->brdname); else - sprintf(buf, "[¤½§i] %s ½ä½L¨ú®ø", bh->brdname); + sprintf(buf, "[¤½§i] %s ½ä½L¨ú®ø", bh->brdname); post_file(bh->brdname, buf, outcome, "[½ä¯«]"); - post_file("Record", buf+7, outcome, "[°¨¸ô±´¤l]"); + post_file("Record", buf + 7, outcome, "[°¨¸ô±´¤l]"); - setbfile(buf, bh->brdname, FN_TICKET_RECORD); + setbfile(buf, bh->brdname, FN_TICKET_RECORD); unlink(buf); - setbfile(buf, bh->brdname, FN_TICKET_USER); + setbfile(buf, bh->brdname, FN_TICKET_USER); unlink(buf); - setbfile(buf, bh->brdname, FN_TICKET_LOCK); + setbfile(buf, bh->brdname, FN_TICKET_LOCK); unlink(buf); exit(1); return 0; } -int ticket_main() { +int +ticket_main() +{ ticket(0); return 0; } diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c index 6969df7a..1eb6ca77 100644 --- a/mbbsd/gomo.c +++ b/mbbsd/gomo.c @@ -1,17 +1,19 @@ -/* $Id: gomo.c,v 1.5 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: gomo.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static char *chess[] = { "¡´", "¡³" }; -static int tick, lastcount, mylasttick, hislasttick; +static char *chess[] = {"¡´", "¡³"}; +static int tick, lastcount, mylasttick, hislasttick; typedef struct { - char x; - char y; -} Horder_t; + char x; + char y; +} Horder_t; static Horder_t *v, pool[225]; -static void HO_init() { +static void +HO_init() +{ memset(pool, 0, sizeof(pool)); v = pool; pat = pat_gomoku; @@ -19,82 +21,92 @@ static void HO_init() { memset(ku, 0, sizeof(ku)); } -static void HO_add(Horder_t *mv) { +static void +HO_add(Horder_t * mv) +{ *v++ = *mv; } -static void HO_undo(Horder_t *mv) { - char *str = "¢z¢s¢{¢u¢q¢t¢|¢r¢}"; - int n1, n2, loc; +static void +HO_undo(Horder_t * mv) +{ + char *str = "¢z¢s¢{¢u¢q¢t¢|¢r¢}"; + int n1, n2, loc; *mv = *(--v); ku[(int)mv->x][(int)mv->y] = BBLANK; BGOTO(mv->x, mv->y); n1 = (mv->x == 0) ? 0 : (mv->x == 14) ? 2 : 1; - n2 = (mv->y == 14)? 0 : (mv->y == 0) ? 2 : 1; - loc= 2 * ( n2 * 3 + n1); + n2 = (mv->y == 14) ? 0 : (mv->y == 0) ? 2 : 1; + loc = 2 * (n2 * 3 + n1); prints("%.2s", str + loc); } -static void HO_log(char *user) { - int i; - FILE *log; - char buf[80]; - char buf1[80]; - char title[80]; - Horder_t *ptr = pool; - fileheader_t mymail; +static void +HO_log(char *user) +{ + int i; + FILE *log; + char buf[80]; + char buf1[80]; + char title[80]; + Horder_t *ptr = pool; + fileheader_t mymail; sprintf(buf, "home/%c/%s/F.%d", cuser.userid[0], cuser.userid, rand() & 65535); log = fopen(buf, "w"); - - for(i = 1; i < 17; i++) + + for (i = 1; i < 17; i++) fprintf(log, "%.*s\n", big_picture[i].len, big_picture[i].data); - + i = 0; do { fprintf(log, "[%2d]%s ==> %c%d%c", i + 1, chess[i % 2], - 'A' + ptr->x, ptr->y + 1, (i % 2) ? '\n' : '\t'); + 'A' + ptr->x, ptr->y + 1, (i % 2) ? '\n' : '\t'); i++; - } while( ++ptr < v); + } while (++ptr < v); fclose(log); - + sethomepath(buf1, cuser.userid); stampfile(buf1, &mymail); - - mymail.filemode = FILE_READ|FILE_HOLD; + + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]"); sprintf(mymail.title, "\033[37;41m´ÑÃÐ\033[m %s VS %s", cuser.userid, user); sethomedir(title, cuser.userid); Rename(buf, buf1); - append_record(title, &mymail, sizeof(mymail)); - + append_record(title, &mymail, sizeof(mymail)); + unlink(buf); } -static int countgomo() { - Horder_t *ptr; - int i; - +static int +countgomo() +{ + Horder_t *ptr; + int i; + ptr = pool; i = 0; do { i++; - } while(++ptr < v); + } while (++ptr < v); return i; } -static int chkmv(Horder_t *mv, int color, int limit) { - char *xtype[] = {"\033[1;31m¸õ¤T\033[m", "\033[1;31m¬¡¤T\033[m", - "\033[1;31m¦º¥|\033[m", "\033[1;31m¸õ¥|\033[m", - "\033[1;31m¬¡¥|\033[m", "\033[1;31m¥|¤T\033[m", - "\033[1;31mÂù¤T\033[m", "\033[1;31mÂù¥|\033[m", - "\033[1;31mÂù¥|\033[m", "\033[1;31m³s¤»\033[m", - "\033[1;31m³s¤\033[m"}; - int rule = getstyle(mv->x, mv->y, color, limit); - if(rule > 1 && rule < 13) { +static int +chkmv(Horder_t * mv, int color, int limit) +{ + char *xtype[] = {"\033[1;31m¸õ¤T\033[m", "\033[1;31m¬¡¤T\033[m", + "\033[1;31m¦º¥|\033[m", "\033[1;31m¸õ¥|\033[m", + "\033[1;31m¬¡¥|\033[m", "\033[1;31m¥|¤T\033[m", + "\033[1;31mÂù¤T\033[m", "\033[1;31mÂù¥|\033[m", + "\033[1;31mÂù¥|\033[m", "\033[1;31m³s¤»\033[m", + "\033[1;31m³s¤\033[m"}; + int rule = getstyle(mv->x, mv->y, color, limit); + if (rule > 1 && rule < 13) { move(15, 40); outs(xtype[rule - 2]); bell(); @@ -102,70 +114,76 @@ static int chkmv(Horder_t *mv, int color, int limit) { return chkwin(rule, limit); } -static int gomo_key(int fd, int ch, Horder_t *mv) { - if( ch >= 'a' && ch <= 'o') { - char pbuf[4], vx, vy; - - *pbuf = ch; - if(fd) +static int +gomo_key(int fd, int ch, Horder_t * mv) +{ + if (ch >= 'a' && ch <= 'o') { + char pbuf[4], vx, vy; + + *pbuf = ch; + if (fd) add_io(0, 0); - oldgetdata(17, 0, "ª½±µ«ü©w¦ì¸m :", pbuf, sizeof(pbuf), DOECHO); - if(fd) + oldgetdata(17, 0, "ª½±µ«ü©w¦ì¸m :", pbuf, sizeof(pbuf), DOECHO); + if (fd) add_io(fd, 0); - vx = pbuf[0] - 'a'; - vy = atoi(pbuf + 1) - 1; - if(vx >= 0 && vx < 15 && vy >= 0 && vy < 15 && - ku[(int)vx][(int)vy] == BBLANK) { + vx = pbuf[0] - 'a'; + vy = atoi(pbuf + 1) - 1; + if (vx >= 0 && vx < 15 && vy >= 0 && vy < 15 && + ku[(int)vx][(int)vy] == BBLANK) { mv->x = vx; mv->y = vy; return 1; - } + } } else { - switch(ch) { + switch (ch) { case KEY_RIGHT: - mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; - break; + mv->x = (mv->x == BRDSIZ - 1) ? mv->x : mv->x + 1; + break; case KEY_LEFT: - mv->x = (mv->x == 0 ) ? 0 : mv->x - 1; - break; + mv->x = (mv->x == 0) ? 0 : mv->x - 1; + break; case KEY_UP: - mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; - break; + mv->y = (mv->y == BRDSIZ - 1) ? mv->y : mv->y + 1; + break; case KEY_DOWN: - mv->y = (mv->y == 0 ) ? 0 : mv->y - 1; - break; + mv->y = (mv->y == 0) ? 0 : mv->y - 1; + break; case ' ': case '\r': - if(ku[(int)mv->x][(int)mv->y] == BBLANK) + if (ku[(int)mv->x][(int)mv->y] == BBLANK) return 1; - } + } } return 0; } -static int reload_gomo() { +static int +reload_gomo() +{ passwd_query(usernum, &xuser); cuser.five_win = xuser.five_win; cuser.five_lose = xuser.five_lose; cuser.five_tie = xuser.five_tie; return 0; -} - -int gomoku(int fd) { - Horder_t mv; - int me, he, win, ch; - int hewantpass, iwantpass; - userinfo_t *my = currutmp; - +} + +int +gomoku(int fd) +{ + Horder_t mv; + int me, he, win, ch; + int hewantpass, iwantpass; + userinfo_t *my = currutmp; + HO_init(); me = !(my->turn) + 1; he = my->turn + 1; win = 1; - tick=now + MAX_TIME; + tick = now + MAX_TIME; lastcount = MAX_TIME; setutmpmode(M_FIVE); clear(); - + prints("\033[1;46m ¤¤l´Ñ¹ï¾Ô \033[45m%30s VS %-30s\033[m", cuser.userid, my->mateid); show_file("etc/@five", 1, -1, ONLY_COLOR); @@ -175,44 +193,44 @@ int gomoku(int fd) { prints("\033[1;33m%s", cuser.userid); move(17, 40); prints("\033[1;33m%s", my->mateid); - + reload_gomo(); move(16, 60); prints("\033[1;31m%d\033[37m³Ó \033[34m%d\033[37m±Ñ \033[36m%d\033[37m©M" "\033[m", cuser.five_win, cuser.five_lose, cuser.five_tie); - - getuser(my->mateid); - move(17, 60); + + getuser(my->mateid); + move(17, 60); prints("\033[1;31m%d\033[37m³Ó \033[34m%d\033[37m±Ñ \033[36m%d\033[37m" "©M\033[m", xuser.five_win, xuser.five_lose, xuser.five_tie); - + cuser.five_lose++; /* ¤@¶i¨Ó¥ý¥[¤@³õ±Ñ³õ, ŤF«á¦A¦©¦^¥h, ÁקK§Ö¿é¤F´c·NÂ_½u */ passwd_update(usernum, &cuser); - + add_io(fd, 0); - + hewantpass = iwantpass = 0; mv.x = mv.y = 7; move(18, 40); prints("%s®É¶¡ÁÙ³Ñ%d:%02d\n", my->turn ? "§Aªº" : "¹ï¤è", - MAX_TIME / 60, MAX_TIME % 60); - for(;;) { + MAX_TIME / 60, MAX_TIME % 60); + for (;;) { move(13, 40); - outs(my->turn ? "½ü¨ì¦Û¤v¤U¤F!": "µ¥«Ý¹ï¤è¤U¤l.."); - if(lastcount != tick-now) { - lastcount = tick-now; + outs(my->turn ? "½ü¨ì¦Û¤v¤U¤F!" : "µ¥«Ý¹ï¤è¤U¤l.."); + if (lastcount != tick - now) { + lastcount = tick - now; move(18, 40); prints("%s®É¶¡ÁÙ³Ñ%d:%02d\n", my->turn ? "§Aªº" : "¹ï¤è", lastcount / 60, lastcount % 60); - if(lastcount <= 0 && my->turn) { + if (lastcount <= 0 && my->turn) { move(19, 40); outs("®É¶¡¤w¨ì, §A¿é¤F"); my->five_lose++; send(fd, '\0', 1, 0); break; } - if(lastcount <= -5 && !my->turn) { + if (lastcount <= -5 && !my->turn) { move(19, 40); outs("¹ï¤â¤Ó¤[¨S¤U, §AŤF!"); win = 1; @@ -222,68 +240,67 @@ int gomoku(int fd) { passwd_update(usernum, &cuser); mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); - mv = *(v - 1); - break; + mv = *(v - 1); + break; } } move(14, 40); - if(hewantpass) { + if (hewantpass) { outs("\033[1;32m©M´Ñn¨D!\033[m"); bell(); } else clrtoeol(); BGOTOCUR(mv.x, mv.y); ch = igetkey(); - if(ch != I_OTHERDATA) + if (ch != I_OTHERDATA) iwantpass = 0; - if(ch == 'q') { - if(countgomo() < 10) { - cuser.five_lose--; + if (ch == 'q') { + if (countgomo() < 10) { + cuser.five_lose--; passwd_update(usernum, &cuser); } send(fd, '\0', 1, 0); break; - } else if(ch == 'u' && !my->turn && v > pool) { + } else if (ch == 'u' && !my->turn && v > pool) { mv.x = mv.y = -1; ch = send(fd, &mv, sizeof(Horder_t), 0); - if(ch == sizeof(Horder_t)) { - HO_undo(&mv); + if (ch == sizeof(Horder_t)) { + HO_undo(&mv); tick = mylasttick; my->turn = 1; continue; - } else + } else break; } - if(ch == 'p') { - if(my->turn ) { - if(iwantpass == 0) { + if (ch == 'p') { + if (my->turn) { + if (iwantpass == 0) { iwantpass = 1; mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); mv = *(v - 1); } continue; - } else if(hewantpass) { + } else if (hewantpass) { win = 0; cuser.five_lose--; cuser.five_tie++; my->five_tie++; passwd_update(usernum, &cuser); - mv.x=mv.y=-2; + mv.x = mv.y = -2; send(fd, &mv, sizeof(Horder_t), 0); mv = *(v - 1); break; } } - - if(ch == I_OTHERDATA) { + if (ch == I_OTHERDATA) { ch = recv(fd, &mv, sizeof(Horder_t), 0); - if(ch != sizeof(Horder_t)) { - lastcount=tick-now; - if(lastcount >=0) { + if (ch != sizeof(Horder_t)) { + lastcount = tick - now; + if (lastcount >= 0) { win = 1; cuser.five_lose--; - if(countgomo() >=10) { + if (countgomo() >= 10) { cuser.five_win++; my->five_win++; } @@ -296,8 +313,8 @@ int gomoku(int fd) { my->five_lose++; break; } - } else if(mv.x == -2 && mv.y == -2) { - if(iwantpass == 1) { + } else if (mv.x == -2 && mv.y == -2) { + if (iwantpass == 1) { win = 0; cuser.five_lose--; cuser.five_tie++; @@ -310,15 +327,14 @@ int gomoku(int fd) { continue; } } - if(my->turn && mv.x == -1 && mv.y == -1) { + if (my->turn && mv.x == -1 && mv.y == -1) { outmsg("¹ï¤è®¬´Ñ"); tick = hislasttick; HO_undo(&mv); my->turn = 0; continue; } - - if(!my->turn) { + if (!my->turn) { win = chkmv(&mv, he, he == BBLACK); HO_add(&mv); hislasttick = tick; @@ -327,16 +343,16 @@ int gomoku(int fd) { bell(); BGOTO(mv.x, mv.y); outs(chess[he - 1]); - - if(win) { + + if (win) { outmsg(win == 1 ? "¹ï¤èŤF!" : "¹ï¤è¸T¤â"); - if(win != 1) { + if (win != 1) { cuser.five_lose--; cuser.five_win++; my->five_win++; passwd_update(usernum, &cuser); } else - my->five_lose++; + my->five_lose++; win = -win; break; } @@ -344,33 +360,32 @@ int gomoku(int fd) { } continue; } - - if(my->turn) { - if(gomo_key(fd, ch, &mv)) + if (my->turn) { + if (gomo_key(fd, ch, &mv)) my->turn = 0; else continue; - - if(!my->turn) { + + if (!my->turn) { HO_add(&mv); BGOTO(mv.x, mv.y); outs(chess[me - 1]); - win = chkmv( &mv, me, me == BBLACK); + win = chkmv(&mv, me, me == BBLACK); ku[(int)mv.x][(int)mv.y] = me; mylasttick = tick; - tick = now + MAX_TIME; /*˼Æ*/ + tick = now + MAX_TIME; /* Ë¼Æ */ lastcount = MAX_TIME; - if(send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) + if (send(fd, &mv, sizeof(Horder_t), 0) != sizeof(Horder_t)) break; - if(win) { - outmsg(win == 1 ? "§ÚĹÅo~~" : "¸T¤â¿é¤F" ); - if(win == 1) { + if (win) { + outmsg(win == 1 ? "§ÚĹÅo~~" : "¸T¤â¿é¤F"); + if (win == 1) { cuser.five_lose--; cuser.five_win++; my->five_win++; passwd_update(usernum, &cuser); - } else - my->five_lose++; + } else + my->five_lose++; break; } move(15, 40); @@ -380,13 +395,13 @@ int gomoku(int fd) { } add_io(0, 0); close(fd); - + igetch(); - if(v > pool) { - char ans[4]; - - getdata(19 , 0, "n«O¯d¥»§½¦¨´ÑÃжÜ?(y/N)", ans, sizeof(ans), LCECHO); - if(*ans == 'y') + if (v > pool) { + char ans[4]; + + getdata(19, 0, "n«O¯d¥»§½¦¨´ÑÃжÜ?(y/N)", ans, sizeof(ans), LCECHO); + if (*ans == 'y') HO_log(my->mateid); } return 0; diff --git a/mbbsd/gomo1.c b/mbbsd/gomo1.c index c741f538..462ceb47 100644 --- a/mbbsd/gomo1.c +++ b/mbbsd/gomo1.c @@ -1,87 +1,95 @@ -/* $Id: gomo1.c,v 1.2 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: gomo1.c,v 1.3 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) /* pattern and advance map */ -static int intrevcmp(const void *a, const void *b) { +static int +intrevcmp(const void *a, const void *b) +{ return (*(int *)b - *(int *)a); } /* 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) { +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) { x += dx; y += dy; - - if((x < 0) || (x >= BRDSIZ) || ( y < 0) || ( y >= BRDSIZ)) { + + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) { n += k; break; - } else if(ku[x][y] != BBLANK) { + } else if (ku[x][y] != BBLANK) { n += k; - if(ku[x][y] != color) + if (ku[x][y] != color) break; } } - - if(i >= 5) + + if (i >= 5) n += k; return n; } -int chkwin(int style, int limit) { - if(style == 0x0c) - return 1 /* style */; - else if(limit == 0) { - if(style == 0x0b) - return 1 /* style */; +int +chkwin(int style, int limit) +{ + if (style == 0x0c) + return 1 /* style */ ; + else if (limit == 0) { + if (style == 0x0b) + return 1 /* style */ ; return 0; } - if((style < 0x0c) && (style > 0x07)) - return -1 /* -style */; + if ((style < 0x0c) && (style > 0x07)) + return -1 /* -style */ ; return 0; } /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit:1,0 ; dx,dy: 0,1 */ -static int dirchk(int x, int y, int color, int limit, int dx, int dy) { - int le, ri, loc, style = 0; +static int +dirchk(int x, int y, int color, int limit, int dx, int dy) +{ + int le, ri, loc, style = 0; le = gomo_getindex(x, y, color, -dx, -dy); - ri = gomo_getindex(x, y, color, dx, dy); + ri = gomo_getindex(x, y, color, dx, dy); loc = (le > ri) ? (((le * (le + 1)) >> 1) + ri) : (((ri * (ri + 1)) >> 1) + le); - + style = pat[loc]; - - if(limit == 0) + + if (limit == 0) return (style & 0x0f); style >>= 4; - - if((style == 3) || (style == 2)) { - int i, n = 0, tmp, nx, ny; - + + if ((style == 3) || (style == 2)) { + int i, n = 0, tmp, nx, ny; + n = adv[loc >> 1]; - + ((loc & 1) == 0) ? (n >>= 4) : (n &= 0x0f); - + ku[x][y] = color; - - for(i = 0; i < 2; i++) { - if((tmp = (i == 0) ? (-(n >> 2)):(n & 3)) != 0) { + + for (i = 0; i < 2; i++) { + if ((tmp = (i == 0) ? (-(n >> 2)) : (n & 3)) != 0) { nx = x + (le > ri ? 1 : -1) * tmp * dx; ny = y + (le > ri ? 1 : -1) * tmp * dy; - - if((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && - (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) + + if ((dirchk(nx, ny, color, 0, dx, dy) == 0x06) && + (chkwin(getstyle(nx, ny, color, limit), limit) >= 0)) break; } } - if(i >= 2) + if (i >= 2) style = 0; ku[x][y] = BBLANK; } @@ -92,26 +100,28 @@ static int dirchk(int x, int y, int color, int limit, int dx, int dy) { /* ¥|¤T=7 ¬¡¥|=6 Â_¥|=5 ¦º¥|=4 ¬¡¤T=3 Â_¤T=2 «O¯d=1 µL®Ä=0 */ /* x,y: 0..BRDSIZ-1 ; color: CBLACK,CWHITE ; limit: 1,0 */ -int getstyle(int x, int y, int color, int limit) { - int i, j, dir[4], style; +int +getstyle(int x, int y, int color, int limit) +{ + int i, j, dir[4], style; - if((x < 0) || (x >= BRDSIZ) || ( y < 0) || (y >= BRDSIZ)) + if ((x < 0) || (x >= BRDSIZ) || (y < 0) || (y >= BRDSIZ)) return 0x0f; - if(ku[x][y] != BBLANK) + if (ku[x][y] != BBLANK) return 0x0d; - for(i = 0; i < 4; i++) - dir[i] = dirchk(x, y, color, limit, i ? (i>>1) : -1, i ? (i&1) : 1); + for (i = 0; i < 4; i++) + dir[i] = dirchk(x, y, color, limit, i ? (i >> 1) : -1, i ? (i & 1) : 1); qsort(dir, 4, sizeof(int), (QCAST)intrevcmp); - if((style = dir[0]) >= 2) { - for(i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { - if((style > j) || (dir[i] < 2)) + if ((style = dir[0]) >= 2) { + for (i = 1, j = 6 + (limit ? 1 : 0); i < 4; i++) { + if ((style > j) || (dir[i] < 2)) break; - if(dir[i] > 3) + if (dir[i] > 3) style = 9; - else if((style < 7) && (style > 3)) + else if ((style < 7) && (style > 3)) style = 7; else style = 8; diff --git a/mbbsd/guess.c b/mbbsd/guess.c index 2a7e6fdb..1f683ce2 100644 --- a/mbbsd/guess.c +++ b/mbbsd/guess.c @@ -1,159 +1,177 @@ -/* $Id: guess.c,v 1.3 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: guess.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define LOGPASS BBSHOME "/etc/winguess.log" -static void show_table(char TABLE[], char ifcomputer) { - int i; - +static void +show_table(char TABLE[], char ifcomputer) +{ + int i; + move(0, 35); prints("\033[1;44;33m ¡i ²q¼Æ¦r ¡j \033[m"); move(8, 1); prints("\033[1;44;36m¥Ø «e ¿ ²v\033[m\n"); prints("\033[1;33m=================\033[m\n"); - if(ifcomputer) { + if (ifcomputer) { prints("Ĺ¹q¸£: 2 ¿\n"); prints("¿é¹q¸£: 0 ¿\n"); } else { - for(i = 1; i <= 6; i++) - prints("²Ä%d¦¸, %02d¿\n",i,TABLE[i]); + for (i = 1; i <= 6; i++) + prints("²Ä%d¦¸, %02d¿\n", i, TABLE[i]); } prints("\033[33m=================\033[m"); } -static unsigned long int get_money(void) { - int money, i; - char data[20]; - +static unsigned long int +get_money(void) +{ + int money, i; + char data[20]; + move(1, 0); prints("±z¥Ø«e¦³:%d Ptt$", cuser.money); do { getdata(2, 0, "n½ä¦h¤Ö(5-10©Î«öqÂ÷¶}): ", data, 9, LCECHO); money = strlen(data); - if(data[0] == 'q' || data[0] == 'Q') { + if (data[0] == 'q' || data[0] == 'Q') { unlockutmpmode(); return 0; } - for(i = 0; i < money; i++) - if(data[i]<'0' || data[i]>'9') { + for (i = 0; i < money; i++) + if (data[i] < '0' || data[i] > '9') { money = -1; break; } - if(money != -1){ + if (money != -1) { money = atol(data); reload_money(); - if(money > cuser.money || money <= 4 || money > 10 || - money < 1) + if (money > cuser.money || money <= 4 || money > 10 || + money < 1) money = -1; - } - } while(money == -1); - move(1,0); + } + } while (money == -1); + move(1, 0); clrtoeol(); reload_money(); prints("±z¥Ø«e¦³:%d Ptt$", cuser.money - money); return money; } -static int check_data(char *str) { - int i, j; - - if(strlen(str) != 4) +static int +check_data(char *str) +{ + int i, j; + + if (strlen(str) != 4) return -1; - for(i = 0; i < 4; i++) - if(str[i] < '0' || str[i] > '9') + for (i = 0; i < 4; i++) + if (str[i] < '0' || str[i] > '9') return -1; - for(i = 0; i < 4; i++) - for(j = i + 1; j < 4; j++) - if(str[i] == str[j]) + for (i = 0; i < 4; i++) + for (j = i + 1; j < 4; j++) + if (str[i] == str[j]) return -1; return 1; } -static char *get_data(int count) { - static char data[5]; - while(1) { +static char * +get_data(int count) +{ + static char data[5]; + while (1) { getdata(6, 0, "¿é¤J¥|¦ì¼Æ¦r(¤£«½Æ): ", data, sizeof(data), LCECHO); - if(check_data(data) == 1) + if (check_data(data) == 1) break; } return data; } -static int guess_play(char *data, char *answer, int count) { - int A_num = 0, B_num = 0; - int i, j; - - for(i = 0; i < 4; i++) { - if(data[i] == answer[i]) +static int +guess_play(char *data, char *answer, int count) +{ + int A_num = 0, B_num = 0; + int i, j; + + for (i = 0; i < 4; i++) { + if (data[i] == answer[i]) A_num++; - for(j = 0; j < 4; j++) - if(i == j) + for (j = 0; j < 4; j++) + if (i == j) continue; - else if(data[i] == answer[j]) { + else if (data[i] == answer[j]) { B_num++; break; } } - if(A_num == 4) + if (A_num == 4) return 1; - move(count + 8,55); + move(count + 8, 55); prints("%s => \033[1;32m%dA %dB\033[m", data, A_num, B_num); return 0; } -static int result(int correct, int number) { - char a = 0, b = 0, i, j; - char n1[5], n2[5]; - - sprintf(n1, "%04d",correct); - sprintf(n2, "%04d",number); - for(i = 0; i < 4; i++) - for(j = 0; j < 4; j++) - if(n1[(int)i] == n2[(int)j]) +static int +result(int correct, int number) +{ + char a = 0, b = 0, i, j; + char n1[5], n2[5]; + + sprintf(n1, "%04d", correct); + sprintf(n2, "%04d", number); + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + if (n1[(int)i] == n2[(int)j]) b++; - for(i = 0; i < 4; i++) - if(n1[(int)i] == n2[(int)i]) { + for (i = 0; i < 4; i++) + if (n1[(int)i] == n2[(int)i]) { b--; a++; } return 10 * a + b; } -static int legal(int number) { - char i, j; - char temp[5]; - +static int +legal(int number) +{ + char i, j; + char temp[5]; + sprintf(temp, "%04d", number); - for(i = 0; i < 4; i++) - for(j = i + 1; j < 4; j++) - if(temp[(int)i] == temp[(int)j]) + for (i = 0; i < 4; i++) + for (j = i + 1; j < 4; j++) + if (temp[(int)i] == temp[(int)j]) return 0; return 1; } -static void initcomputer(char flag[]) { - int i; - - for(i = 0; i < 10000; i++) - if(legal(i)) +static void +initcomputer(char flag[]) +{ + int i; + + for (i = 0; i < 10000; i++) + if (legal(i)) flag[i] = 1; - else + else flag[i] = 0; } -static int computer(int correct, int total, char flag[], int n[]) { - int guess; - static int j; - int k,i; - char data[5]; - - if(total == 1) { +static int +computer(int correct, int total, char flag[], int n[]) +{ + int guess; + static int j; + int k, i; + char data[5]; + + if (total == 1) { do { guess = rand() % 10000; - } while(!legal(guess)); - } else + } while (!legal(guess)); + } else guess = n[rand() % j]; k = result(correct, guess); - if(k == 40) { + if (k == 40) { move(total + 8, 25); sprintf(data, "%04d", guess); prints("%s => ²q¤¤¤F!!", data); @@ -164,25 +182,27 @@ static int computer(int correct, int total, char flag[], int n[]) { prints("%s => \033[1;32m%dA %dB\033[m", data, k / 10, k % 10); } j = 0; - for(i = 0; i < 10000; i++) - if(flag[i]) { - if(result(i, guess) != k) + for (i = 0; i < 10000; i++) + if (flag[i]) { + if (result(i, guess) != k) flag[i] = 0; - else + else n[j++] = i; } return 0; } -static void Diff_Random(char *answer) { - register int i = 0, j, k; - - while(i < 4) { +static void +Diff_Random(char *answer) +{ + register int i = 0, j, k; + + while (i < 4) { k = rand() % 10 + '0'; - for(j = 0; j < i; j++) - if(k == answer[j]) + for (j = 0; j < i; j++) + if (k == answer[j]) break; - if(j == i) { + if (j == i) { answer[j] = k; i++; } @@ -192,24 +212,26 @@ static void Diff_Random(char *answer) { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int guess_main() { +int +guess_main() +{ unsigned long int money; - char computerwin = 0,youwin = 0; - int count = 0,c_count = 0; - char ifcomputer[2]; - char answer[5]; - int *n = NULL; - char yournum[5]; - char *flag = NULL; - static char TABLE[]={0,10,8,4,2,1,0,0,0,0,0}; - FILE *file; + char computerwin = 0, youwin = 0; + int count = 0, c_count = 0; + char ifcomputer[2]; + char answer[5]; + int *n = NULL; + char yournum[5]; + char *flag = NULL; + static char TABLE[] = {0, 10, 8, 4, 2, 1, 0, 0, 0, 0, 0}; + FILE *file; clear(); showtitle("²q¼Æ¦r", BBSName); lockreturn0(GUESSNUM, LOCK_MULTI); reload_money(); - if(cuser.money < 5) { + if (cuser.money < 5) { clear(); move(12, 35); prints("¿ú¤£°÷°Õ ¦Ü¤Ön 5 Ptt$"); @@ -217,29 +239,29 @@ int guess_main() { pressanykey(); return 1; } - if((money = get_money()) == 0) - return 1; - vice(money,"²q¼Æ¦r"); - + if ((money = get_money()) == 0) + return 1; + vice(money, "²q¼Æ¦r"); + Diff_Random(answer); move(2, 0); clrtoeol(); prints("±z¤Uª` :%d Ptt$", money); - + getdata_str(4, 0, "±zn©M¹q¸£¤ñÁɶÜ? <y/n>[y]:", - ifcomputer, sizeof(ifcomputer), LCECHO, "y"); - if(ifcomputer[0] == 'y') { + ifcomputer, sizeof(ifcomputer), LCECHO, "y"); + if (ifcomputer[0] == 'y') { ifcomputer[0] = 1; show_table(TABLE, 1); } else { ifcomputer[0] = 0; show_table(TABLE, 0); } - if(ifcomputer[0]) { + if (ifcomputer[0]) { do { getdata(5, 0, "½Ð¿é¤J±znÅý¹q¸£²qªº¼Æ¦r: ", yournum, sizeof(yournum), LCECHO); - } while(!legal(atoi(yournum))); + } while (!legal(atoi(yournum))); move(8, 25); prints("¹q¸£²q"); flag = malloc(sizeof(char) * 10000); @@ -248,46 +270,47 @@ int guess_main() { } move(8, 55); prints("§A²q"); - while(((!computerwin || !youwin) && count <10 && (ifcomputer[0])) || - (!ifcomputer[0] && count < 10 && !youwin)) { - if(!computerwin && ifcomputer[0]) { + while (((!computerwin || !youwin) && count < 10 && (ifcomputer[0])) || + (!ifcomputer[0] && count < 10 && !youwin)) { + if (!computerwin && ifcomputer[0]) { ++c_count; - if(computer(atoi(yournum), c_count, flag, n)) - computerwin = 1; + if (computer(atoi(yournum), c_count, flag, n)) + computerwin = 1; } move(20, 55); prints("²Ä %d ¦¸¾÷·| ", count + 1); - if(!youwin) { + if (!youwin) { ++count; - if(guess_play(get_data(count),answer,count)) - youwin=1; + if (guess_play(get_data(count), answer, count)) + youwin = 1; } } move(17, 35); - if(ifcomputer[0]) { + if (ifcomputer[0]) { free(flag); free(n); - if(count > c_count) { + if (count > c_count) { prints("§A¿éµ¹¹q¸£¤F"); move(18, 35); prints("§A½ß¤F %d ", money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "¹q¸£²Ä%d¦¸²q¤¤, ", c_count); - if(youwin) + if (youwin) fprintf(file, "%s ²Ä%d¦¸²q¤¤, ", cuser.userid, count); else - fprintf(file, "%s ¨S²q¤¤, ", cuser.userid); - fprintf(file,"¹q¸£ÁȨ«¤F%s %ld Ptt$\n", cuser.userid, money); + fprintf(file, "%s ¨S²q¤¤, ", cuser.userid); + fprintf(file, "¹q¸£ÁȨ«¤F%s %ld Ptt$\n", cuser.userid, money); fclose(file); } unlockutmpmode(); pressanykey(); - return 1; - } else if(count < c_count) { + return 1; + } else if (count < c_count) { prints("¯u¼F®`, Åý§AÁȨìÅo"); - move(18,35);prints("§AÁȨ«¤F %d ",money*2); - demoney(money*2); - if((file = fopen(LOGPASS,"a"))) { + move(18, 35); + prints("§AÁȨ«¤F %d ", money * 2); + demoney(money * 2); + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, ²Ä%d¦¸²q¤¤, ¹q¸£²Ä%d¦¸²q¤¤, " "ŤF¹q¸£ %ld Ptt$\n", cuser.userid, count, c_count, money * 2); @@ -299,7 +322,7 @@ int guess_main() { } else { prints("¯u¼F®`, ©M¹q¸£¥´¦¨¥¤â¤F, ®³¦^¥»¿ú%d\n", money); demoney(money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s ©M¹q¸£¥´¦¨¤F¥¤â\n", cuser.userid); fclose(file); } @@ -308,29 +331,28 @@ int guess_main() { return 1; } } - if(youwin) { - demoney(TABLE[count]*money); - if(count < 5) { + if (youwin) { + demoney(TABLE[count] * money); + if (count < 5) { prints("¯u¼F®`, ¿ú³Q§AÁȨ«¤F"); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, ²Ä%d¦¸²q¤¤, ŤF %ld Ptt$\n", cuser.userid, count, TABLE[count] * money); fclose(file); } - } else if(count > 5) { + } else if (count > 5) { prints("ü, ¤Ó¦h¦¸¤~²q¥X¨Ó¤F"); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, ²Ä%d¦¸¤~²q¤¤, ½ß¤F %ld Ptt$\n", cuser.userid, count, money); fclose(file); } - } - else { + } else { prints("¤¦¸²q¥X¨Ó, ÁÙ§A¥»¿ú§a"); - move(18,35); + move(18, 35); clrtoeol(); prints("§A®³¦^¤F%d Ptt$\n", money); - if((file = fopen(LOGPASS,"a"))) { + if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, ²Ä%d¦¸²q¤¤, ®³¦^¤F¥»¿ú %ld Ptt$\n", cuser.userid, count, money); fclose(file); @@ -340,12 +362,12 @@ int guess_main() { pressanykey(); return 1; } - move(17,35); + move(17, 35); prints("¼K¼K ¼Ð·Çµª®×¬O %s ", answer); - move(18,35); + move(18, 35); prints("¤U¦¸¦A¨Ó§a"); - if((file = fopen(BBSHOME "/etc/loseguess.log","a"))) { - fprintf(file,"id: %s ½ä¤F %ld Ptt$\n",cuser.userid,money); + if ((file = fopen(BBSHOME "/etc/loseguess.log", "a"))) { + fprintf(file, "id: %s ½ä¤F %ld Ptt$\n", cuser.userid, money); fclose(file); } return 1; diff --git a/mbbsd/indict.c b/mbbsd/indict.c index ca44033a..5a575211 100644 --- a/mbbsd/indict.c +++ b/mbbsd/indict.c @@ -1,30 +1,31 @@ -/* $Id: indict.c,v 1.4 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: indict.c,v 1.5 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define REFER "etc/dicts" -static void addword(char word[]) +static void +addword(char word[]) { - char buf[150],temp[150],a[3]; - FILE *fp = fopen(database,"r+"); + char buf[150], temp[150], a[3]; + FILE *fp = fopen(database, "r+"); - if( fp == NULL ){ + if (fp == NULL) { vmsg("database error"); - return ; + return; } - fgets(buf,130,fp); - fseek(fp,0,2); - if(HAVE_PERM(PERM_LOGINOK)) { + fgets(buf, 130, fp); + fseek(fp, 0, 2); + if (HAVE_PERM(PERM_LOGINOK)) { clear(); - move(4,0); + move(4, 0); outs(" \033[31mĵ§i\033[m:Y»W·N¶ñ¼g°²¸ê®Æ±N\033[36m¬åid\033[m³B¥÷\n"); sprintf(temp, "\n¿é¤J½d§Q\n:\033[33m%s\033[m", buf); outs(temp); outs("\n½Ð¨Ì¤W¦C½d¨Ò¿é¤J¤@¦æ¸ê®Æ(ª½±µenter©ñ±ó)\n"); getdata(10, 0, ":", buf, 65, DOECHO); - if(buf[0]) { + if (buf[0]) { getdata(13, 0, "½T©w·s¼W?(Y/n)", a, sizeof(a), LCECHO); - if(a[0] != 'n') + if (a[0] != 'n') fprintf(fp, "%-65s[%s]\n", buf, cuser.userid); } } @@ -32,29 +33,31 @@ static void addword(char word[]) clear(); } -static int choose_dict(void) { - int c; - FILE *fp; - char buf[10][21], data[10][21], cho[130]; +static int +choose_dict(void) +{ + int c; + FILE *fp; + char buf[10][21], data[10][21], cho[130]; move(12, 0); clrtobot(); outs(" " "¡´ \033[45;33m¦r¨åò ¡º n¬dþ¤@¥»¡H\033[m ¡´"); - if((fp = fopen(REFER, "r"))) { - for(c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++ ) { - sprintf(cho,"\n " - "(\033[36m%d\033[m) %-20s¤j¦r¨å",c+1,buf[c]); - outs(cho); + if ((fp = fopen(REFER, "r"))) { + for (c = 0; fscanf(fp, "%s %s", buf[c], data[c]) != EOF; c++) { + sprintf(cho, "\n " + "(\033[36m%d\033[m) %-20s¤j¦r¨å", c + 1, buf[c]); + outs(cho); } - + getdata(22, 14, " ¡¹ ½Ð¿ï¾Ü¡A[Enter]Â÷¶}¡G", cho, 3, LCECHO); cho[0] -= '1'; - if(cho[1]) + if (cho[1]) cho[0] = (cho[0] + 1) * 10 + (cho[1] - '1'); - - if(cho[0] >= 0 && cho[0] < c) { + + if (cho[0] >= 0 && cho[0] < c) { strcpy(dict, buf[(int)cho[0]]); strcpy(database, data[(int)cho[0]]); return 1; @@ -64,33 +67,37 @@ static int choose_dict(void) { return 0; } -static char *lower(char str[]) { - int c; - static char temp[200]; +static char * +lower(char str[]) +{ + int c; + static char temp[200]; - strcpy(temp,str); - for(c = 0; temp[c] !=0; c++) - if(temp[c] >= 'A' && temp[c] <= 'Z') + strcpy(temp, str); + for (c = 0; temp[c] != 0; c++) + if (temp[c] >= 'A' && temp[c] <= 'Z') temp[c] += 'a' - 'A'; return temp; } -int use_dict() { - FILE *fp; - char lang[150], word[80] = ""; - char j, f, buf[120], sys[] = "|\033[31me\033[m:½sÄy¦r¨å"; - int i = 0; - +int +use_dict() +{ + FILE *fp; + char lang[150], word[80] = ""; + char j, f, buf[120], sys[] = "|\033[31me\033[m:½sÄy¦r¨å"; + int i = 0; + setutmpmode(DICT); - if(!HAS_PERM(PERM_SYSOP)) - sys[0]=0; - + if (!HAS_PERM(PERM_SYSOP)) + sys[0] = 0; + clear(); - - sprintf(buf,"\033[45m ¡´\033[1;44;33m" + + sprintf(buf, "\033[45m ¡´\033[1;44;33m" " %-14s\033[3;45m ¡´ ", dict); - strcpy(&buf[100],"\033[m\n"); - for(;;) { + strcpy(&buf[100], "\033[m\n"); + for (;;) { move(0, 0); sprintf(lang, " ½Ð¿é¤JÃöÁä¦r¦ê(%s) ©Î«ü¥O(h,t,a)\n", dict); outs(lang); @@ -99,27 +106,27 @@ int use_dict() { outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("¸ê®Æ·j´M¤¤½ÐµyÔ...."); - strcpy(word,lower(word)); - if(word[0] == 0) + strcpy(word, lower(word)); + if (word[0] == 0) return 0; clear(); move(4, 0); outs(buf); - if(strlen(word) == 1) { - if(word[0] == 'a') { + if (strlen(word) == 1) { + if (word[0] == 'a') { clear(); - move(4,0); + move(4, 0); outs(buf); addword(word); continue; - } else if(word[0] == 't') + } else if (word[0] == 't') word[0] = 0; - else if(word[0] == 'h') { - more("etc/dict.hlp",YEA); + else if (word[0] == 'h') { + more("etc/dict.hlp", YEA); clear(); continue; - } else if(word[0]=='e') { - vedit(database,NA, NULL); + } else if (word[0] == 'e') { + vedit(database, NA, NULL); clear(); continue; } else { @@ -127,43 +134,42 @@ int use_dict() { continue; } } - - if((fp = fopen(database,"r"))) { + if ((fp = fopen(database, "r"))) { i = 0; - while(fgets(lang,150,fp) != NULL) { - if(lang[65] == '[') { + while (fgets(lang, 150, fp) != NULL) { + if (lang[65] == '[') { lang[65] = 0; f = 1; } else f = 0; - if(strstr(lower(lang),word)) { - if(f == 1) + if (strstr(lower(lang), word)) { + if (f == 1) lang[65] = '['; outs(lang); i++; - if(!((i+1)%17)) { + if (!((i + 1) % 17)) { move(23, 0); outs("\033[45m " - "¥ô·NÁäÄ~Äò Q:Â÷¶} " + "¥ô·NÁäÄ~Äò Q:Â÷¶} " "\033[m "); j = igetch(); - if(j == 'q') + if (j == 'q') break; - else { + else { clear(); - move(4,0); + move(4, 0); outs(buf); - } + } } } } } fclose(fp); - if(i == 0) { + if (i == 0) { getdata(5, 0, "¨S³oÓ¸ê®ÆC,·s¼W¶Ü?(y/N)", lang, 3, LCECHO); - if(lang[0] == 'y') { + if (lang[0] == 'y') { clear(); - move(4,0); + move(4, 0); outs(buf); addword(word); } @@ -171,8 +177,10 @@ int use_dict() { } } -int x_dict() { - if(choose_dict()) +int +x_dict() +{ + if (choose_dict()) use_dict(); return 0; } @@ -1,4 +1,4 @@ -/* $Id: io.c,v 1.17 2002/06/04 13:08:33 in2 Exp $ */ +/* $Id: io.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #if defined(linux) @@ -9,30 +9,35 @@ #define IBUFSIZE 256 #endif -static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; -static int obufsize = 0, ibufsize = 0; -static int icurrchar = 0; +static char outbuf[OBUFSIZE], inbuf[IBUFSIZE]; +static int obufsize = 0, ibufsize = 0; +static int icurrchar = 0; /* ----------------------------------------------------- */ /* output routines */ /* ----------------------------------------------------- */ -void oflush() { - if(obufsize) { +void +oflush() +{ + if (obufsize) { write(1, outbuf, obufsize); obufsize = 0; } } -void init_buf() +void +init_buf() { - memset(inbuf,0,IBUFSIZE); + memset(inbuf, 0, IBUFSIZE); } -void output(char *s, int len) { +void +output(char *s, int len) +{ /* Invalid if len >= OBUFSIZE */ - if(obufsize + len > OBUFSIZE) { + if (obufsize + len > OBUFSIZE) { write(1, outbuf, obufsize); obufsize = 0; } @@ -40,8 +45,10 @@ void output(char *s, int len) { obufsize += len; } -int ochar(int c) { - if(obufsize > OBUFSIZE - 1) { +int +ochar(int c) +{ + if (obufsize > OBUFSIZE - 1) { write(1, outbuf, obufsize); obufsize = 0; } @@ -53,104 +60,108 @@ int ochar(int c) { /* input routines */ /* ----------------------------------------------------- */ -static int i_newfd = 0; +static int i_newfd = 0; static struct timeval i_to, *i_top = NULL; -static int (*flushf) () = NULL; +static int (*flushf) () = NULL; -void add_io(int fd, int timeout) { +void +add_io(int fd, int timeout) +{ i_newfd = fd; - if(timeout) { + if (timeout) { i_to.tv_sec = timeout; - i_to.tv_usec = 16384; /* Ptt: §ï¦¨16384 ÁקK¤£«ö®Éfor loop¦Ycpu time - 16384 ¬ù¨C¬í64¦¸ */ + i_to.tv_usec = 16384; /* Ptt: §ï¦¨16384 ÁקK¤£«ö®Éfor loop¦Ycpu + * time 16384 ¬ù¨C¬í64¦¸ */ i_top = &i_to; } else i_top = NULL; } -int num_in_buf() { +int +num_in_buf() +{ return icurrchar - ibufsize; } /* - dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, - and dogetch() might be called again, and then ibufsize/icurrchar/inbuf - might be inconsistent. - We try to not segfault here... -*/ + * dogetch() is not reentrant-safe. SIGUSR[12] might happen at any time, and + * dogetch() might be called again, and then ibufsize/icurrchar/inbuf might + * be inconsistent. We try to not segfault here... + */ -static int dogetch() { - int len; - static time_t lastact; - if(ibufsize <= icurrchar) { +static int +dogetch() +{ + int len; + static time_t lastact; + if (ibufsize <= icurrchar) { - if(flushf) - (*flushf)(); + if (flushf) + (*flushf) (); refresh(); - if(i_newfd) { - - struct timeval timeout; - fd_set readfds; - - if(i_top) timeout=*i_top; /* copy it because select() might change it */ - + if (i_newfd) { + + struct timeval timeout; + fd_set readfds; + + if (i_top) + timeout = *i_top; /* copy it because select() might + * change it */ + FD_ZERO(&readfds); FD_SET(0, &readfds); FD_SET(i_newfd, &readfds); /* jochang: modify first argument of select from FD_SETSIZE */ /* since we are only waiting input from fd 0 and i_newfd(>0) */ - - while((len = select(i_newfd+1, &readfds, NULL, NULL, i_top?&timeout:NULL))<0) - { - if(errno != EINTR) + + while ((len = select(i_newfd + 1, &readfds, NULL, NULL, i_top ? &timeout : NULL)) < 0) { + if (errno != EINTR) abort_bbs(0); - /* raise(SIGHUP); */ + /* raise(SIGHUP); */ } - if(len == 0) + if (len == 0) return I_TIMEOUT; - if(i_newfd && FD_ISSET(i_newfd, &readfds)) + if (i_newfd && FD_ISSET(i_newfd, &readfds)) return I_OTHERDATA; } - - - while((len = read(0, inbuf, IBUFSIZE)) <= 0) { - if(len == 0 || errno != EINTR) - abort_bbs(0); - /* raise(SIGHUP); */ - } + while ((len = read(0, inbuf, IBUFSIZE)) <= 0) { + if (len == 0 || errno != EINTR) + abort_bbs(0); + /* raise(SIGHUP); */ + } ibufsize = len; icurrchar = 0; } - - if(currutmp) - { - now= time(0); - if(now-lastact < 3) - currutmp->lastact=now; - lastact=now; - } + if (currutmp) { + now = time(0); + if (now - lastact < 3) + currutmp->lastact = now; + lastact = now; + } return inbuf[icurrchar++]; } -static int water_which_flag=0; -int igetch() { - register int ch; - while((ch = dogetch())) { - switch(ch) { +static int water_which_flag = 0; +int +igetch() +{ + register int ch; + while ((ch = dogetch())) { + switch (ch) { case Ctrl('L'): redoscr(); continue; case Ctrl('U'): - if(currutmp != NULL && currutmp->mode != EDITING - && currutmp->mode != LUSERS && currutmp->mode) { + if (currutmp != NULL && currutmp->mode != EDITING + && currutmp->mode != LUSERS && currutmp->mode) { - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); - int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + int y, x, my_newfd; getyx(&y, &x); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); @@ -165,9 +176,9 @@ int igetch() { continue; } else return (ch); - case KEY_TAB: - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) - if( currutmp != NULL && watermode > 0 ){ + case KEY_TAB: + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) + if (currutmp != NULL && watermode > 0) { watermode = (watermode + water_which->count) % water_which->count + 1; t_display_new(); @@ -176,16 +187,16 @@ int igetch() { return ch; break; - case Ctrl('R'): - if(currutmp == NULL) + case Ctrl('R'): + if (currutmp == NULL) return (ch); - if( currutmp->msgs[0].pid && - WATERMODE(WATER_OFO) && wmofo == -1 ){ - int y, x, my_newfd; - screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + if (currutmp->msgs[0].pid && + WATERMODE(WATER_OFO) && wmofo == -1) { + int y, x, my_newfd; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); - getyx(&y, &x); + getyx(&y, &x); my_newfd = i_newfd; i_newfd = 0; my_write2(); @@ -195,31 +206,27 @@ int igetch() { free(screen0); redoscr(); continue; - } - else if(!WATERMODE(WATER_OFO)) - { - if( watermode > 0 ){ + } else if (!WATERMODE(WATER_OFO)) { + if (watermode > 0) { watermode = (watermode + water_which->count) % water_which->count + 1; t_display_new(); continue; - } - else if( currutmp->mode == 0 && - (currutmp->chatid[0]==2 || currutmp->chatid[0]==3) && - water_which->count != 0 && watermode == 0) { + } else if (currutmp->mode == 0 && + (currutmp->chatid[0] == 2 || currutmp->chatid[0] == 3) && + water_which->count != 0 && watermode == 0) { /* ²Ä¤G¦¸«ö Ctrl-R */ watermode = 1; t_display_new(); continue; - } - else if(watermode==-1 && currutmp->msgs[0].pid) { + } else if (watermode == -1 && currutmp->msgs[0].pid) { /* ²Ä¤@¦¸«ö Ctrl-R (¥²¶·¥ý³Q¥á¹L¤ô²y) */ - screenline_t *screen0; - int y, x, my_newfd; + screenline_t *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)); - + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + /* ¦pªG¥¿¦btalkªº¸Ü¥ý¤£³B²z¹ï¤è°e¹L¨Óªº«Ê¥] (¤£¥hselect) */ my_newfd = i_newfd; i_newfd = 0; @@ -228,43 +235,43 @@ int igetch() { my_write(currutmp->msgs[0].pid, "¤ô²y¥á¹L¥h ¡G ", currutmp->msgs[0].userid, 0, NULL); i_newfd = my_newfd; - + /* ÁÙì¿Ã¹õ */ - memcpy(big_picture, screen0, t_lines*sizeof(screenline_t)); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); move(y, x); free(screen0); redoscr(); continue; } - } + } return ch; - case '\n': /* Ptt§â \n®³±¼ */ + case '\n': /* Ptt§â \n®³±¼ */ continue; - case Ctrl('T'): - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ - if(watermode > 0) { - if(watermode>1) + case Ctrl('T'): + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) { + if (watermode > 0) { + if (watermode > 1) watermode--; else - watermode = water_which->count; + watermode = water_which->count; t_display_new(); continue; } } return (ch); - case Ctrl('F'): - if( WATERMODE(WATER_NEW) ){ - if(watermode >0){ - if( water_which_flag == (int)water_usies ) + case Ctrl('F'): + if (WATERMODE(WATER_NEW)) { + if (watermode > 0) { + if (water_which_flag == (int)water_usies) water_which_flag = 0; else water_which_flag = - (water_which_flag+1) % (int)(water_usies+1); - if(water_which_flag==0) + (water_which_flag + 1) % (int)(water_usies + 1); + if (water_which_flag == 0) water_which = &water[0]; else - water_which = swater[water_which_flag-1]; + water_which = swater[water_which_flag - 1]; watermode = 1; t_display_new(); continue; @@ -272,14 +279,14 @@ int igetch() { } return ch; - case Ctrl('G'): - if( WATERMODE(WATER_NEW) ){ - if( watermode > 0 ){ - water_which_flag=(water_which_flag+water_usies)%(water_usies+1); - if(water_which_flag==0) + case Ctrl('G'): + if (WATERMODE(WATER_NEW)) { + if (watermode > 0) { + water_which_flag = (water_which_flag + water_usies) % (water_usies + 1); + if (water_which_flag == 0) water_which = &water[0]; else - water_which = swater[water_which_flag-1]; + water_which = swater[water_which_flag - 1]; watermode = 1; t_display_new(); continue; @@ -287,23 +294,25 @@ int igetch() { } return ch; - default: + default: return ch; } } return 0; } -int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { - register int ch, i; - int clen; - int x = col, y = line; +int +oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) +{ + register int ch, i; + int clen; + int x = col, y = line; #define MAXLASTCMD 12 - static char lastcmd[MAXLASTCMD][80]; + static char lastcmd[MAXLASTCMD][80]; strip_ansi(buf, buf, STRIP_ALL); - if(prompt) { + if (prompt) { move(line, col); @@ -311,56 +320,54 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { outs(prompt); - x += strip_ansi(NULL,prompt,0); + x += strip_ansi(NULL, prompt, 0); } - - if(!echo) { + if (!echo) { len--; clen = 0; - while((ch = igetch()) != '\r') { - if(ch == '\177' || ch == Ctrl('H')) { - if(!clen) { + while ((ch = igetch()) != '\r') { + if (ch == '\177' || ch == Ctrl('H')) { + if (!clen) { bell(); continue; } clen--; - if(echo) { + if (echo) { ochar(Ctrl('H')); ochar(' '); ochar(Ctrl('H')); } continue; } -// Ptt + //Ptt #ifdef BIT8 - if(!isprint2(ch)) + if (!isprint2(ch)) #else - if(!isprint(ch)) + if (!isprint(ch)) #endif - { - if(echo) - bell(); - continue; - } - - if(clen >= len) { - if(echo) + { + if (echo) + bell(); + continue; + } + if (clen >= len) { + if (echo) bell(); continue; } buf[clen++] = ch; - if(echo) + if (echo) ochar(ch); } buf[clen] = '\0'; outc('\n'); oflush(); } else { - int cmdpos = -1; - int currchar = 0; + int cmdpos = -1; + int currchar = 0; standout(); - for(clen = len--; clen; clen--) + for (clen = len--; clen; clen--) outc(' '); standend(); buf[len] = 0; @@ -368,81 +375,81 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { edit_outs(buf); clen = currchar = strlen(buf); - while(move(y, x + currchar), (ch = igetkey()) != '\r') { - switch(ch) { + while (move(y, x + currchar), (ch = igetkey()) != '\r') { + switch (ch) { case KEY_DOWN: case Ctrl('N'): - buf[clen] = '\0'; /* Ptt */ - strncpy(lastcmd[cmdpos], buf, 79); - cmdpos += MAXLASTCMD - 2; + buf[clen] = '\0'; /* Ptt */ + strncpy(lastcmd[cmdpos], buf, 79); + cmdpos += MAXLASTCMD - 2; case Ctrl('P'): case KEY_UP: - if(ch == KEY_UP || ch == Ctrl('P')) { - buf[clen] = '\0'; /* Ptt */ + if (ch == KEY_UP || ch == Ctrl('P')) { + buf[clen] = '\0'; /* Ptt */ strncpy(lastcmd[cmdpos], buf, 79); - } - cmdpos++; - cmdpos %= MAXLASTCMD; - strncpy(buf, lastcmd[cmdpos], len); - buf[len] = 0; - - move(y, x); /* clrtoeof */ - for(i = 0; i <= clen; i++) + } + cmdpos++; + cmdpos %= MAXLASTCMD; + strncpy(buf, lastcmd[cmdpos], len); + buf[len] = 0; + + move(y, x); /* clrtoeof */ + for (i = 0; i <= clen; i++) outc(' '); - move(y, x); - edit_outs(buf); - clen = currchar = strlen(buf); - break; + move(y, x); + edit_outs(buf); + clen = currchar = strlen(buf); + break; case KEY_LEFT: - if(currchar) + if (currchar) --currchar; - break; + break; case KEY_RIGHT: - if(buf[currchar]) + if (buf[currchar]) ++currchar; - break; + break; case '\177': case Ctrl('H'): - if(currchar) { + if (currchar) { currchar--; clen--; - for(i = currchar; i <= clen; i++) + for (i = currchar; i <= clen; i++) buf[i] = buf[i + 1]; move(y, x + clen); outc(' '); move(y, x); edit_outs(buf); - } - break; + } + break; case Ctrl('Y'): - currchar = 0; + currchar = 0; case Ctrl('K'): - buf[currchar] = 0; - move(y, x + currchar); - for(i = currchar; i < clen; i++) + buf[currchar] = 0; + move(y, x + currchar); + for (i = currchar; i < clen; i++) outc(' '); - clen = currchar; - break; + clen = currchar; + break; case Ctrl('D'): - if(buf[currchar]) { + if (buf[currchar]) { clen--; - for(i = currchar; i <= clen; i++) + for (i = currchar; i <= clen; i++) buf[i] = buf[i + 1]; move(y, x + clen); outc(' '); move(y, x); edit_outs(buf); - } - break; + } + break; case Ctrl('A'): - currchar = 0; - break; + currchar = 0; + break; case Ctrl('E'): - currchar = clen; - break; + currchar = clen; + break; default: - if(isprint2(ch) && clen < len && x + clen < scr_cols) { - for(i = clen + 1; i > currchar;i--) + if (isprint2(ch) && clen < len && x + clen < scr_cols) { + for (i = clen + 1; i > currchar; i--) buf[i] = buf[i - 1]; buf[currchar] = ch; move(y, x + currchar); @@ -450,103 +457,111 @@ int oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) { currchar++; clen++; } - break; - }/* end case */ - } /* end while */ - - if(clen > 1) - for(cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { - strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); - strncpy(lastcmd[0], buf, len); + break; + } /* end case */ + } /* end while */ + + if (clen > 1) + for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--) { + strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]); + strncpy(lastcmd[0], buf, len); } - if(echo) + if (echo) outc('\n'); refresh(); } - if((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) + if ((echo == LCECHO) && ((ch = buf[0]) >= 'A') && (ch <= 'Z')) buf[0] = ch | 32; -#ifdef SUPPORT_GB - if(echo == DOECHO && current_font_type == TYPE_GB) - { - strcpy(buf,hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); +#ifdef SUPPORT_GB + if (echo == DOECHO && current_font_type == TYPE_GB) { + strcpy(buf, hc_convert_str(buf, HC_GBtoBIG, HC_DO_SINGLE)); } #endif return clen; } /* Ptt */ -int getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) { +int +getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) +{ return oldgetdata(line, col, prompt, buf, len, echo); } char getans(char *prompt) { - char ans[5]; + char ans[5]; - getdata(t_lines-1, 0, prompt, ans, sizeof(ans), LCECHO); - return ans[0]; + getdata(t_lines - 1, 0, prompt, ans, sizeof(ans), LCECHO); + return ans[0]; } -int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) { +int +getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) +{ strncpy(buf, defaultstr, len); - + buf[len - 1] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } -int getdata(int line, int col, char *prompt, char *buf, int len, int echo) { +int +getdata(int line, int col, char *prompt, char *buf, int len, int echo) +{ buf[0] = 0; return oldgetdata(line, col, prompt, buf, len, echo); } int -rget(int x,char *prompt) +rget(int x, char *prompt) { - register int ch; + register int ch; - move(x,0); - clrtobot(); - outs(prompt); - refresh(); + move(x, 0); + clrtobot(); + outs(prompt); + refresh(); - ch = igetch(); - if( ch >= 'A' && ch <= 'Z') ch |= 32; + ch = igetch(); + if (ch >= 'A' && ch <= 'Z') + ch |= 32; - return ch; + return ch; } -int igetkey() { - int mode; - int ch, last; +int +igetkey() +{ + int mode; + int ch, last; mode = last = 0; - while(1) { + while (1) { ch = igetch(); - if(mode == 0) { - if(ch == KEY_ESC) + if (mode == 0) { + if (ch == KEY_ESC) mode = 1; else - return ch; /* Normal Key */ - } else if (mode == 1) { /* Escape sequence */ - if(ch == '[' || ch == 'O') + return ch; /* Normal Key */ + } else if (mode == 1) { /* Escape sequence */ + if (ch == '[' || ch == 'O') mode = 2; - else if(ch == '1' || ch == '4') + else if (ch == '1' || ch == '4') mode = 3; else { KEY_ESC_arg = ch; return KEY_ESC; } - } else if(mode == 2) { /* Cursor key */ - if(ch >= 'A' && ch <= 'D') + } else if (mode == 2) { /* Cursor key */ + if (ch >= 'A' && ch <= 'D') return KEY_UP + (ch - 'A'); - else if(ch >= '1' && ch <= '6') + else if (ch >= '1' && ch <= '6') mode = 3; else return ch; - } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ - if(ch == '~') + } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ + if (ch == '~') return KEY_HOME + (last - '1'); else return ch; @@ -554,4 +569,3 @@ int igetkey() { last = ch; } } - diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index e529aa3d..e3fd1b62 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -1,89 +1,98 @@ -/* $Id: kaede.c,v 1.7 2002/06/26 08:39:07 ptt Exp $ */ +/* $Id: kaede.c,v 1.8 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -char *Ptt_prints(char *str, int mode) { - char *po , strbuf[256]; +char * +Ptt_prints(char *str, int mode) +{ + char *po, strbuf[256]; - while((po = strstr(str, "\033*s"))) { + while ((po = strstr(str, "\033*s"))) { po[0] = 0; sprintf(strbuf, "%s%s%s", str, cuser.userid, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*t"))) { + while ((po = strstr(str, "\033*t"))) { po[0] = 0; sprintf(strbuf, "%s%s", str, Cdate(&now)); - str[strlen(strbuf)-1] = 0; + str[strlen(strbuf) - 1] = 0; strcat(strbuf, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*u"))) { - int attempts; + while ((po = strstr(str, "\033*u"))) { + int attempts; attempts = SHM->UTMPnumber; po[0] = 0; sprintf(strbuf, "%s%d%s", str, attempts, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*b"))) { + while ((po = strstr(str, "\033*b"))) { po[0] = 0; sprintf(strbuf, "%s%d/%d%s", str, cuser.month, cuser.day, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*l"))) { + while ((po = strstr(str, "\033*l"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.numlogins, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*p"))) { + while ((po = strstr(str, "\033*p"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.numposts, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*n"))) { + while ((po = strstr(str, "\033*n"))) { po[0] = 0; sprintf(strbuf, "%s%s%s", str, cuser.username, po + 3); strcpy(str, strbuf); } - while((po = strstr(str, "\033*m"))) { + while ((po = strstr(str, "\033*m"))) { po[0] = 0; sprintf(strbuf, "%s%d%s", str, cuser.money, po + 3); strcpy(str, strbuf); } - strip_ansi(str, str ,mode); + strip_ansi(str, str, mode); return str; } -int Rename(char* src, char* dst) { - char buf[256]; - if(rename(src, dst) == 0) - return 0; - if(!strchr(src,';') && !strchr(dst,';')) // Ptt ¨¾¤£¥¿±`«ü¥O - { - sprintf(buf,"/bin/mv %s %s",src,dst); - system(buf); - } +int +Rename(char *src, char *dst) +{ + char buf[256]; + if (rename(src, dst) == 0) + return 0; + if (!strchr(src, ';') && !strchr(dst, ';')) + //Ptt ¨ ¾¤£¥¿±`«ü¥O + { + sprintf(buf, "/bin/mv %s %s", src, dst); + system(buf); + } return -1; } -int Link(char* src, char* dst) { - char cmd[200]; - - if(strcmp(src, BBSHOME "/home") == 0) - return 1; - if(symlink(dst, src) == 0) +int +Link(char *src, char *dst) +{ + char cmd[200]; + + if (strcmp(src, BBSHOME "/home") == 0) + return 1; + if (symlink(dst, src) == 0) return 0; - + sprintf(cmd, "/bin/cp -R %s %s", src, dst); return system(cmd); } -char *my_ctime(const time_t *t) { - struct tm *tp; - static char ans[100]; +char * +my_ctime(const time_t * t) +{ + struct tm *tp; + static char ans[100]; tp = localtime(t); sprintf(ans, "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), - tp->tm_mon + 1,tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); + tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); return ans; } diff --git a/mbbsd/lovepaper.c b/mbbsd/lovepaper.c index d4757ecf..c2f4459c 100644 --- a/mbbsd/lovepaper.c +++ b/mbbsd/lovepaper.c @@ -1,53 +1,54 @@ -/* $Id: lovepaper.c,v 1.6 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: lovepaper.c,v 1.7 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define DATA "etc/lovepaper.dat" -int x_love() { - char buf1[200], save_title[TTLEN + 1]; - char receiver[61], path[STRLEN] = "home/"; - int x, y = 0, tline = 0, poem = 0; - FILE *fp, *fpo; - struct tm *gtime; - fileheader_t mhdr; - +int +x_love() +{ + char buf1[200], save_title[TTLEN + 1]; + char receiver[61], path[STRLEN] = "home/"; + int x, y = 0, tline = 0, poem = 0; + FILE *fp, *fpo; + struct tm *gtime; + fileheader_t mhdr; + setutmpmode(LOVE); gtime = localtime(&now); - sprintf(buf1,"%c/%s/love%d%d", - cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min); - strcat(path,buf1); - move(1,0); + sprintf(buf1, "%c/%s/love%d%d", + cuser.userid[0], cuser.userid, gtime->tm_sec, gtime->tm_min); + strcat(path, buf1); + move(1, 0); clrtobot(); - + outs("\nÅwªï¨Ï¥Î±¡®Ñ²£¥Í¾¹ v0.00 ªO \n"); outs("¦³¦óÃø¥H±Ò¾¦ªº¸Ü,¥æ¥Ñ¨t²ÎÀ°§A»¡§a.\nª¨ª¨»¡ : Àݱ¡¤£¥Çªk.\n"); - - if(!getdata(7, 0, "¦¬«H¤H¡G", receiver, sizeof(receiver), DOECHO)) + + if (!getdata(7, 0, "¦¬«H¤H¡G", receiver, sizeof(receiver), DOECHO)) return 0; - if(receiver[0] && !(searchuser(receiver) && - getdata(8, 0, "¥D ÃD¡G", save_title, - sizeof(save_title), DOECHO))) { + if (receiver[0] && !(searchuser(receiver) && + getdata(8, 0, "¥D ÃD¡G", save_title, + sizeof(save_title), DOECHO))) { move(10, 0); outs("¦¬«H¤H©Î¥DÃD¤£¥¿½T, ±¡®ÑµLªk¶Ç»¼. "); pressanykey(); return 0; } - fpo = fopen(path, "w"); fprintf(fpo, "\n"); - if((fp = fopen(DATA, "r"))) { - while(fgets(buf1,100, fp)) { - switch(buf1[0]) { + if ((fp = fopen(DATA, "r"))) { + while (fgets(buf1, 100, fp)) { + switch (buf1[0]) { case '#': break; case '@': - if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) - tline=3; - else if(!strncmp(buf1,"@poem",5)) { + if (!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4)) + tline = 3; + else if (!strncmp(buf1, "@poem", 5)) { poem = 1; tline = 1; fprintf(fpo, "\n\n"); } else - tline=2; + tline = 2; break; case '1': case '2': @@ -58,32 +59,32 @@ int x_love() { case '7': case '8': case '9': - sscanf(buf1,"%d",&x); - y = (rand() % (x - 1)) * tline; + sscanf(buf1, "%d", &x); + y = (rand() % (x - 1)) * tline; break; default: - if(!poem) { - if(y > 0) + if (!poem) { + if (y > 0) y = y - 1; else { - if(tline > 0) { + if (tline > 0) { fprintf(fpo, "%s", buf1); tline--; } } } else { - if(buf1[0] == '$') + if (buf1[0] == '$') y--; - else if(y == 0) - fprintf(fpo,"%s",buf1); + else if (y == 0) + fprintf(fpo, "%s", buf1); } - } + } } - + fclose(fp); fclose(fpo); - if(vedit(path, YEA, NULL) == -1) { + if (vedit(path, YEA, NULL) == -1) { unlink(path); clear(); outs("\n\n ©ñ±ó±H±¡®Ñ\n"); @@ -95,8 +96,8 @@ int x_love() { Rename(path, buf1); strncpy(mhdr.title, save_title, TTLEN); strcpy(mhdr.owner, cuser.userid); - sethomedir(path, receiver ); - if(append_record(path, &mhdr, sizeof(mhdr)) == -1) + sethomedir(path, receiver); + if (append_record(path, &mhdr, sizeof(mhdr)) == -1) return -1; hold_mail(buf1, receiver); return 1; diff --git a/mbbsd/mail.c b/mbbsd/mail.c index bc7d25a5..d6d4e3d9 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1,37 +1,39 @@ -/* $Id: mail.c,v 1.17 2002/07/03 09:14:57 in2 Exp $ */ +/* $Id: mail.c,v 1.18 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -char currmaildir[32]; -static char msg_cc[] = "\033[32m[¸s²Õ¦W³æ]\033[m\n"; -static char listfile[] = "list.0"; -static int mailkeep = 0, mailsum = 0; -static int mailsumlimit = 0,mailmaxkeep = 0; - -int setforward() { - char buf[80], ip[50] = "", yn[4]; - FILE *fp; - +char currmaildir[32]; +static char msg_cc[] = "\033[32m[¸s²Õ¦W³æ]\033[m\n"; +static char listfile[] = "list.0"; +static int mailkeep = 0, mailsum = 0; +static int mailsumlimit = 0, mailmaxkeep = 0; + +int +setforward() +{ + char buf[80], ip[50] = "", yn[4]; + FILE *fp; + sethomepath(buf, cuser.userid); - strcat(buf,"/.forward"); - if((fp = fopen(buf,"r"))) { - fscanf(fp,"%s",ip); + strcat(buf, "/.forward"); + if ((fp = fopen(buf, "r"))) { + fscanf(fp, "%s", ip); fclose(fp); } getdata_buf(b_lines - 1, 0, "½Ð¿é¤J«H½c¦Û°ÊÂà±Hªºemail¦a§}:", ip, sizeof(ip), DOECHO); - if(ip[0] && ip[0] != ' ') { + if (ip[0] && ip[0] != ' ') { getdata(b_lines, 0, "½T©w¶}±Ò¦Û°ÊÂà«H¥\\¯à?(Y/n)", yn, sizeof(yn), LCECHO); - if(yn[0] != 'n' && (fp = fopen(buf, "w"))) { - move(b_lines,0); + if (yn[0] != 'n' && (fp = fopen(buf, "w"))) { + move(b_lines, 0); clrtoeol(); - fprintf(fp,"%s",ip); + fprintf(fp, "%s", ip); fclose(fp); outs("³]©w§¹¦¨!"); refresh(); return 0; } } - move(b_lines,0); + move(b_lines, 0); clrtoeol(); outs("¨ú®ø¦Û°ÊÂà«H!"); unlink(buf); @@ -39,74 +41,88 @@ int setforward() { return 0; } -int built_mail_index() { - char genbuf[128]; - +int +built_mail_index() +{ + char genbuf[128]; + getdata(b_lines, 0, "««Ø«H½c?(ĵ§i:½Ð½T©w«H½c¦³°ÝÃD®É¤~¨Ï¥Î)(y/N)", genbuf, 3, - LCECHO); - if(genbuf[0] != 'y') return 0; + LCECHO); + if (genbuf[0] != 'y') + return 0; sprintf(genbuf, BBSHOME "/bin/buildir " BBSHOME "/home/%c/%s", cuser.userid[0], cuser.userid); - move(22,0); - prints("\033[1;31m¤w¸g³B²z§¹²¦!! ½Ñ¦h¤£«K ·q½Ðì½Ì~\033[m");pressanykey(); + move(22, 0); + prints("\033[1;31m¤w¸g³B²z§¹²¦!! ½Ñ¦h¤£«K ·q½Ðì½Ì~\033[m"); + pressanykey(); system(genbuf); return 0; } -int mailalert(char *userid) +int +mailalert(char *userid) { - userinfo_t *uentp=NULL; - int n,tuid,i; + userinfo_t *uentp = NULL; + int n, tuid, i; - if((tuid=searchuser(userid))==0) return -1; + if ((tuid = searchuser(userid)) == 0) + return -1; - n=count_logins(tuid, 0); - for(i=1;i<=n;i++) - if((uentp = (userinfo_t *)search_ulistn(tuid, i))) - uentp->mailalert=1; + n = count_logins(tuid, 0); + for (i = 1; i <= n; i++) + if ((uentp = (userinfo_t *) search_ulistn(tuid, i))) + uentp->mailalert = 1; return 0; } -int mail_muser(userec_t muser, char *title, char *filename) { +int +mail_muser(userec_t muser, char *title, char *filename) +{ return mail_id(muser.userid, title, filename, cuser.userid); } /* Heat: ¥Îid¨Ó±H«H,¤º®e«hlink·Ç³Æ¦nªºÀÉ®× */ -int mail_id(char* id, char *title, char *filename, char *owner) { - fileheader_t mhdr; - char genbuf[128]; +int +mail_id(char *id, char *title, char *filename, char *owner) +{ + fileheader_t mhdr; + char genbuf[128]; sethomepath(genbuf, id); - if(stampfile(genbuf, &mhdr)) - return 0; + if (stampfile(genbuf, &mhdr)) + return 0; strcpy(mhdr.owner, owner); strncpy(mhdr.title, title, TTLEN); mhdr.filemode = 0; Link(filename, genbuf); - sethomedir(genbuf,id); + sethomedir(genbuf, id); append_record(genbuf, &mhdr, sizeof(mhdr)); mailalert(id); return 0; -} - -int invalidaddr(char *addr) { - if(*addr == '\0') - return 1; /* blank */ - while(*addr) { - if(not_alnum(*addr) && !strchr("[].@-_", *addr)) +} + +int +invalidaddr(char *addr) +{ + if (*addr == '\0') + return 1; /* blank */ + while (*addr) { + if (not_alnum(*addr) && !strchr("[].@-_", *addr)) return 1; addr++; } return 0; } -int m_internet() { - char receiver[60]; - +int +m_internet() +{ + char receiver[60]; + getdata(20, 0, "¦¬«H¤H¡G", receiver, sizeof(receiver), DOECHO); - if(strchr(receiver, '@') && !invalidaddr(receiver) && - getdata(21, 0, "¥D ÃD¡G", save_title, STRLEN, DOECHO)) + if (strchr(receiver, '@') && !invalidaddr(receiver) && + getdata(21, 0, "¥D ÃD¡G", save_title, STRLEN, DOECHO)) do_send(receiver, save_title); else { move(22, 0); @@ -116,33 +132,33 @@ int m_internet() { return 0; } -void m_init() { +void +m_init() +{ sethomedir(currmaildir, cuser.userid); } -int chkmailbox() { - if(!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { - int max_keepmail = MAX_KEEPMAIL; - if ( HAS_PERM(PERM_SYSSUBOP) || HAS_PERM(PERM_SMG) || - HAS_PERM(PERM_PRG) || HAS_PERM(PERM_ACTION) || HAS_PERM(PERM_PAINT)) - { - mailsumlimit = 700; - max_keepmail = 500; - } - else if(HAS_PERM(PERM_BM)) - { +int +chkmailbox() +{ + if (!HAVE_PERM(PERM_SYSOP) && !HAVE_PERM(PERM_MAILLIMIT)) { + int max_keepmail = MAX_KEEPMAIL; + if (HAS_PERM(PERM_SYSSUBOP) || HAS_PERM(PERM_SMG) || + HAS_PERM(PERM_PRG) || HAS_PERM(PERM_ACTION) || HAS_PERM(PERM_PAINT)) { + mailsumlimit = 700; + max_keepmail = 500; + } else if (HAS_PERM(PERM_BM)) { mailsumlimit = 500; - max_keepmail = 300; - } - else if(HAS_PERM(PERM_LOGINOK)) + max_keepmail = 300; + } else if (HAS_PERM(PERM_LOGINOK)) mailsumlimit = 200; else mailsumlimit = 50; mailsumlimit += cuser.exmailbox * 10; mailmaxkeep = max_keepmail + cuser.exmailbox; m_init(); - if((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > - mailmaxkeep) { + if ((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > + mailmaxkeep) { move(b_lines, 0); clrtoeol(); bell(); @@ -153,8 +169,8 @@ int chkmailbox() { igetch(); return mailkeep; } - if((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > - mailsumlimit) { + if ((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > + mailsumlimit) { move(b_lines, 0); clrtoeol(); bell(); @@ -169,70 +185,76 @@ int chkmailbox() { return 0; } -static void do_hold_mail(char *fpath, char *receiver, char *holder) { - char buf[80], title[128]; - - fileheader_t mymail; - +static void +do_hold_mail(char *fpath, char *receiver, char *holder) +{ + char buf[80], title[128]; + + fileheader_t mymail; + sethomepath(buf, holder); stampfile(buf, &mymail); - - mymail.filemode = FILE_READ|FILE_HOLD; + + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]"); - if(receiver) { + if (receiver) { sprintf(title, "(%s) %s", receiver, save_title); strncpy(mymail.title, title, TTLEN); } else strcpy(mymail.title, save_title); - + sethomedir(title, holder); - + unlink(buf); Link(fpath, buf); /* Ptt: append_record->do_append */ do_append(title, &mymail, sizeof(mymail)); } -void hold_mail(char *fpath, char *receiver) { - char buf[4]; - +void +hold_mail(char *fpath, char *receiver) +{ + char buf[4]; + getdata(b_lines - 1, 0, "¤w¶¶§Q±H¥X¡A¬O§_¦Û¦s©³½Z(Y/N)¡H[N] ", buf, sizeof(buf), LCECHO); - - if(buf[0] == 'y') + + if (buf[0] == 'y') do_hold_mail(fpath, receiver, cuser.userid); } -int do_send(char *userid, char *title) { - fileheader_t mhdr; - char fpath[STRLEN]; - char receiver[IDLEN]; - char genbuf[200]; - int internet_mail, i; - - if(strchr(userid, '@')) +int +do_send(char *userid, char *title) +{ + fileheader_t mhdr; + char fpath[STRLEN]; + char receiver[IDLEN]; + char genbuf[200]; + int internet_mail, i; + + if (strchr(userid, '@')) internet_mail = 1; else { internet_mail = 0; - if(!getuser(userid)) + if (!getuser(userid)) return -1; - if(!(xuser.userlevel & PERM_READMAIL)) + if (!(xuser.userlevel & PERM_READMAIL)) return -3; - - if(!title) - getdata(2, 0, "¥DÃD¡G", save_title, STRLEN-20, DOECHO); + + if (!title) + getdata(2, 0, "¥DÃD¡G", save_title, STRLEN - 20, DOECHO); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; } - + setutmpmode(SMAIL); - + fpath[0] = '\0'; - - if(internet_mail) { - int res, ch; - if(vedit(fpath, NA, NULL) == -1) { + if (internet_mail) { + int res, ch; + + if (vedit(fpath, NA, NULL) == -1) { unlink(fpath); clear(); return -2; @@ -241,7 +263,7 @@ int do_send(char *userid, char *title) { prints("«H¥ó§Y±N±Hµ¹ %s\n¼ÐÃD¬°¡G%s\n½T©wn±H¥X¶Ü? (Y/N) [Y]", userid, title); ch = igetch(); - switch(ch) { + switch (ch) { case 'N': case 'n': outs("N\n«H¥ó¤w¨ú®ø"); @@ -253,7 +275,7 @@ int do_send(char *userid, char *title) { #ifndef USE_BSMTP bbs_sendmail(fpath, title, userid); #else - bsmtp(fpath, title, userid,0); + bsmtp(fpath, title, userid, 0); #endif hold_mail(fpath, userid); } @@ -265,31 +287,34 @@ int do_send(char *userid, char *title) { stampfile(genbuf, &mhdr); strcpy(mhdr.owner, cuser.userid); strncpy(mhdr.title, save_title, TTLEN); - if(vedit(genbuf, YEA, NULL) == -1) { + if (vedit(genbuf, YEA, NULL) == -1) { unlink(genbuf); clear(); return -2; } clear(); sethomefile(fpath, userid, FN_OVERRIDES); - i=belong(fpath, cuser.userid); - sethomefile(fpath, userid, FN_REJECT); + i = belong(fpath, cuser.userid); + sethomefile(fpath, userid, FN_REJECT); - if(i || !belong(fpath, cuser.userid)) //Ptt:¥Îbelong¦³ÂI°Q¹½ - { + if (i || !belong(fpath, cuser.userid)) + //Ptt: ¥Îbelong ¦ ³ÂI ° Q ¹ ½ + { sethomedir(fpath, userid); - if(append_record(fpath, &mhdr, sizeof(mhdr)) == -1) - return -1; - mailalert(userid); - } + if (append_record(fpath, &mhdr, sizeof(mhdr)) == -1) + return -1; + mailalert(userid); + } hold_mail(genbuf, userid); return 0; } } -void my_send(char *uident) { - switch(do_send(uident, NULL)) { - case -1: +void +my_send(char *uident) +{ + switch (do_send(uident, NULL)) { + case -1: outs(err_uid); break; case -2: @@ -302,44 +327,48 @@ void my_send(char *uident) { pressanykey(); } -int m_send() { - char uident[40]; +int +m_send() +{ + char uident[40]; stand_title("¥BÅ¥·ªº¸Ü"); usercomplete(msg_uid, uident); showplans(uident); - if(uident[0]) + if (uident[0]) my_send(uident); return 0; } /* ¸s²Õ±H«H¡B¦^«H : multi_send, multi_reply */ -static void multi_list(int *reciper) { - char uid[16]; - char genbuf[200]; +static void +multi_list(int *reciper) +{ + char uid[16]; + char genbuf[200]; - while(1) { + while (1) { stand_title("¸s²Õ±H«H¦W³æ"); ShowNameList(3, 0, msg_cc); getdata(1, 0, "(I)¤Þ¤J¦n¤Í (O)¤Þ¤J¤W½u³qª¾ (N)¤Þ¤J·s¤å³¹³qª¾ " "(0-9)¤Þ¤J¨ä¥L¯S§O¦W³æ\n" - "(A)¼W¥[ (D)§R°£ (M)½T»{±H«H¦W³æ (Q)¨ú®ø ¡H[M]", + "(A)¼W¥[ (D)§R°£ (M)½T»{±H«H¦W³æ (Q)¨ú®ø ¡H[M]", genbuf, 4, LCECHO); - switch(genbuf[0]) { + switch (genbuf[0]) { case 'a': - while(1) { + while (1) { move(1, 0); usercomplete("½Ð¿é¤Jn¼W¥[ªº¥N¸¹(¥u«ö ENTER µ²§ô·s¼W): ", uid); - if(uid[0] == '\0') + if (uid[0] == '\0') break; - + move(2, 0); clrtoeol(); - - if(!searchuser(uid)) + + if (!searchuser(uid)) outs(err_uid); - else if(!InNameList(uid)) { + else if (!InNameList(uid)) { AddNameList(uid); (*reciper)++; } @@ -347,12 +376,12 @@ static void multi_list(int *reciper) { } break; case 'd': - while(*reciper) { + while (*reciper) { move(1, 0); namecomplete("½Ð¿é¤Jn§R°£ªº¥N¸¹(¥u«ö ENTER µ²§ô§R°£): ", uid); - if(uid[0] == '\0') + if (uid[0] == '\0') break; - if(RemoveNameList(uid)) + if (RemoveNameList(uid)) (*reciper)--; ShowNameList(3, 0, msg_cc); } @@ -390,68 +419,69 @@ static void multi_list(int *reciper) { } } -static void multi_send(char *title) { - FILE *fp; - struct word_t *p = NULL; - fileheader_t mymail; - char fpath[TTLEN], *ptr; - int reciper, listing; - char genbuf[256]; - +static void +multi_send(char *title) +{ + FILE *fp; + struct word_t *p = NULL; + fileheader_t mymail; + char fpath[TTLEN], *ptr; + int reciper, listing; + char genbuf[256]; + CreateNameList(); listing = reciper = 0; - if(*quote_file) { + if (*quote_file) { AddNameList(quote_user); reciper = 1; fp = fopen(quote_file, "r"); - while(fgets(genbuf, 256, fp)) { - if(strncmp(genbuf, "¡° ", 3)) { - if(listing) + while (fgets(genbuf, 256, fp)) { + if (strncmp(genbuf, "¡° ", 3)) { + if (listing) break; } else { - if(listing) { + if (listing) { strtok(ptr = genbuf + 3, " \n\r"); do { - if(searchuser(ptr) && !InNameList(ptr) && - strcmp(cuser.userid, ptr)) { + if (searchuser(ptr) && !InNameList(ptr) && + strcmp(cuser.userid, ptr)) { AddNameList(ptr); reciper++; } - } while((ptr = (char *)strtok(NULL, " \n\r"))); - } else if(!strncmp(genbuf + 3, "[³q§i]", 6)) + } while ((ptr = (char *)strtok(NULL, " \n\r"))); + } else if (!strncmp(genbuf + 3, "[³q§i]", 6)) listing = 1; } } ShowNameList(3, 0, msg_cc); } - multi_list(&reciper); move(1, 0); clrtobot(); - - if(reciper) { + + if (reciper) { setutmpmode(SMAIL); - if(title) + if (title) do_reply_title(2, title); else { getdata(2, 0, "¥DÃD¡G", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[³q§i] %s", fpath); } - + setuserfile(fpath, fn_notes); - - if((fp = fopen(fpath, "w"))) { + + if ((fp = fopen(fpath, "w"))) { fprintf(fp, "¡° [³q§i] ¦@ %d ¤H¦¬¥ó", reciper); listing = 80; - for(p = toplev; p; p = p->next) { + for (p = toplev; p; p = p->next) { reciper = strlen(p->word) + 1; - if(listing + reciper > 75) { + if (listing + reciper > 75) { listing = reciper; fprintf(fp, "\n¡°"); } else listing += reciper; - + fprintf(fp, " %s", p->word); } memset(genbuf, '-', 75); @@ -459,25 +489,23 @@ static void multi_send(char *title) { fprintf(fp, "\n%s\n\n", genbuf); fclose(fp); } - curredit |= EDIT_LIST; - if(vedit(fpath, YEA, NULL) == -1) { + if (vedit(fpath, YEA, NULL) == -1) { unlink(fpath); curredit = 0; outs(msg_cancel); pressanykey(); return; } - stand_title("±H«H¤¤..."); refresh(); - + listing = 80; - - for(p = toplev; p; p = p->next) { + + for (p = toplev; p; p = p->next) { reciper = strlen(p->word) + 1; - if(listing + reciper > 75) { + if (listing + reciper > 75) { listing = reciper; outc('\n'); } else { @@ -485,19 +513,19 @@ static void multi_send(char *title) { outc(' '); } outs(p->word); - if(searchuser(p->word) && strcmp(STR_GUEST, p->word) ) + if (searchuser(p->word) && strcmp(STR_GUEST, p->word)) sethomepath(genbuf, p->word); else continue; stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); - + strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); - mymail.filemode |= FILE_MULTI; /* multi-send flag */ + mymail.filemode |= FILE_MULTI; /* multi-send flag */ sethomedir(genbuf, p->word); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); mailalert(p->word); } @@ -509,8 +537,10 @@ static void multi_send(char *title) { pressanykey(); } -static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { - if(!(fhdr->filemode&FILE_MULTI) ) +static int +multi_reply(int ent, fileheader_t * fhdr, char *direct) +{ + if (!(fhdr->filemode & FILE_MULTI)) return mail_reply(ent, fhdr, direct); stand_title("¸s²Õ¦^«H"); @@ -520,39 +550,42 @@ static int multi_reply(int ent, fileheader_t *fhdr, char *direct) { return 0; } -int mail_list() { +int +mail_list() +{ stand_title("¸s²Õ§@·~"); multi_send(NULL); return 0; } -int mail_all() { - FILE *fp; - fileheader_t mymail; - char fpath[TTLEN]; - char genbuf[200]; - int i, unum; - char *userid; - +int +mail_all() +{ + FILE *fp; + fileheader_t mymail; + char fpath[TTLEN]; + char genbuf[200]; + int i, unum; + char *userid; + stand_title("µ¹©Ò¦³¨Ï¥ÎªÌªº¨t²Î³q§i"); setutmpmode(SMAIL); getdata(2, 0, "¥DÃD¡G", fpath, sizeof(fpath), DOECHO); sprintf(save_title, "[¨t²Î³q§i]\033[1;32m %s\033[m", fpath); - + setuserfile(fpath, fn_notes); - - if((fp = fopen(fpath, "w"))) { + + if ((fp = fopen(fpath, "w"))) { fprintf(fp, "¡° [\033[1m¨t²Î³q§i\033[m] ³o¬O«Êµ¹©Ò¦³¨Ï¥ÎªÌªº«H\n"); fprintf(fp, "-----------------------------------------------------" "----------------------\n"); fclose(fp); } - *quote_file = 0; - + curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; - if(vedit(fpath, YEA, NULL) == -1) { + if (vedit(fpath, YEA, NULL) == -1) { curredit = 0; unlink(fpath); outs(msg_cancel); @@ -560,41 +593,41 @@ int mail_all() { return 0; } curredit = 0; - + setutmpmode(MAILALL); stand_title("±H«H¤¤..."); - + sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); unlink(fpath); strcpy(fpath, genbuf); - - strcpy(mymail.owner, cuser.userid); /*¯¸ªø ID*/ + + strcpy(mymail.owner, cuser.userid); /* ¯¸ªø ID */ strcpy(mymail.title, save_title); - + sethomedir(genbuf, cuser.userid); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); - - for(unum = SHM->number, i = 0; i < unum; i++) { - if(bad_user_id(SHM->userid[i])) - continue; /* Ptt */ - + + for (unum = SHM->number, i = 0; i < unum; i++) { + if (bad_user_id(SHM->userid[i])) + continue; /* Ptt */ + userid = SHM->userid[i]; - if(strcmp(userid,STR_GUEST) && strcmp(userid, "new") && - strcmp(userid, cuser.userid)) { + if (strcmp(userid, STR_GUEST) && strcmp(userid, "new") && + strcmp(userid, cuser.userid)) { sethomepath(genbuf, userid); stampfile(genbuf, &mymail); unlink(genbuf); Link(fpath, genbuf); - + strcpy(mymail.owner, cuser.userid); strcpy(mymail.title, save_title); /* mymail.filemode |= FILE_MARKED; Ptt ¤½§i§ï¦¨¤£·|mark */ sethomedir(genbuf, userid); - if(append_record(genbuf, &mymail, sizeof(mymail)) == -1) + if (append_record(genbuf, &mymail, sizeof(mymail)) == -1) outs(err_uid); sprintf(genbuf, "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); outmsg(genbuf); @@ -604,9 +637,11 @@ int mail_all() { return 0; } -int mail_mbox() { - char cmd[100]; - fileheader_t fhdr; +int +mail_mbox() +{ + char cmd[100]; + fileheader_t fhdr; sprintf(cmd, "/tmp/%s.uu", cuser.userid); sprintf(fhdr.title, "%s ¨p¤H¸ê®Æ", cuser.userid); @@ -614,12 +649,14 @@ int mail_mbox() { return 0; } -static int m_forward(int ent, fileheader_t *fhdr, char *direct) { - char uid[STRLEN]; +static int +m_forward(int ent, fileheader_t * fhdr, char *direct) +{ + char uid[STRLEN]; stand_title("Âà¹F«H¥ó"); usercomplete(msg_uid, uid); - if(uid[0] == '\0') + if (uid[0] == '\0') return FULLUPDATE; strcpy(quote_user, fhdr->owner); @@ -629,7 +666,7 @@ static int m_forward(int ent, fileheader_t *fhdr, char *direct) { clrtobot(); prints("Âà«Hµ¹: %s\n¼Ð ÃD: %s\n", uid, save_title); - switch(do_send(uid, save_title)) { + switch (do_send(uid, save_title)) { case -1: outs(err_uid); break; @@ -644,44 +681,46 @@ static int m_forward(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int delmsgs[128]; -static int delcnt; -static int mrd; - -static int read_new_mail(fileheader_t *fptr) { - static int idc; - char done = NA, delete_it; - char fname[256]; - char genbuf[4]; - - if(fptr == NULL) { +static int delmsgs[128]; +static int delcnt; +static int mrd; + +static int +read_new_mail(fileheader_t * fptr) +{ + static int idc; + char done = NA, delete_it; + char fname[256]; + char genbuf[4]; + + if (fptr == NULL) { delcnt = 0; idc = 0; return 0; } idc++; - if(fptr->filemode) + if (fptr->filemode) return 0; clear(); move(10, 0); prints("±znŪ¨Ó¦Û[%s]ªº°T®§(%s)¶Ü¡H", fptr->owner, fptr->title); getdata(11, 0, "½Ð±z½T©w(Y/N/Q)?[Y] ", genbuf, 3, DOECHO); - if(genbuf[0] == 'q') + if (genbuf[0] == 'q') return QUIT; - if(genbuf[0] == 'n') + if (genbuf[0] == 'n') return 0; - + setuserfile(fname, fptr->filename); fptr->filemode |= FILE_READ; - if(substitute_record(currmaildir, fptr, sizeof(*fptr), idc)) + if (substitute_record(currmaildir, fptr, sizeof(*fptr), idc)) return -1; - + mrd = 1; delete_it = NA; - while(!done) { - int more_result = more(fname, YEA); + while (!done) { + int more_result = more(fname, YEA); - switch(more_result) { + switch (more_result) { case 1: return READ_PREV; case 2: @@ -705,8 +744,8 @@ static int read_new_mail(fileheader_t *fptr) { clrtoeol(); outs(msg_mailer); refresh(); - - switch(egetch()) { + + switch (egetch()) { case 'r': case 'R': mail_reply(idc, fptr, currmaildir); @@ -724,11 +763,11 @@ static int read_new_mail(fileheader_t *fptr) { done = YEA; } } - if(delete_it) { + if (delete_it) { clear(); prints("§R°£«H¥ó¡m%s¡n", fptr->title); getdata(1, 0, msg_sure_ny, genbuf, 2, LCECHO); - if(genbuf[0] == 'y') { + if (genbuf[0] == 'y') { unlink(fname); delmsgs[delcnt++] = idc; } @@ -737,7 +776,9 @@ static int read_new_mail(fileheader_t *fptr) { return 0; } -int m_new() { +int +m_new() +{ clear(); mrd = 0; setutmpmode(RMAIL); @@ -745,14 +786,14 @@ int m_new() { clear(); curredit |= EDIT_MAIL; curredit &= ~EDIT_ITEM; - if(apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) { + if (apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) { outs("¨S¦³·s«H¥ó¤F"); pressanykey(); return -1; } curredit = 0; - if(delcnt) { - while(delcnt--) + if (delcnt) { + while (delcnt--) delete_record(currmaildir, sizeof(fileheader_t), delmsgs[delcnt]); } outs(mrd ? "«H¤w¾\\²¦" : "¨S¦³·s«H¥ó¤F"); @@ -760,32 +801,36 @@ int m_new() { return -1; } -static void mailtitle() { - char buf[256] = ""; +static void +mailtitle() +{ + char buf[256] = ""; showtitle("\0¶l¥ó¿ï³æ", BBSName); - sprintf(buf,"[¡ö]Â÷¶}[¡ô¡õ]¿ï¾Ü[¡÷]¾\\Ū«H¥ó [R]¦^«H [x]Âà¹F " - "[y]¸s²Õ¦^«H [O]¯¸¥~«H:%s [h]¨D§U\n\033[7m" - "½s¸¹ ¤é ´Á §@ ªÌ «H ¥ó ¼Ð ÃD \033[32m", - HAS_PERM(PERM_NOOUTMAIL)? "\033[31mÃö\033[m":"¶}"); + sprintf(buf, "[¡ö]Â÷¶}[¡ô¡õ]¿ï¾Ü[¡÷]¾\\Ū«H¥ó [R]¦^«H [x]Âà¹F " + "[y]¸s²Õ¦^«H [O]¯¸¥~«H:%s [h]¨D§U\n\033[7m" + "½s¸¹ ¤é ´Á §@ ªÌ «H ¥ó ¼Ð ÃD \033[32m", + HAS_PERM(PERM_NOOUTMAIL) ? "\033[31mÃö\033[m" : "¶}"); outs(buf); - buf[0]=0; - if(mailsumlimit) { - sprintf(buf,"(®e¶q:%d/%dk %d/%d½g)", mailsum, mailsumlimit, + buf[0] = 0; + if (mailsumlimit) { + sprintf(buf, "(®e¶q:%d/%dk %d/%d½g)", mailsum, mailsumlimit, mailkeep, mailmaxkeep); } - sprintf(buf, "%s%*s\033[m", buf, 29 - (int) strlen(buf), ""); + sprintf(buf, "%s%*s\033[m", buf, 29 - (int)strlen(buf), ""); outs(buf); } -static void maildoent(int num, fileheader_t *ent) { - char *title, *mark, color, type = "+ Mm"[(ent->filemode&3)]; +static void +maildoent(int num, fileheader_t * ent) +{ + char *title, *mark, color, type = "+ Mm"[(ent->filemode & 3)]; if (TagNum && !Tagger(atoi(ent->filename + 2), 0, TAG_NIN)) - type = 'D'; + type = 'D'; title = subject(mark = ent->title); - if(title == mark) { + if (title == mark) { color = '1'; mark = "¡º"; } else { @@ -793,7 +838,7 @@ static void maildoent(int num, fileheader_t *ent) { mark = "R:"; } - if(strncmp(currtitle, title, TTLEN)) + if (strncmp(currtitle, title, TTLEN)) prints("%5d %c %-7s%-15.14s%s %.46s\n", num, type, ent->date, ent->owner, mark, title); else @@ -801,25 +846,29 @@ static void maildoent(int num, fileheader_t *ent) { ent->date, ent->owner, color, mark, title); } -static int m_idle(int ent, fileheader_t *fhdr, char *direct) { +static int +m_idle(int ent, fileheader_t * fhdr, char *direct) +{ t_idle(); return FULLUPDATE; } -static int mail_del(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; +static int +mail_del(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; - if(fhdr->filemode & FILE_MARKED) + if (fhdr->filemode & FILE_MARKED) return DONOTHING; getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if(genbuf[0] == 'y') { + if (genbuf[0] == 'y') { strcpy(currfile, fhdr->filename); - if(!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { + if (!delete_file(direct, sizeof(*fhdr), ent, cmpfilename)) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); - if((currmode & MODE_SELECT)) { - int index; + if ((currmode & MODE_SELECT)) { + int index; sethomedir(genbuf, cuser.userid); index = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); delete_file(genbuf, sizeof(fileheader_t), index, cmpfilename); @@ -830,31 +879,32 @@ static int mail_del(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_read(int ent, fileheader_t *fhdr, char *direct) { - char buf[64]; - char done, delete_it, replied; +static int +mail_read(int ent, fileheader_t * fhdr, char *direct) +{ + char buf[64]; + char done, delete_it, replied; clear(); setdirpath(buf, direct, fhdr->filename); strncpy(currtitle, subject(fhdr->title), TTLEN); done = delete_it = replied = NA; - while(!done) { - int more_result = more(buf, YEA); - - if(more_result != -1) { + while (!done) { + int more_result = more(buf, YEA); + + if (more_result != -1) { fhdr->filemode |= FILE_READ; - if((currmode & MODE_SELECT)) { - int index; - + if ((currmode & MODE_SELECT)) { + int index; + index = getindex(currmaildir, fhdr->filename, - sizeof(fileheader_t)); + sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); - } - else + } else substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); } - switch(more_result) { + switch (more_result) { case 1: return READ_PREV; case 2: @@ -878,8 +928,8 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { clrtoeol(); refresh(); outs(msg_mailer); - - switch(egetch()) { + + switch (egetch()) { case 'r': case 'R': replied = YEA; @@ -897,17 +947,17 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { done = YEA; } } - if(delete_it) + if (delete_it) mail_del(ent, fhdr, direct); else { fhdr->filemode |= FILE_READ; #ifdef POSTBUG - if(replied) + if (replied) bug_possible = YEA; #endif - if((currmode & MODE_SELECT)) { - int index; - + if ((currmode & MODE_SELECT)) { + int index; + index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); substitute_record(direct, fhdr, sizeof(*fhdr), ent); @@ -921,31 +971,32 @@ static int mail_read(int ent, fileheader_t *fhdr, char *direct) { } /* in boards/mail ¦^«Hµ¹ì§@ªÌ¡AÂà«H¯¸¥ç¥i */ -int mail_reply(int ent, fileheader_t *fhdr, char *direct) { - char uid[STRLEN]; - char *t; - FILE *fp; - char genbuf[512]; +int +mail_reply(int ent, fileheader_t * fhdr, char *direct) +{ + char uid[STRLEN]; + char *t; + FILE *fp; + char genbuf[512]; stand_title("¦^ «H"); /* §PÂ_¬O boards ©Î mail */ - if(curredit & EDIT_MAIL) + if (curredit & EDIT_MAIL) setuserfile(quote_file, fhdr->filename); else setbfile(quote_file, currboard, fhdr->filename); /* find the author */ strcpy(quote_user, fhdr->owner); - if(strchr(quote_user, '.')) { + if (strchr(quote_user, '.')) { genbuf[0] = '\0'; - if((fp = fopen(quote_file, "r"))) { + if ((fp = fopen(quote_file, "r"))) { fgets(genbuf, 512, fp); fclose(fp); } - t = strtok(genbuf, str_space); - if(!strcmp(t, str_author1) || !strcmp(t, str_author2)) + if (!strcmp(t, str_author1) || !strcmp(t, str_author2)) strcpy(uid, strtok(NULL, str_space)); else { outs("¿ù»~: §ä¤£¨ì§@ªÌ¡C"); @@ -954,14 +1005,14 @@ int mail_reply(int ent, fileheader_t *fhdr, char *direct) { } } else strcpy(uid, quote_user); - + /* make the title */ do_reply_title(3, fhdr->title); prints("\n¦¬«H¤H: %s\n¼Ð ÃD: %s\n", uid, save_title); - + /* edit, then send the mail */ ent = curredit; - switch(do_send(uid, save_title)) { + switch (do_send(uid, save_title)) { case -1: outs(err_uid); break; @@ -977,12 +1028,14 @@ int mail_reply(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_edit(int ent, fileheader_t *fhdr, char *direct) { - char genbuf[200]; +static int +mail_edit(int ent, fileheader_t * fhdr, char *direct) +{ + char genbuf[200]; - if(!HAS_PERM(PERM_SYSOP) && - strcmp(cuser.userid, fhdr->owner) && - strcmp("[³Æ.§Ñ.¿ý]", fhdr->owner)) + if (!HAS_PERM(PERM_SYSOP) && + strcmp(cuser.userid, fhdr->owner) && + strcmp("[³Æ.§Ñ.¿ý]", fhdr->owner)) return DONOTHING; setdirpath(genbuf, direct, fhdr->filename); @@ -990,7 +1043,8 @@ static int mail_edit(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -static int mail_nooutmail(int ent, fileheader_t *fhdr, char *direct) +static int +mail_nooutmail(int ent, fileheader_t * fhdr, char *direct) { cuser.userlevel ^= PERM_NOOUTMAIL; passwd_update(usernum, &cuser); @@ -998,11 +1052,13 @@ static int mail_nooutmail(int ent, fileheader_t *fhdr, char *direct) } -static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { +static int +mail_mark(int ent, fileheader_t * fhdr, char *direct) +{ fhdr->filemode ^= FILE_MARKED; - - if((currmode & MODE_SELECT)) { - int index; + + if ((currmode & MODE_SELECT)) { + int index; index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); @@ -1013,7 +1069,7 @@ static int mail_mark(int ent, fileheader_t *fhdr, char *direct) { } /* help for mail reading */ -static char *mail_help[] = { +static char *mail_help[] = { "\0¹q¤l«H½c¾Þ§@»¡©ú", "\01°ò¥»©R¥O", "(p)(¡ô) «e¤@½g¤å³¹", @@ -1038,19 +1094,23 @@ static char *mail_help[] = { NULL }; -static int m_help() { +static int +m_help() +{ show_help(mail_help); return FULLUPDATE; } -static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { - char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; - fileheader_t xfile; - FILE *xptr; - int author = 0; - char genbuf[200]; - char genbuf2[4]; - +static int +mail_cross_post(int ent, fileheader_t * fhdr, char *direct) +{ + char xboard[20], fname[80], xfpath[80], xtitle[80], inputbuf[10]; + fileheader_t xfile; + FILE *xptr; + int author = 0; + char genbuf[200]; + char genbuf2[4]; + move(2, 0); clrtoeol(); move(3, 0); @@ -1061,72 +1121,70 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*xboard == '\0' || !haspostperm(xboard)) + if (*xboard == '\0' || !haspostperm(xboard)) return FULLUPDATE; - + ent = 1; - if(HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { + if (HAS_PERM(PERM_SYSOP) || !strcmp(fhdr->owner, cuser.userid)) { getdata(2, 0, "(1)ì¤åÂà¸ü (2)ÂÂÂà¿ý®æ¦¡¡H[1] ", genbuf, 3, DOECHO); - if(genbuf[0] != '2') { + if (genbuf[0] != '2') { ent = 0; getdata(2, 0, "«O¯dì§@ªÌ¦WºÙ¶Ü?[Y] ", inputbuf, 3, DOECHO); - if(inputbuf[0] != 'n' && inputbuf[0] != 'N') + if (inputbuf[0] != 'n' && inputbuf[0] != 'N') author = 1; } } - - if(ent) + if (ent) sprintf(xtitle, "[Âà¿ý]%.66s", fhdr->title); else strcpy(xtitle, fhdr->title); - + sprintf(genbuf, "±Ä¥Îì¼ÐÃD¡m%.60s¡n¶Ü?[Y] ", xtitle); getdata(2, 0, genbuf, genbuf2, sizeof(genbuf2), LCECHO); - if(*genbuf2 == 'n') - if(getdata(2, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO)) + if (*genbuf2 == 'n') + if (getdata(2, 0, "¼ÐÃD¡G", genbuf, TTLEN, DOECHO)) strcpy(xtitle, genbuf); - + getdata(2, 0, "(S)¦sÀÉ (L)¯¸¤º (Q)¨ú®ø¡H[Q] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'l' || genbuf[0] == 's') { - int currmode0 = currmode; + if (genbuf[0] == 'l' || genbuf[0] == 's') { + int currmode0 = currmode; currmode = 0; setbpath(xfpath, xboard); stampfile(xfpath, &xfile); - if(author) + if (author) strcpy(xfile.owner, fhdr->owner); else strcpy(xfile.owner, cuser.userid); strcpy(xfile.title, xtitle); - if(genbuf[0] == 'l') { + if (genbuf[0] == 'l') { xfile.filemode = FILE_LOCAL; - } - + } setuserfile(fname, fhdr->filename); - if(ent) { + if (ent) { xptr = fopen(xfpath, "w"); - + strcpy(save_title, xfile.title); strcpy(xfpath, currboard); strcpy(currboard, xboard); write_header(xptr); strcpy(currboard, xfpath); - + fprintf(xptr, "¡° [¥»¤åÂà¿ý¦Û %s «H½c]\n\n", cuser.userid); - + b_suckinfile(xptr, fname); - addsignature(xptr,0); + addsignature(xptr, 0); fclose(xptr); } else { unlink(xfpath); Link(fname, xfpath); } - + setbdir(fname, xboard); append_record(fname, &xfile, sizeof(xfile)); setbtotal(getbnum(xboard)); - if(!xfile.filemode) + if (!xfile.filemode) outgo_post(&xfile, xboard); cuser.numposts++; passwd_update(usernum, &cuser); @@ -1137,12 +1195,14 @@ static int mail_cross_post(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } -int mail_man() { - char buf[64],buf1[64]; +int +mail_man() +{ + char buf[64], buf1[64]; if (HAS_PERM(PERM_MAILLIMIT)) { - int mode0 = currutmp->mode; - int stat0 = currstat; - + int mode0 = currutmp->mode; + int stat0 = currstat; + sethomeman(buf, cuser.userid); sprintf(buf1, "%s ªº«H¥ó§¨", cuser.userid); a_menu(buf1, buf, 1); @@ -1153,20 +1213,22 @@ int mail_man() { return DONOTHING; } -static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN + 1]; - static char xboard[20]; - char buf[20]; - boardheader_t *bp; +static int +mail_cite(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[256]; + char title[TTLEN + 1]; + static char xboard[20]; + char buf[20]; + boardheader_t *bp; setuserfile(fpath, fhdr->filename); strcpy(title, "¡º "); - strncpy(title+3, fhdr->title, TTLEN-3); + strncpy(title + 3, fhdr->title, TTLEN - 3); title[TTLEN] = '\0'; a_copyitem(fpath, title, 0, 1); - if(cuser.userlevel >= PERM_BM) { + if (cuser.userlevel >= PERM_BM) { move(2, 0); clrtoeol(); move(3, 0); @@ -1179,9 +1241,9 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { completeboard_compar, completeboard_permission, completeboard_getname); - if(*buf) + if (*buf) strcpy(xboard, buf); - if(*xboard && (bp = getbcache(getbnum(xboard)))) { + if (*xboard && (bp = getbcache(getbnum(xboard)))) { setapath(fpath, xboard); setutmpmode(ANNOUNCE); a_menu(xboard, fpath, HAS_PERM(PERM_ALLBOARD) ? 2 : @@ -1192,15 +1254,17 @@ static int mail_cite(int ent, fileheader_t *fhdr, char *direct) { return FULLUPDATE; } else { mail_man(); - return FULLUPDATE; + return FULLUPDATE; } } -static int mail_save(int ent, fileheader_t *fhdr, char *direct) { - char fpath[256]; - char title[TTLEN+1]; +static int +mail_save(int ent, fileheader_t * fhdr, char *direct) +{ + char fpath[256]; + char title[TTLEN + 1]; - if(HAS_PERM(PERM_MAILLIMIT)) { + if (HAS_PERM(PERM_MAILLIMIT)) { setuserfile(fpath, fhdr->filename); strcpy(title, "¡º "); strncpy(title + 3, fhdr->title, TTLEN - 3); @@ -1214,50 +1278,53 @@ static int mail_save(int ent, fileheader_t *fhdr, char *direct) { } #ifdef OUTJOBSPOOL -static int mail_waterball(int ent, fileheader_t *fhdr, char *direct) +static int +mail_waterball(int ent, fileheader_t * fhdr, char *direct) { - static char address[60], cmode = 1; - char fname[500], genbuf[200]; - FILE *fp; + static char address[60], cmode = 1; + char fname[500], genbuf[200]; + FILE *fp; - if( !(strstr(fhdr->title, "¼ö½u") && strstr(fhdr->title, "°O¿ý")) ){ + if (!(strstr(fhdr->title, "¼ö½u") && strstr(fhdr->title, "°O¿ý"))) { vmsg("¥²¶·¬O ¼ö½u°O¿ý ¤~¯à¨Ï¥Î¤ô²y¾ã²zªºò!"); return 1; } - if(!address[0]) + if (!address[0]) strcpy(address, cuser.email); move(b_lines - 5, 0); outs("¤ô²y¾ã²zµ{¦¡:\n" "¨t²Î±N·|«ö·Ó©M¤£¦P¤H¥áªº¤ô²y¦U¦Û¿W¥ß\n" "©ó¾ãÂIªº®ÉÔ (¦y¾W®É¬q°£¥~) ±N¸ê®Æ¾ã²z¦n±H°eµ¹±z\n\n\n"); - if(address[0]) { + if (address[0]) { sprintf(genbuf, "±Hµ¹ [%s] ¶Ü(Y/N/Q)¡H[Y] ", address); getdata(b_lines - 2, 0, genbuf, fname, 3, LCECHO); - if(fname[0] == 'q') { outmsg("¨ú®ø³B²z"); return 1; } - if(fname[0] == 'n') + if (fname[0] == 'q') { + outmsg("¨ú®ø³B²z"); + return 1; + } + if (fname[0] == 'n') address[0] = '\0'; } - - if(!address[0]) { + if (!address[0]) { getdata(b_lines - 2, 0, "½Ð¿é¤J¶l¥ó¦a§}¡G", fname, 60, DOECHO); - if(fname[0] && strchr(fname, '.')) { + if (fname[0] && strchr(fname, '.')) { strcpy(address, fname); } else { vmsg("¨ú®ø³B²z"); return 1; } } - if(invalidaddr(address)) + if (invalidaddr(address)) return -2; - - // sprintf(fname, "%d\n", cmode); + + //sprintf(fname, "%d\n", cmode); getdata(b_lines - 1, 0, "¨Ï¥Î¼Ò¦¡(0/1/Q)? [1]", fname, 3, LCECHO); - if( fname[0] == 'Q' || fname[0] == 'q' ){ + if (fname[0] == 'Q' || fname[0] == 'q') { outmsg("¨ú®ø³B²z"); return 1; } cmode = (fname[0] != '0' && fname[0] != '1') ? 1 : fname[0] - '0'; - + sprintf(fname, BBSHOME "/jobspool/water.src.%s-%d", cuser.userid, (int)now); sprintf(genbuf, "cp " BBSHOME "/home/%c/%s/%s %s", @@ -1287,7 +1354,7 @@ static struct onekey_t mail_comms[] = { {'T', edit_title}, {'x', m_forward}, {'X', mail_cross_post}, - {Ctrl('G'), built_mail_index}, /* ׫H½c */ + {Ctrl('G'), built_mail_index}, /* ׫H½c */ {'y', multi_reply}, {Ctrl('I'), m_idle}, {'h', m_help}, @@ -1297,13 +1364,15 @@ static struct onekey_t mail_comms[] = { {'\0', NULL} }; -int m_read() { - if(get_num_records(currmaildir, sizeof(fileheader_t))) { +int +m_read() +{ + if (get_num_records(currmaildir, sizeof(fileheader_t))) { curredit = EDIT_MAIL; curredit &= ~EDIT_ITEM; - i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1); + i_read(RMAIL, currmaildir, mailtitle, maildoent, mail_comms, -1); curredit = 0; - currutmp->mailalert = load_mailalert(cuser.userid); + currutmp->mailalert = load_mailalert(cuser.userid); return 0; } else { outs("±z¨S¦³¨Ó«H"); @@ -1312,15 +1381,17 @@ int m_read() { } /* ±H¯¸¤º«H */ -static int send_inner_mail(char *fpath, char *title, char *receiver) { - char genbuf[256]; - fileheader_t mymail; - - if(!searchuser(receiver)) +static int +send_inner_mail(char *fpath, char *title, char *receiver) +{ + char genbuf[256]; + fileheader_t mymail; + + if (!searchuser(receiver)) return -2; sethomepath(genbuf, receiver); stampfile(genbuf, &mymail); - if(!strcmp(receiver, cuser.userid)) { + if (!strcmp(receiver, cuser.userid)) { strcpy(mymail.owner, "[" BBSNAME "]"); mymail.filemode = FILE_READ; } else @@ -1329,7 +1400,7 @@ static int send_inner_mail(char *fpath, char *title, char *receiver) { unlink(genbuf); Link(fpath, genbuf); sethomedir(genbuf, receiver); - return do_append(genbuf, &mymail, sizeof(mymail)); + return do_append(genbuf, &mymail, sizeof(mymail)); } #include <netdb.h> @@ -1337,55 +1408,54 @@ static int send_inner_mail(char *fpath, char *title, char *receiver) { #include <time.h> #ifndef USE_BSMTP -static int bbs_sendmail(char *fpath, char *title, char *receiver) { - static int configured = 0; - static char myhostname[STRLEN]; - static char myusername[20]; +static int +bbs_sendmail(char *fpath, char *title, char *receiver) +{ + static int configured = 0; + static char myhostname[STRLEN]; + static char myusername[20]; struct hostent *hbuf; - struct passwd *pbuf; - char *ptr; - char genbuf[256]; - FILE *fin, *fout; + struct passwd *pbuf; + char *ptr; + char genbuf[256]; + FILE *fin, *fout; /* ¤¤³~ÄdºI */ - if((ptr = strchr(receiver, ';'))) { - struct tm *ptime; - + if ((ptr = strchr(receiver, ';'))) { + struct tm *ptime; + *ptr = '\0'; } - - if((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver,'@')) { - char hacker[20]; - int len; - - if(strchr(receiver,'@')) { - len = ptr - receiver; - memcpy(hacker, receiver, len); - hacker[len] = '\0'; - } else - strcpy(hacker,receiver); + if ((ptr = strstr(receiver, str_mail_address)) || !strchr(receiver, '@')) { + char hacker[20]; + int len; + + if (strchr(receiver, '@')) { + len = ptr - receiver; + memcpy(hacker, receiver, len); + hacker[len] = '\0'; + } else + strcpy(hacker, receiver); return send_inner_mail(fpath, title, hacker); } - /* setup the hostname and username */ - if(!configured) { + if (!configured) { /* get host name */ hbuf = gethostbyname("localhost"); - if(hbuf) + if (hbuf) strncpy(myhostname, hbuf->h_name, STRLEN); /* get bbs uident */ pbuf = getpwuid(getuid()); - if(pbuf) + if (pbuf) strncpy(myusername, pbuf->pw_name, 20); - if(hbuf && pbuf) + if (hbuf && pbuf) configured = 1; else return -1; } - /* Running the sendmail */ - if(fpath == NULL) { + if (fpath == NULL) { sprintf(genbuf, "/usr/sbin/sendmail %s > /dev/null", receiver); fin = fopen("etc/confirm", "r"); } else { @@ -1394,18 +1464,18 @@ static int bbs_sendmail(char *fpath, char *title, char *receiver) { fin = fopen(fpath, "r"); } fout = popen(genbuf, "w"); - if(fin == NULL || fout == NULL) + if (fin == NULL || fout == NULL) return -1; - - if(fpath) + + if (fpath) fprintf(fout, "Reply-To: %s%s\nFrom: %s%s\n", cuser.userid, str_mail_address, cuser.userid, str_mail_address); fprintf(fout, "To: %s\nSubject: %s\n", receiver, title); fprintf(fout, "X-Disclaimer: " BBSNAME "¹ï¥»«H¤º®e®¤¤£t³d¡C\n\n"); - - while(fgets(genbuf, 255, fin)) { - if(genbuf[0] == '.' && genbuf[1] == '\n') + + while (fgets(genbuf, 255, fin)) { + if (genbuf[0] == '.' && genbuf[1] == '\n') fputs(". \n", fout); else fputs(genbuf, fout); @@ -1415,82 +1485,84 @@ static int bbs_sendmail(char *fpath, char *title, char *receiver) { pclose(fout); return 0; } -#else /* USE_BSMTP */ +#else /* USE_BSMTP */ -int bsmtp(char *fpath, char *title, char *rcpt, int method) { - char buf[80], *ptr; - time_t chrono; - MailQueue mqueue; +int +bsmtp(char *fpath, char *title, char *rcpt, int method) +{ + char buf[80], *ptr; + time_t chrono; + MailQueue mqueue; /* check if the mail is a inner mail */ - if((ptr = strstr(rcpt, str_mail_address)) || !strchr(rcpt, '@')) { - char hacker[20]; - int len; - - if(strchr(rcpt,'@')) { - len = ptr - rcpt; - memcpy(hacker, rcpt, len); - hacker[len] = '\0'; - } else - strcpy(hacker, rcpt); + if ((ptr = strstr(rcpt, str_mail_address)) || !strchr(rcpt, '@')) { + char hacker[20]; + int len; + + if (strchr(rcpt, '@')) { + len = ptr - rcpt; + memcpy(hacker, rcpt, len); + hacker[len] = '\0'; + } else + strcpy(hacker, rcpt); return send_inner_mail(fpath, title, hacker); } - chrono = now; - if(method != MQ_JUSTIFY) { /* »{ÃÒ«H */ + if (method != MQ_JUSTIFY) { /* »{ÃÒ«H */ /* stamp the queue file */ strcpy(buf, "out/"); - for(;;) { - sprintf(buf + 4,"M.%ld.A", ++chrono); - if(!dashf(buf)) { + for (;;) { + sprintf(buf + 4, "M.%ld.A", ++chrono); + if (!dashf(buf)) { Link(fpath, buf); break; } } - + fpath = buf; strcpy(mqueue.filepath, fpath); strcpy(mqueue.subject, title); } - /* setup mail queue */ + /* setup mail queue */ mqueue.mailtime = chrono; mqueue.method = method; strcpy(mqueue.sender, cuser.userid); strcpy(mqueue.username, cuser.username); strcpy(mqueue.rcpt, rcpt); - if(do_append("out/.DIR", (fileheader_t *)&mqueue, sizeof(mqueue)) < 0) + if (do_append("out/.DIR", (fileheader_t *) & mqueue, sizeof(mqueue)) < 0) return 0; return chrono; } -#endif /* USE_BSMTP */ - -int doforward(char *direct, fileheader_t *fh, int mode) { - static char address[60]; - char fname[500]; - int return_no; - char genbuf[200]; - - if(!address[0]) +#endif /* USE_BSMTP */ + +int +doforward(char *direct, fileheader_t * fh, int mode) +{ + static char address[60]; + char fname[500]; + int return_no; + char genbuf[200]; + + if (!address[0]) strcpy(address, cuser.email); - if(address[0]) { + if (address[0]) { sprintf(genbuf, "½T©wÂà±Hµ¹ [%s] ¶Ü(Y/N/Q)¡H[Y] ", address); getdata(b_lines - 1, 0, genbuf, fname, 3, LCECHO); - - if(fname[0] == 'q') { + + if (fname[0] == 'q') { outmsg("¨ú®øÂà±H"); return 1; } - if(fname[0] == 'n') + if (fname[0] == 'n') address[0] = '\0'; } - - if(!address[0]) { - do{ + if (!address[0]) { + do { getdata(b_lines - 1, 0, "½Ð¿é¤JÂà±H¦a§}¡G", fname, 60, DOECHO); - if(fname[0]) { - if(strchr(fname, '.')) + if (fname[0]) { + if (strchr(fname, '.')) strcpy(address, fname); else sprintf(address, "%s.bbs@%s", fname, MYHOSTNAME); @@ -1498,28 +1570,27 @@ int doforward(char *direct, fileheader_t *fh, int mode) { outmsg("¨ú®øÂà±H"); return 1; } - }while(mode=='Z' && strstr(address, MYHOSTNAME)); + } while (mode == 'Z' && strstr(address, MYHOSTNAME)); } - if(invalidaddr(address)) + if (invalidaddr(address)) return -2; - + sprintf(fname, "¥¿Âà±Hµ¹ %s, ½ÐµyÔ...", address); outmsg(fname); move(b_lines - 1, 0); refresh(); - + /* °lÂÜ¨Ï¥ÎªÌ */ - if(HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - + if (HAS_PERM(PERM_LOGUSER)) { + char msg[200]; + sprintf(msg, "%s mailforward to %s at %s", cuser.userid, address, Cdate(&now)); log_user(msg); } - - if(mode == 'Z') { + if (mode == 'Z') { sprintf(fname, TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " - MUTT_PATH" -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" + MUTT_PATH " -a /tmp/home.%s.tgz -s 'home.%s.tgz' '%s' </dev/null;" "rm /tmp/home.%s.tgz", cuser.userid, cuser.userid[0], cuser.userid, cuser.userid, cuser.userid, address, cuser.userid); @@ -1530,58 +1601,60 @@ int doforward(char *direct, fileheader_t *fh, int mode) { cuser.userid[0], cuser.userid, cuser.userid, direct); system(fname); strcpy(fname, direct); - } else if(mode == 'U') { - char tmp_buf[128]; + } else if (mode == 'U') { + char tmp_buf[128]; sprintf(fname, "/tmp/bbs.uu%05d", currpid); sprintf(tmp_buf, "/usr/bin/uuencode %s/%s uu.%05d > %s", direct, fh->filename, currpid, fname); system(tmp_buf); - } else if (mode == 'F'){ - char tmp_buf[128]; - + } else if (mode == 'F') { + char tmp_buf[128]; + sprintf(fname, "/tmp/bbs.f%05d", currpid); - sprintf(tmp_buf, "cp %s/%s %s",direct,fh->filename,fname); + sprintf(tmp_buf, "cp %s/%s %s", direct, fh->filename, fname); system(tmp_buf); } else return -1; - + return_no = #ifndef USE_BSMTP bbs_sendmail(fname, fh->title, address); #else - bsmtp(fname, fh->title, address,mode); + bsmtp(fname, fh->title, address, mode); #endif unlink(fname); return (return_no); } -int load_mailalert(char *userid) { - struct stat st; - char maildir[256]; - int fd; - register int numfiles; - fileheader_t my_mail; - - sethomedir(maildir, userid); - if(!HAS_PERM(PERM_BASIC)) +int +load_mailalert(char *userid) +{ + struct stat st; + char maildir[256]; + int fd; + register int numfiles; + fileheader_t my_mail; + + sethomedir(maildir, userid); + if (!HAS_PERM(PERM_BASIC)) return 0; - if(stat(maildir, &st) < 0) + if (stat(maildir, &st) < 0) return 0; numfiles = st.st_size / sizeof(fileheader_t); - if(numfiles <= 0) + if (numfiles <= 0) return 0; - - /* ¬Ý¬Ý¦³¨S¦³«H¥óÁÙ¨SŪ¹L¡H±qÀɧÀ¦^ÀYÀˬd¡A®Ä²v¸û°ª */ - if((fd = open(maildir, O_RDONLY)) > 0) { + + /* ¬Ý¬Ý¦³¨S¦³«H¥óÁÙ¨SŪ¹L¡H±qÀɧÀ¦^ÀYÀˬd¡A®Ä²v¸û°ª */ + if ((fd = open(maildir, O_RDONLY)) > 0) { lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET); - while(numfiles--) { + while (numfiles--) { read(fd, &my_mail, sizeof(fileheader_t)); - if(!(my_mail.filemode & FILE_READ)) { + if (!(my_mail.filemode & FILE_READ)) { close(fd); return 1; } - lseek(fd, -(off_t)2 * sizeof(fileheader_t), SEEK_CUR); + lseek(fd, -(off_t) 2 * sizeof(fileheader_t), SEEK_CUR); } close(fd); } @@ -1589,11 +1662,13 @@ int load_mailalert(char *userid) { } #ifdef EMAIL_JUSTIFY -static void mail_justify(userec_t muser) { - fileheader_t mhdr; - char title[128], buf1[80]; - FILE* fp; - +static void +mail_justify(userec_t muser) +{ + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + sethomepath(buf1, muser.userid); stampfile(buf1, &mhdr); unlink(buf1); @@ -1601,36 +1676,36 @@ static void mail_justify(userec_t muser) { strncpy(mhdr.title, "[¼f®Ö³q¹L]", TTLEN); mhdr.filemode = 0; - if(valid_ident(muser.email) && !invalidaddr(muser.email)) { - char title[80], *ptr; - unsigned short checksum; /* 16-bit is enough */ - char ch; - + if (valid_ident(muser.email) && !invalidaddr(muser.email)) { + char title[80], *ptr; + unsigned short checksum; /* 16-bit is enough */ + char ch; + checksum = searchuser(muser.userid); ptr = muser.email; - while((ch = *ptr++)) { - if(ch <= ' ') + while ((ch = *ptr++)) { + if (ch <= ' ') break; - if(ch >= 'A' && ch <= 'Z') + if (ch >= 'A' && ch <= 'Z') ch |= 0x20; checksum = (checksum << 1) ^ ch; } - + sprintf(title, "[PTT BBS]To %s(%d:%d) [User Justify]", muser.userid, getuser(muser.userid) + MAGIC_KEY, checksum); - if( + if ( #ifndef USE_BSMTP bbs_sendmail(NULL, title, muser.email) #else bsmtp(NULL, title, muser.email, MQ_JUSTIFY); #endif - < 0) + <0) Link("etc/bademail", buf1); else - Link("etc/replyemail", buf1); + Link("etc/replyemail", buf1); } else Link("etc/bademail", buf1); sethomedir(title, muser.userid); append_record(title, &mhdr, sizeof(mhdr)); } -#endif /* EMAIL_JUSTIFY */ +#endif /* EMAIL_JUSTIFY */ diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 5109474d..c9736e1b 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1,148 +1,150 @@ -/* $Id: mbbsd.c,v 1.39 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: mbbsd.c,v 1.40 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define SOCKET_QLEN 4 #define TH_LOW 100 #define TH_HIGH 120 -static void do_aloha (char *hello); +static void do_aloha(char *hello); #if 0 -static jmp_buf byebye; +static jmp_buf byebye; #endif -static char remoteusername[40] = "?"; +static char remoteusername[40] = "?"; static unsigned char enter_uflag; -static int use_shell_login_mode = 0; +static int use_shell_login_mode = 0; static struct sockaddr_in xsin; /* set signal handler, which won't be reset once signal comes */ static void -signal_restart (int signum, void (*handler) (int)) +signal_restart(int signum, void (*handler) (int)) { struct sigaction act; act.sa_handler = handler; - memset (&(act.sa_mask), 0, sizeof (sigset_t)); + memset(&(act.sa_mask), 0, sizeof(sigset_t)); act.sa_flags = 0; - sigaction (signum, &act, NULL); + sigaction(signum, &act, NULL); } static void -start_daemon () +start_daemon() { - int n; - char buf[80]; - + int n; + char buf[80]; + /* * More idiot speed-hacking --- the first time conversion makes the C * library open the files containing the locale definition and time zone. * If this hasn't happened in the parent process, it happens in the * children, once per connection --- and it does add up. */ - time_t dummy = time (NULL); - struct tm *dummy_time = localtime (&dummy); - - strftime (buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); - -#ifndef NO_FORK - if ((n = fork ())){ - exit (0); + time_t dummy = time(NULL); + struct tm *dummy_time = localtime(&dummy); + + strftime(buf, 80, "%d/%b/%Y:%H:%M:%S", dummy_time); + +#ifndef NO_FORK + if ((n = fork())) { + exit(0); } #endif - + /* rocker.011018: it's a good idea to close all unexcept fd!! */ - n = getdtablesize (); + n = getdtablesize(); while (n) - close (--n); - /* rocker.011018: we don't need to remember original tty, - so request a new session id */ - setsid (); - - /* rocker.011018: after new session, - we should insure the process is clean daemon */ + close(--n); + /* + * rocker.011018: we don't need to remember original tty, so request a + * new session id + */ + setsid(); + + /* + * rocker.011018: after new session, we should insure the process is + * clean daemon + */ #ifndef NO_FORK - if ((n = fork ())){ - exit (0); + if ((n = fork())) { + exit(0); } #endif } static void -reapchild (int sig) +reapchild(int sig) { - int state, pid; - - while ((pid = waitpid (-1, &state, WNOHANG | WUNTRACED)) > 0) - ; + int state, pid; + + while ((pid = waitpid(-1, &state, WNOHANG | WUNTRACED)) > 0); } #define BANNER \ "¡i" BBSNAME "¡j¡· ¥x¤j¬y¦æºô ¡·(" MYHOSTNAME ") ½Õ´T(" MYIP ") " /* -#define BANNER \ -"¡i" BBSNAME "¡j¡· ¥x¤j¬y¦æºô ¡·(" MYHOSTNAME ")\r\n"\ -" ½Õ´T(" MYIP ") " -*/ + * #define BANNER \ "¡i" BBSNAME "¡j¡· ¥x¤j¬y¦æºô ¡·(" MYHOSTNAME ")\r\n"\ " + * ½Õ´T(" MYIP ") " + */ /* check load and print approriate banner string in buf */ static int -chkload (char *buf) +chkload(char *buf) { - char cpu_load[30]; - int i; - - i = cpuload (cpu_load); - - sprintf (buf, BANNER" ¨t²Ît²ü\r\n %s %s \r\n", cpu_load, - (i > MAX_CPULOAD ? "¡A°ªt²ü¶q¡A½Ðµy«á¦A¨Ó " - "(½Ð§Q¥Îport 3000~3010³s½u)" : "")); + char cpu_load[30]; + int i; + + i = cpuload(cpu_load); + + sprintf(buf, BANNER " ¨t²Ît²ü\r\n %s %s \r\n", cpu_load, + (i > MAX_CPULOAD ? "¡A°ªt²ü¶q¡A½Ðµy«á¦A¨Ó " + "(½Ð§Q¥Îport 3000~3010³s½u)" : "")); #ifdef INSCREEN strcpy(buf, (i > MAX_CPULOAD ? BANNER "°ªt²ü¶q¡A½Ðµy«á¦A¨Ó(½Ð§Q¥Îport 3000~3010³s½u)" : "")); #else sprintf(buf, BANNER "%s\r\n", - (i > MAX_CPULOAD ? "°ªt²ü¶q¡A½Ðµy«á¦A¨Ó(½Ð§Q¥Îport 3000~3010³s½u)":"")); + (i > MAX_CPULOAD ? "°ªt²ü¶q¡A½Ðµy«á¦A¨Ó(½Ð§Q¥Îport 3000~3010³s½u)" : "")); #endif if (i > MAX_CPULOAD) return 1; - + return 0; } void -log_user (char *msg) +log_user(char *msg) { - char filename[200]; - - sprintf (filename, BBSHOME "/home/%c/%s/USERLOG", - cuser.userid[0], cuser.userid); - log_file (filename, msg); + char filename[200]; + + sprintf(filename, BBSHOME "/home/%c/%s/USERLOG", + cuser.userid[0], cuser.userid); + log_file(filename, msg); } void -log_usies (char *mode, char *mesg) +log_usies(char *mode, char *mesg) { - char genbuf[200]; - + char genbuf[200]; + if (!mesg) - sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : - "%s %s %s Stay:%d (%s)", - Cdate (&now), mode, cuser.userid, - (int)(now - login_start_time) / 60, cuser.username); + sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s Stay:%d (%s)" : + "%s %s %s Stay:%d (%s)", + Cdate(&now), mode, cuser.userid, + (int)(now - login_start_time) / 60, cuser.username); else - sprintf (genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", - Cdate (&now), mode, cuser.userid, mesg); - log_file (FN_USIES, genbuf); - + sprintf(genbuf, cuser.userid[0] ? "%s %s %-12s %s" : "%s %s %s%s", + Cdate(&now), mode, cuser.userid, mesg); + log_file(FN_USIES, genbuf); + /* °lÂÜ¨Ï¥ÎªÌ */ - if (HAS_PERM (PERM_LOGUSER)) - log_user (genbuf); + if (HAS_PERM(PERM_LOGUSER)) + log_user(genbuf); } static void -setflags (int mask, int value) +setflags(int mask, int value) { if (value) cuser.uflag |= mask; @@ -151,209 +153,206 @@ setflags (int mask, int value) } void -u_exit (char *mode) +u_exit(char *mode) { //userec_t xuser; - int diff = (time (0) - login_start_time) / 60; + int diff = (time(0) - login_start_time) / 60; /* close fd 0 & a to terminate network */ close(0); close(1); - reload_money(); - auto_backup (); + reload_money(); + auto_backup(); save_brdbuf(); - setflags (PAGER_FLAG, currutmp->pager != 1); - setflags (CLOAK_FLAG, currutmp->invisible); - + setflags(PAGER_FLAG, currutmp->pager != 1); + setflags(CLOAK_FLAG, currutmp->invisible); + cuser.invisible = currutmp->invisible; cuser.pager = currutmp->pager; memcpy(cuser.mind, currutmp->mind, 4); setutmpbid(0); - if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && - !currutmp->invisible ) - do_aloha ("<<¤U¯¸³qª¾>> -- §Ú¨«Åo¡I"); - - purge_utmp (currutmp); - if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff){ + if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && + !currutmp->invisible) + do_aloha("<<¤U¯¸³qª¾>> -- §Ú¨«Åo¡I"); + + purge_utmp(currutmp); + if ((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || diff) { if (!diff && cuser.numlogins) cuser.numlogins = --cuser.numlogins; /* Leeym ¤W¯¸°±¯d®É¶¡¨î¦¡ */ } - passwd_update (usernum, &cuser); - log_usies (mode, NULL); + passwd_update(usernum, &cuser); + log_usies(mode, NULL); } void -system_abort () +system_abort() { if (currmode) - u_exit ("ABORT"); - - clear (); - refresh (); - fprintf (stdout, "ÁÂÁÂ¥úÁ{, °O±o±`¨Ó³á !\n"); - exit (0); + u_exit("ABORT"); + + clear(); + refresh(); + fprintf(stdout, "ÁÂÁÂ¥úÁ{, °O±o±`¨Ó³á !\n"); + exit(0); } void -abort_bbs (int sig) +abort_bbs(int sig) { if (currmode) - u_exit ("AXXED"); - exit (0); + u_exit("AXXED"); + exit(0); } static void -abort_bbs_debug (int sig) +abort_bbs_debug(int sig) { - static int reentrant = 0; - - if (!reentrant){ - int i; + static int reentrant = 0; + + if (!reentrant) { + int i; /* close all file descriptors (including the network connection) */ - for( i = 0 ; i < 256 ; ++i ) + for (i = 0; i < 256; ++i) close(i); reentrant = 1; if (currmode) - u_exit ("AXXED"); - setproctitle("debug me!(%d)",sig); - sleep(3600); /* wait 60 mins for debug */ + u_exit("AXXED"); + setproctitle("debug me!(%d)", sig); + sleep(3600); /* wait 60 mins for debug */ } - exit (0); + exit(0); } /* µn¿ý BBS µ{¦¡ */ static void -mysrand () +mysrand() { - srand (time (NULL) + currutmp->pid); /* ®É¶¡¸ò pid ·í rand ªº seed */ + srand(time(NULL) + currutmp->pid); /* ®É¶¡¸ò pid ·í rand ªº seed */ } int -dosearchuser (char *userid) +dosearchuser(char *userid) { - if ((usernum = getuser (userid))) - memcpy (&cuser, &xuser, sizeof (cuser)); + if ((usernum = getuser(userid))) + memcpy(&cuser, &xuser, sizeof(cuser)); else - memset (&cuser, 0, sizeof (cuser)); + memset(&cuser, 0, sizeof(cuser)); return usernum; } static void talk_request(int sig) { - bell (); - bell (); - if (currutmp->msgcount){ - char buf[200]; - time_t now = time (0); - - sprintf (buf, "\033[33;41m¡¹%s\033[34;47m [%s] %s \033[0m", - SHM->uinfo[currutmp->destuip].userid, my_ctime (&now), - (currutmp->sig == 2)? "«n®ø®§¼s¼½¡I(½ÐCtrl-U,l¬d¬Ý¼ö°T°O¿ý)" - : "©I¥s¡B©I¥s¡AÅ¥¨ì½Ð¦^µª"); - move (0, 0); - clrtoeol (); - outs (buf); - refresh (); - } - else{ - unsigned char mode0 = currutmp->mode; - char c0 = currutmp->chatid[0]; - screenline_t *screen0 = calloc (t_lines, sizeof (screenline_t)); - + bell(); + bell(); + if (currutmp->msgcount) { + char buf[200]; + time_t now = time(0); + + sprintf(buf, "\033[33;41m¡¹%s\033[34;47m [%s] %s \033[0m", + SHM->uinfo[currutmp->destuip].userid, my_ctime(&now), + (currutmp->sig == 2) ? "«n®ø®§¼s¼½¡I(½ÐCtrl-U,l¬d¬Ý¼ö°T°O¿ý)" + : "©I¥s¡B©I¥s¡AÅ¥¨ì½Ð¦^µª"); + move(0, 0); + clrtoeol(); + outs(buf); + refresh(); + } else { + unsigned char mode0 = currutmp->mode; + char c0 = currutmp->chatid[0]; + screenline_t *screen0 = calloc(t_lines, sizeof(screenline_t)); + currutmp->mode = 0; currutmp->chatid[0] = 1; - memcpy (screen0, big_picture, t_lines * sizeof (screenline_t)); - talkreply (); + memcpy(screen0, big_picture, t_lines * sizeof(screenline_t)); + talkreply(); currutmp->mode = mode0; currutmp->chatid[0] = c0; - memcpy (big_picture, screen0, t_lines * sizeof (screenline_t)); - free (screen0); - redoscr (); + memcpy(big_picture, screen0, t_lines * sizeof(screenline_t)); + free(screen0); + redoscr(); } } void show_call_in(int save, int which) { - char buf[200]; - sprintf (buf, "\033[1;33;46m¡¹%s\033[37;45m %s \033[m", - currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); - move (b_lines, 0); - clrtoeol (); - refresh (); - outmsg (buf); - - if (save){ - char genbuf[200]; - time_t now; - if (!fp_writelog){ - sethomefile (genbuf, cuser.userid, fn_writelog); - fp_writelog = fopen (genbuf, "a"); + char buf[200]; + sprintf(buf, "\033[1;33;46m¡¹%s\033[37;45m %s \033[m", + currutmp->msgs[which].userid, currutmp->msgs[which].last_call_in); + move(b_lines, 0); + clrtoeol(); + refresh(); + outmsg(buf); + + if (save) { + char genbuf[200]; + time_t now; + if (!fp_writelog) { + sethomefile(genbuf, cuser.userid, fn_writelog); + fp_writelog = fopen(genbuf, "a"); } - if (fp_writelog){ - time (&now); - fprintf (fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite (&now)); + if (fp_writelog) { + time(&now); + fprintf(fp_writelog, "%s \033[0m[%s]\n", buf, Cdatelite(&now)); } } } -static int add_history_water(water_t *w, msgque_t *msg) +static int +add_history_water(water_t * w, msgque_t * msg) { - // mode: 1: all data(including userid, pid); - // 0: only last_call_in Ptt:¥ý§ï¦^¨Ó ¬Ù¤£¦h ¶i¶¥·|¦³°ÝÃD - memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); + //mode:1:all data(including userid, pid); +//0: only last_call_in Ptt:¥ý§ï¦^¨Ó¬Ù¤£¦h ¶ i ¶ ¥·|¦³°ÝÃD + memcpy(&w->msg[w->top], msg, sizeof(msgque_t)); w->top++; w->top %= WATERMODE(WATER_OFO) ? 5 : MAX_REVIEW; - + if (w->count < MAX_REVIEW) w->count++; - + return w->count; } static int -add_history(msgque_t *msg) +add_history(msgque_t * msg) { - int i = 0, j, waterinit = 0; - water_t *tmp; - if( WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ) + int i = 0, j, waterinit = 0; + water_t *tmp; + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) add_history_water(&water[0], msg); - if( WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO) ){ - for(i = 0 ; i < 5 && swater[i] ; i++ ) - if( swater[i]->pid == msg->pid ) + if (WATERMODE(WATER_NEW) || WATERMODE(WATER_OFO)) { + for (i = 0; i < 5 && swater[i]; i++) + if (swater[i]->pid == msg->pid) break; - if( i == 5 ){ + if (i == 5) { waterinit = 1; i = 4; memset(swater[4], 0, sizeof(water_t)); - } - else if( !swater[i] ){ + } else if (!swater[i]) { water_usies = i + 1; swater[i] = &water[i + 1]; waterinit = 1; } tmp = swater[i]; - if( waterinit ){ + if (waterinit) { memcpy(swater[i]->userid, msg->userid, sizeof(swater[i]->userid)); swater[i]->pid = msg->pid; } - - if( !swater[i]->uin ) + if (!swater[i]->uin) swater[i]->uin = currutmp; - - for( j = i ; j > 0 ; j-- ) + + for (j = i; j > 0; j--) swater[j] = swater[j - 1]; swater[0] = tmp; add_history_water(swater[0], msg); } - - if(WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW) ){ - if( watermode > 0 && - (water_which == swater[0] || water_which == &water[0]) ){ + if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) { + if (watermode > 0 && + (water_which == swater[0] || water_which == &water[0])) { if (watermode < water_which->count) watermode++; t_display_new(); @@ -363,35 +362,34 @@ add_history(msgque_t *msg) } void -write_request (int sig) +write_request(int sig) { - int i; - - if( WATERMODE(WATER_OFO) ){ - /* sig = SIGUSR2 waterball come in - 0 flush to water[] (by my_write2()) - */ - if( sig != 0 ){ - if( wmofo == 0 ) /* ¥¿¦b¦^¤ô²y */ + int i; + + if (WATERMODE(WATER_OFO)) { + /* + * sig = SIGUSR2 waterball come in 0 flush to water[] (by + * my_write2()) + */ + if (sig != 0) { + if (wmofo == 0) /* ¥¿¦b¦^¤ô²y */ wmofo = 1; - bell (); + bell(); show_call_in(1, currutmp->msgcount - 1); - refresh (); + refresh(); } - - if( sig == 0 || /* ¦^¤ô²yªº®ÉÔ¤S¦³¤ô²y¶i¨Ó, ¦^§¹«á¤@¦¸¼g¦^¥h */ - wmofo == -1 ){ /* ¤£¦b¦^¤ô²y¼Ò¦¡ */ - do{ + if (sig == 0 || /* ¦^¤ô²yªº®ÉÔ¤S¦³¤ô²y¶i¨Ó, ¦^§¹«á¤@¦¸¼g¦^¥h */ + wmofo == -1) { /* ¤£¦b¦^¤ô²y¼Ò¦¡ */ + do { add_history(&currutmp->msgs[0]); - if( currutmp->msgcount-- ) + if (currutmp->msgcount--) for (i = 0; i < currutmp->msgcount; i++) currutmp->msgs[i] = currutmp->msgs[i + 1]; } while (currutmp->msgcount); currutmp->msgcount = 0; } - } - else{ + } else { if (currutmp->mode != 0 && currutmp->pager != 0 && cuser.userlevel != 0 && @@ -401,25 +399,24 @@ write_request (int sig) currutmp->mode != CHATING && currutmp->mode != PAGE && currutmp->mode != IDLE && - currutmp->mode != MAILALL && currutmp->mode != MONITOR){ - char c0 = currutmp->chatid[0]; - int currstat0 = currstat; - unsigned char mode0 = currutmp->mode; - + currutmp->mode != MAILALL && currutmp->mode != MONITOR) { + char c0 = currutmp->chatid[0]; + int currstat0 = currstat; + unsigned char mode0 = currutmp->mode; + currutmp->mode = 0; currutmp->chatid[0] = 2; currstat = XMODE; - - do{ - bell (); + + do { + bell(); show_call_in(1, 0); - igetch (); + igetch(); currutmp->msgcount--; - if (currutmp->msgcount >= MAX_MSGS){ + if (currutmp->msgcount >= MAX_MSGS) { /* this causes chaos... jochang */ - raise (SIGFPE); + raise(SIGFPE); } - add_history(&currutmp->msgs[0]); for (i = 0; i < currutmp->msgcount; i++) currutmp->msgs[i] = currutmp->msgs[i + 1]; @@ -428,271 +425,263 @@ write_request (int sig) currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; - } - else{ - bell (); + } else { + bell(); show_call_in(1, 0); add_history(&currutmp->msgs[0]); - - refresh (); + + refresh(); currutmp->msgcount = 0; } } } static void -multi_user_check () +multi_user_check() { register userinfo_t *ui; - register pid_t pid; - char genbuf[3]; - - if (HAS_PERM (PERM_SYSOP)) + register pid_t pid; + char genbuf[3]; + + if (HAS_PERM(PERM_SYSOP)) return; /* don't check sysops */ - - if (cuser.userlevel){ - if (!(ui = (userinfo_t *) search_ulist (usernum))) - return; /* user isn't logged in */ - + + if (cuser.userlevel) { + if (!(ui = (userinfo_t *) search_ulist(usernum))) + return; /* user isn't logged in */ + pid = ui->pid; - if (!pid /*|| (kill(pid, 0) == -1) */ ) - return; /* stale entry in utmp file */ - - getdata (b_lines - 1, 0, "±z·Q§R°£¨ä¥L«½Æªº login (Y/N)¶Ü¡H[Y] ", - genbuf, 3, LCECHO); - - if (genbuf[0] != 'n'){ + if (!pid /* || (kill(pid, 0) == -1) */ ) + return; /* stale entry in utmp file */ + + getdata(b_lines - 1, 0, "±z·Q§R°£¨ä¥L«½Æªº login (Y/N)¶Ü¡H[Y] ", + genbuf, 3, LCECHO); + + if (genbuf[0] != 'n') { if (pid > 0) - kill (pid, SIGHUP); - log_usies ("KICK ", cuser.username); + kill(pid, SIGHUP); + log_usies("KICK ", cuser.username); + } else { + if (search_ulistn(usernum, 3) != NULL) + system_abort(); /* Goodbye(); */ } - else{ - if (search_ulistn(usernum, 3)!=NULL) - system_abort (); /* Goodbye(); */ - } - } - else{ + } else { /* allow multiple guest user */ - if (search_ulistn(usernum, 100)!=NULL){ - outs ("\n©êºp¡A¥Ø«e¤w¦³¤Ó¦h guest ¦b¯¸¤W, ½Ð¥Înewµù¥U¡C\n"); - pressanykey (); - oflush (); - exit (1); + if (search_ulistn(usernum, 100) != NULL) { + outs("\n©êºp¡A¥Ø«e¤w¦³¤Ó¦h guest ¦b¯¸¤W, ½Ð¥Înewµù¥U¡C\n"); + pressanykey(); + oflush(); + exit(1); } } } /* bad login */ -static char str_badlogin[] = "logins.bad"; +static char str_badlogin[] = "logins.bad"; static void -logattempt (char *uid, char type) +logattempt(char *uid, char type) { - char fname[40]; - int fd, len; - char genbuf[200]; - - sprintf (genbuf, "%c%-12s[%s] %s@%s\n", type, uid, - Cdate (&login_start_time), remoteusername, fromhost); - len = strlen (genbuf); - if ((fd = open (str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ - write (fd, genbuf, len); - close (fd); + char fname[40]; + int fd, len; + char genbuf[200]; + + sprintf(genbuf, "%c%-12s[%s] %s@%s\n", type, uid, + Cdate(&login_start_time), remoteusername, fromhost); + len = strlen(genbuf); + if ((fd = open(str_badlogin, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + write(fd, genbuf, len); + close(fd); } - if (type == '-'){ - sprintf (genbuf, "[%s] %s\n", Cdate (&login_start_time), fromhost); - len = strlen (genbuf); - sethomefile (fname, uid, str_badlogin); - if ((fd = open (fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0){ - write (fd, genbuf, len); - close (fd); + if (type == '-') { + sprintf(genbuf, "[%s] %s\n", Cdate(&login_start_time), fromhost); + len = strlen(genbuf); + sethomefile(fname, uid, str_badlogin); + if ((fd = open(fname, O_WRONLY | O_CREAT | O_APPEND, 0644)) > 0) { + write(fd, genbuf, len); + close(fd); } } } static void -login_query () +login_query() { - char uid[IDLEN + 1], passbuf[PASSLEN]; - int attempts; - char genbuf[200]; + char uid[IDLEN + 1], passbuf[PASSLEN]; + int attempts; + char genbuf[200]; attach_SHM(); - resolve_garbage (); - now= time(0); + resolve_garbage(); + now = time(0); attempts = SHM->UTMPnumber; #ifdef DEBUG move(1, 0); prints("debugging mode\ncurrent pid: %d\n", getpid()); #else - show_file ("etc/Welcome", 1, -1, NO_RELOAD); + show_file("etc/Welcome", 1, -1, NO_RELOAD); #endif - output ("1", 1); - if (attempts >= MAX_ACTIVE){ - outs ("¥Ñ©ó¤H¼Æ¤Ó¦h¡A½Ð±zµy«á¦A¨Ó¡C\n"); - refresh (); - exit (1); + output("1", 1); + if (attempts >= MAX_ACTIVE) { + outs("¥Ñ©ó¤H¼Æ¤Ó¦h¡A½Ð±zµy«á¦A¨Ó¡C\n"); + refresh(); + exit(1); } - - /* hint */ - - attempts = 0; - while (1){ - if (attempts++ >= LOGINATTEMPTS){ - more ("etc/goodbye", NA); - pressanykey (); - exit (1); - } + /* hint */ + + attempts = 0; + while (1) { + if (attempts++ >= LOGINATTEMPTS) { + more("etc/goodbye", NA); + pressanykey(); + exit(1); + } #ifdef DEBUG - move(19, 0); - prints("current pid: %d ", getpid()); + move(19, 0); + prints("current pid: %d ", getpid()); #endif - getdata (20, 0, "½Ð¿é¤J¥N¸¹¡A©Î¥H[guest]°ÑÆ[¡A¥H[new]µù¥U¡G", - uid, sizeof(uid), DOECHO); - if (strcasecmp (uid, str_new) == 0){ + getdata(20, 0, "½Ð¿é¤J¥N¸¹¡A©Î¥H[guest]°ÑÆ[¡A¥H[new]µù¥U¡G", + uid, sizeof(uid), DOECHO); + if (strcasecmp(uid, str_new) == 0) { #ifdef LOGINASNEW - new_register (); - break; + new_register(); + break; #else - outs ("¥»¨t²Î¥Ø«eµLªk¥H new µù¥U, ½Ð¥Î guest ¶i¤J\n"); - continue; + outs("¥»¨t²Î¥Ø«eµLªk¥H new µù¥U, ½Ð¥Î guest ¶i¤J\n"); + continue; #endif - } - else if (uid[0] == '\0' || !dosearchuser (uid)){ - outs (err_uid); - } - else if (strcmp (uid, STR_GUEST)){ - getdata (21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); - passbuf[8] = '\0'; - - if (!checkpasswd (cuser.passwd, passbuf) - /* || (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode) */ ){ - logattempt (cuser.userid, '-'); - outs (ERR_PASSWD); - } - else{ - logattempt (cuser.userid, ' '); - if (strcasecmp ("SYSOP", cuser.userid) == 0) - cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | - PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | - PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | - PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS | - PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; - break; - } - } - else{ /* guest */ - cuser.userlevel = 0; - cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; - break; - } - } - multi_user_check (); - sethomepath (genbuf, cuser.userid); - mkdir (genbuf, 0755); + } else if (uid[0] == '\0' || !dosearchuser(uid)) { + outs(err_uid); + } else if (strcmp(uid, STR_GUEST)) { + getdata(21, 0, MSG_PASSWD, passbuf, sizeof(passbuf), NOECHO); + passbuf[8] = '\0'; + + if (!checkpasswd(cuser.passwd, passbuf) + /* || (HAS_PERM(PERM_SYSOP) && !use_shell_login_mode) */ ) { + logattempt(cuser.userid, '-'); + outs(ERR_PASSWD); + } else { + logattempt(cuser.userid, ' '); + if (strcasecmp("SYSOP", cuser.userid) == 0) + cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | + PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | + PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | + PERM_DENYPOST | PERM_BM | PERM_ACCOUNTS | + PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; + break; + } + } else { /* guest */ + cuser.userlevel = 0; + cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + break; + } + } + multi_user_check(); + sethomepath(genbuf, cuser.userid); + mkdir(genbuf, 0755); } void -add_distinct (char *fname, char *line) +add_distinct(char *fname, char *line) { - FILE *fp; - int n = 0; - - if ((fp = fopen (fname, "a+"))){ - char buffer[80]; - char tmpname[100]; - FILE *fptmp; - - strcpy (tmpname, fname); - strcat (tmpname, "_tmp"); - if (!(fptmp = fopen (tmpname, "w"))){ - fclose (fp); + FILE *fp; + int n = 0; + + if ((fp = fopen(fname, "a+"))) { + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy(tmpname, fname); + strcat(tmpname, "_tmp"); + if (!(fptmp = fopen(tmpname, "w"))) { + fclose(fp); return; } - rewind (fp); - while (fgets (buffer, 80, fp)){ - char *p = buffer + strlen (buffer) - 1; - + rewind(fp); + while (fgets(buffer, 80, fp)) { + char *p = buffer + strlen(buffer) - 1; + if (p[-1] == '\n' || p[-1] == '\r') p[-1] = 0; - if (!strcmp (buffer, line)) + if (!strcmp(buffer, line)) break; - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - - if (feof (fp)) - fprintf (fptmp, "%s%c#1\n", line, 0); - else{ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n + 1); - while (fgets (buffer, 80, fp)){ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + + if (feof(fp)) + fprintf(fptmp, "%s%c#1\n", line, 0); + else { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n + 1); + while (fgets(buffer, 80, fp)) { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } } - fclose (fp); - fclose (fptmp); - unlink (fname); - rename (tmpname, fname); + fclose(fp); + fclose(fptmp); + unlink(fname); + rename(tmpname, fname); } } void -del_distinct (char *fname, char *line) +del_distinct(char *fname, char *line) { - FILE *fp; - int n = 0; - - if ((fp = fopen (fname, "r"))){ - char buffer[80]; - char tmpname[100]; - FILE *fptmp; - - strcpy (tmpname, fname); - strcat (tmpname, "_tmp"); - if (!(fptmp = fopen (tmpname, "w"))){ - fclose (fp); + FILE *fp; + int n = 0; + + if ((fp = fopen(fname, "r"))) { + char buffer[80]; + char tmpname[100]; + FILE *fptmp; + + strcpy(tmpname, fname); + strcat(tmpname, "_tmp"); + if (!(fptmp = fopen(tmpname, "w"))) { + fclose(fp); return; } - rewind (fp); - while (fgets (buffer, 80, fp)){ - char *p = buffer + strlen (buffer) - 1; - + rewind(fp); + while (fgets(buffer, 80, fp)) { + char *p = buffer + strlen(buffer) - 1; + if (p[-1] == '\n' || p[-1] == '\r') p[-1] = 0; - if (!strcmp (buffer, line)) + if (!strcmp(buffer, line)) break; - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - - if (!feof (fp)) - while (fgets (buffer, 80, fp)){ - sscanf (buffer + strlen (buffer) + 2, "%d", &n); - fprintf (fptmp, "%s%c#%d\n", buffer, 0, n); + + if (!feof(fp)) + while (fgets(buffer, 80, fp)) { + sscanf(buffer + strlen(buffer) + 2, "%d", &n); + fprintf(fptmp, "%s%c#%d\n", buffer, 0, n); } - fclose (fp); - fclose (fptmp); - unlink (fname); - rename (tmpname, fname); + fclose(fp); + fclose(fptmp); + unlink(fname); + rename(tmpname, fname); } } #ifdef WHERE static int -where (char *from) +where(char *from) { - register int i = 0, count = 0, j; - - for (j = 0; j < SHM->top; j++){ - char *token = strtok (SHM->domain[j], "&"); - + register int i = 0, count = 0, j; + + for (j = 0; j < SHM->top; j++) { + char *token = strtok(SHM->domain[j], "&"); + i = 0; count = 0; - while (token){ - if (strstr (from, token)) + while (token) { + if (strstr(from, token)) count++; - token = strtok (NULL, "&"); + token = strtok(NULL, "&"); i++; } if (i == count) @@ -705,305 +694,302 @@ where (char *from) #endif static void -check_BM () +check_BM() { - int i; - boardheader_t *bhdr; - + int i; + boardheader_t *bhdr; + cuser.userlevel &= ~PERM_BM; - for (i = 0, bhdr = bcache; i < numboards && !is_BM (bhdr->BM); i++, bhdr++) - ; + for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); } static void -setup_utmp (int mode) +setup_utmp(int mode) { - userinfo_t uinfo; - memset (&uinfo, 0, sizeof (uinfo)); - uinfo.pid = currpid = getpid (); + userinfo_t uinfo; + memset(&uinfo, 0, sizeof(uinfo)); + uinfo.pid = currpid = getpid(); uinfo.uid = usernum; uinfo.mode = currstat = mode; - uinfo.mailalert = load_mailalert (cuser.userid); + uinfo.mailalert = load_mailalert(cuser.userid); if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM) - check_BM (); /* Ptt ¦Û°Ê¨ú¤UÂ÷¾ªO¥DÅv¤O */ - + check_BM(); /* Ptt ¦Û°Ê¨ú¤UÂ÷¾ªO¥DÅv¤O */ + uinfo.userlevel = cuser.userlevel; uinfo.sex = cuser.sex % 8; - uinfo.lastact = time (NULL); - strcpy (uinfo.userid, cuser.userid); - strcpy (uinfo.realname, cuser.realname); - strcpy (uinfo.username, cuser.username); - strncpy (uinfo.from, fromhost, 23); + uinfo.lastact = time(NULL); + strcpy(uinfo.userid, cuser.userid); + strcpy(uinfo.realname, cuser.realname); + strcpy(uinfo.username, cuser.username); + strncpy(uinfo.from, fromhost, 23); uinfo.five_win = cuser.five_win; uinfo.five_lose = cuser.five_lose; uinfo.five_tie = cuser.five_tie; uinfo.invisible = cuser.invisible % 2; - uinfo.pager = cuser.pager%5; + uinfo.pager = cuser.pager % 5; memcpy(uinfo.mind, cuser.mind, 4); #ifdef WHERE - uinfo.from_alias = where (fromhost); + uinfo.from_alias = where(fromhost); #endif #ifndef FAST_LOGIN - setuserfile (buf, "remoteuser"); - - strcpy (remotebuf, fromhost); - strcat (remotebuf, ctime (&now)); - remotebuf[strlen (remotebuf) - 1] = 0; - add_distinct (buf, remotebuf); + setuserfile(buf, "remoteuser"); + + strcpy(remotebuf, fromhost); + strcat(remotebuf, ctime(&now)); + remotebuf[strlen(remotebuf) - 1] = 0; + add_distinct(buf, remotebuf); #endif if (enter_uflag & CLOAK_FLAG) uinfo.invisible = YEA; - getnewutmpent (&uinfo); + getnewutmpent(&uinfo); #ifndef _BBS_UTIL_C_ - friend_load (); + friend_load(); #endif } static void -user_login () +user_login() { - char ans[4], i; - char genbuf[200]; - struct tm *ptime, *tmp; - time_t now; - int a; + char ans[4], i; + char genbuf[200]; + struct tm *ptime, *tmp; + time_t now; + int a; /*** Heat:¼s§iµü char *ADV[] = { "7/17 @LIVE ¶Ã¼u, ¦óªYÁJ ªº ¤J³õ¨÷n°eµ¹ ptt ªº·R¥ÎªÌ!", "±ýª¾¸Ô±¡½Ð¬Ý PttAct ªO!!", }; ***/ - - log_usies ("ENTER", fromhost); - setproctitle ("%s: %s", margs, cuser.userid); - resolve_fcache (); - resolve_boards (); - memset( &water[0],0,sizeof(water_t) * 6); + + log_usies("ENTER", fromhost); + setproctitle("%s: %s", margs, cuser.userid); + resolve_fcache(); + resolve_boards(); + memset(&water[0], 0, sizeof(water_t) * 6); strcpy(water[0].userid, " ¥þ³¡ "); /* ªì©l¤Æ uinfo¡Bflag¡Bmode */ - setup_utmp (LOGIN); - mysrand (); /* ªì©l¤Æ: random number ¼W¥[user¸ò®É¶¡ªº®t²§ */ + setup_utmp(LOGIN); + mysrand(); /* ªì©l¤Æ: random number ¼W¥[user¸ò®É¶¡ªº®t²§ */ currmode = MODE_STARTED; enter_uflag = cuser.uflag; - + /* get local time */ - time (&now); - ptime = localtime (&now); - tmp = localtime (&cuser.lastlogin); - if ((a = SHM->UTMPnumber) > SHM->max_user){ + time(&now); + ptime = localtime(&now); + tmp = localtime(&cuser.lastlogin); + if ((a = SHM->UTMPnumber) > SHM->max_user) { SHM->max_user = a; SHM->max_time = now; } - init_brdbuf(); - brc_initial (DEFAULT_BOARD); - set_board (); + init_brdbuf(); + brc_initial(DEFAULT_BOARD); + set_board(); /* µe±³B²z¶}©l */ - if (!(HAS_PERM (PERM_SYSOP) && HAS_PERM (PERM_DENYPOST)) && !currutmp->invisible ) - do_aloha ("<<¤W¯¸³qª¾>> -- §Ú¨Ó°Õ¡I"); - if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month){ - more ("etc/Welcome_birth", NA); + if (!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST)) && !currutmp->invisible) + do_aloha("<<¤W¯¸³qª¾>> -- §Ú¨Ó°Õ¡I"); + if (ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) { + more("etc/Welcome_birth", NA); currutmp->birth = 1; - } - else{ + } else { #ifdef MULTI_WELCOME_LOGIN - char buf[80]; - int nScreens; - for( nScreens = 0 ; nScreens < 10 ; ++nScreens ){ + char buf[80]; + int nScreens; + for (nScreens = 0; nScreens < 10; ++nScreens) { sprintf(buf, "etc/Welcome_login.%d", nScreens); - if( access(buf, 0) < 0 ) + if (access(buf, 0) < 0) break; } printf("%d\n", nScreens); - if( nScreens == 0 ){ // multi screen error? - more ("etc/Welcome_login", NA); - } - else{ + if (nScreens == 0) { + //multi screen error ? + more("etc/Welcome_login", NA); + } else { sprintf(buf, "etc/Welcome_login.%d", (int)login_start_time % nScreens); - more (buf, NA); + more(buf, NA); } #else - more ("etc/Welcome_login", NA); + more("etc/Welcome_login", NA); #endif //pressanykey(); //more("etc/CSIE_Week", NA); currutmp->birth = 0; } - - if (cuser.userlevel){/* not guest */ - move (t_lines - 4, 0); - prints ("\033[m Åwªï±z²Ä \033[1;33m%d\033[0;37m «×«ô³X¥»¯¸¡A" - "¤W¦¸±z¬O±q \033[1;33m%s\033[0;37m ³s©¹¥»¯¸¡A\n" - " §Ú°O±o¨º¤Ñ¬O \033[1;33m%s\033[0;37m¡C\n", - ++cuser.numlogins, cuser.lasthost, Cdate (&cuser.lastlogin)); - pressanykey (); - - if (currutmp->birth && tmp->tm_mday != ptime->tm_mday){ - more ("etc/birth.post", YEA); - brc_initial ("WhoAmI"); - set_board (); - do_post (); + + if (cuser.userlevel) { /* not guest */ + move(t_lines - 4, 0); + prints("\033[m Åwªï±z²Ä \033[1;33m%d\033[0;37m «×«ô³X¥»¯¸¡A" + "¤W¦¸±z¬O±q \033[1;33m%s\033[0;37m ³s©¹¥»¯¸¡A\n" + " §Ú°O±o¨º¤Ñ¬O \033[1;33m%s\033[0;37m¡C\n", + ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); + pressanykey(); + + if (currutmp->birth && tmp->tm_mday != ptime->tm_mday) { + more("etc/birth.post", YEA); + brc_initial("WhoAmI"); + set_board(); + do_post(); } - setuserfile (genbuf, str_badlogin); - if (more (genbuf, NA) != -1){ - getdata (b_lines - 1, 0, "±zn§R°£¥H¤W¿ù»~¹Á¸Õªº°O¿ý¶Ü(Y/N)?[Y]", - ans, 3, LCECHO); + setuserfile(genbuf, str_badlogin); + if (more(genbuf, NA) != -1) { + getdata(b_lines - 1, 0, "±zn§R°£¥H¤W¿ù»~¹Á¸Õªº°O¿ý¶Ü(Y/N)?[Y]", + ans, 3, LCECHO); if (*ans != 'n') - unlink (genbuf); + unlink(genbuf); } - check_register (); - strncpy (cuser.lasthost, fromhost, 16); + check_register(); + strncpy(cuser.lasthost, fromhost, 16); cuser.lasthost[15] = '\0'; - restore_backup (); - } - else if (!strcmp (cuser.userid, STR_GUEST)){ - char *nick[13] = { + restore_backup(); + } else if (!strcmp(cuser.userid, STR_GUEST)) { + char *nick[13] = { "·¦¤l", "¨©´ß", "¤º¦ç", "Ä_¯S²~", "½¨®³½", "¾ð¸", "¯BµÓ", "¾c¤l", "¼ç¤ô¸¥", "Å]¤ý", "ÅKÅø", "¦Ò¨÷", "¤j¬ü¤k" }; - char *name[13] = { + char *name[13] = { "¤j¤ý·¦¤l", "ÆxÄMÁ³", "¤ñ°ò¥§", "¥i¤f¥i¼Ö", "¥õªaªº³½", "¾Ð", "°ª©£«Î", "AIR Jordon", "¬õ¦â¤Q¤ë¸¹", "§å½ð½ð", "SASAYA·¦¥¤", "Àn³J", "¥¬¾|§J÷«³½»µ·" }; - char *addr[13] = { + char *addr[13] = { "¤Ñ°ó¼Ö¶é", "¤j®ü", "ºñ®q¤p©]¦±", "¬ü°ê", "ºñ¦â¬À·äÁG", "»·¤è", "쥻®ü", "NIKE", "ĬÁp", "¨k¤K618«Ç", "·R¤§¨ý", "¤Ñ¤W", "ÂŦâ¬À·äÁG" }; i = login_start_time % 13; - sprintf (cuser.username, "®üÃäº}¨Óªº%s", nick[(int) i]); - sprintf (currutmp->username, cuser.username); - sprintf (cuser.realname, name[(int) i]); - sprintf (currutmp->realname, cuser.realname); - sprintf (cuser.address, addr[(int) i]); + sprintf(cuser.username, "®üÃäº}¨Óªº%s", nick[(int)i]); + sprintf(currutmp->username, cuser.username); + sprintf(cuser.realname, name[(int)i]); + sprintf(currutmp->realname, cuser.realname); + sprintf(cuser.address, addr[(int)i]); cuser.sex = i % 8; currutmp->pager = 2; - pressanykey (); - } - else - pressanykey (); - - if (!PERM_HIDE (currutmp)) + pressanykey(); + } else + pressanykey(); + + if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; - - passwd_update (usernum, &cuser); - + + passwd_update(usernum, &cuser); + for (i = 0; i < NUMVIEWFILE; i++) if ((cuser.loginview >> i) & 1) - more (loginview_file[(int) i][0], YEA); + more(loginview_file[(int)i][0], YEA); } static void -do_aloha (char *hello) +do_aloha(char *hello) { - FILE *fp; - char userid[80]; - char genbuf[200]; - - setuserfile (genbuf, "aloha"); - if ((fp = fopen (genbuf, "r"))){ - sprintf (genbuf, hello); - while (fgets (userid, 80, fp)){ - userinfo_t *uentp; - int tuid; - - if ((tuid = searchuser (userid)) && tuid != usernum && - (uentp = (userinfo_t *) search_ulist (tuid)) && - isvisible(uentp, currutmp)){ - my_write (uentp->pid, genbuf, uentp->userid, 2, NULL); + FILE *fp; + char userid[80]; + char genbuf[200]; + + setuserfile(genbuf, "aloha"); + if ((fp = fopen(genbuf, "r"))) { + sprintf(genbuf, hello); + while (fgets(userid, 80, fp)) { + userinfo_t *uentp; + int tuid; + + if ((tuid = searchuser(userid)) && tuid != usernum && + (uentp = (userinfo_t *) search_ulist(tuid)) && + isvisible(uentp, currutmp)) { + my_write(uentp->pid, genbuf, uentp->userid, 2, NULL); } } - fclose (fp); + fclose(fp); } } static void -do_term_init () +do_term_init() { - term_init (); - initscr (); + term_init(); + initscr(); } static void -start_client () +start_client() { #ifdef CPULIMIT - struct rlimit rml; + struct rlimit rml; rml.rlim_cur = CPULIMIT * 60; rml.rlim_max = CPULIMIT * 60; setrlimit(RLIMIT_CPU, &rml); #endif - + /* system init */ - nice (2); /* Ptt: lower priority */ - login_start_time = time (0); + nice(2); /* Ptt: lower priority */ + login_start_time = time(0); currmode = 0; - - signal (SIGHUP, abort_bbs); - signal (SIGTERM, abort_bbs); - signal (SIGPIPE, abort_bbs); - - signal (SIGINT, abort_bbs_debug); - signal (SIGQUIT, abort_bbs_debug); - signal (SIGILL, abort_bbs_debug); - signal (SIGABRT, abort_bbs_debug); - signal (SIGFPE, abort_bbs_debug); - signal (SIGBUS, abort_bbs_debug); - signal (SIGSEGV, abort_bbs_debug); - - signal_restart (SIGUSR1, talk_request); - signal_restart (SIGUSR2, write_request); - - dup2 (0, 1); + + signal(SIGHUP, abort_bbs); + signal(SIGTERM, abort_bbs); + signal(SIGPIPE, abort_bbs); + + signal(SIGINT, abort_bbs_debug); + signal(SIGQUIT, abort_bbs_debug); + signal(SIGILL, abort_bbs_debug); + signal(SIGABRT, abort_bbs_debug); + signal(SIGFPE, abort_bbs_debug); + signal(SIGBUS, abort_bbs_debug); + signal(SIGSEGV, abort_bbs_debug); + + signal_restart(SIGUSR1, talk_request); + signal_restart(SIGUSR2, write_request); + + dup2(0, 1); /* initialize passwd semaphores */ - if( passwd_init() ) - exit (1); - - do_term_init (); - signal (SIGALRM, abort_bbs); - alarm (600); - login_query (); /* Ptt ¥[¤Wlogin time out */ - user_login (); - m_init (); - - if (now - SHM->close_vote_time > 86400) // §ï¬°¤@¤Ñ¤@¦¸ - { - b_closepolls (); - SHM->close_vote_time = now; - } + if (passwd_init()) + exit(1); + + do_term_init(); + signal(SIGALRM, abort_bbs); + alarm(600); + login_query(); /* Ptt ¥[¤Wlogin time out */ + user_login(); + m_init(); + + if (now - SHM->close_vote_time > 86400) + //§ï¬°¤@¤Ñ¤@¦¸ + { + b_closepolls(); + SHM->close_vote_time = now; + } if (!(cuser.uflag & COLOR_FLAG)) showansi = 0; - signal (SIGALRM, SIG_IGN); - if (chkmailbox ()) - m_read (); - - domenu (MMENU, "¥D¥\\¯àªí", (currutmp->mailalert ? 'M' : 'C'), cmdlist); + signal(SIGALRM, SIG_IGN); + if (chkmailbox()) + m_read(); + + domenu(MMENU, "¥D¥\\¯àªí", (currutmp->mailalert ? 'M' : 'C'), cmdlist); } /* FSA (finite state automata) for telnet protocol */ static void -telnet_init () +telnet_init() { - static char svr[] = { + static char svr[] = { IAC, DO, TELOPT_TTYPE, IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE, IAC, WILL, TELOPT_ECHO, IAC, WILL, TELOPT_SGA }; - char *cmd; - int n, len, rset; - struct timeval to; - char buf[64]; - for (n = 0, cmd = svr; n < 4; n++){ + char *cmd; + int n, len, rset; + struct timeval to; + char buf[64]; + for (n = 0, cmd = svr; n < 4; n++) { len = (n == 1 ? 6 : 3); - write (0, cmd, len); + write(0, cmd, len); cmd += len; to.tv_sec = 3; to.tv_usec = 0; - rset=1; + rset = 1; if (select(1, (fd_set *) & rset, NULL, NULL, &to) > 0) - recv(0, buf, sizeof (buf),0); + recv(0, buf, sizeof(buf), 0); } } @@ -1013,7 +999,7 @@ telnet_init () * 1413 protocols. It queries an RFC 931 etc. compatible daemon on a remote * host to look up the owner of a connection. The information should not be * used for authentication purposes. This routine intercepts alarm signals. - * + * * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands. */ @@ -1025,140 +1011,141 @@ telnet_init () #if 0 /* timeout - handle timeouts */ static void -timeout (int sig) +timeout(int sig) { - longjmp (byebye, sig); + longjmp(byebye, sig); } #endif static void -getremotename (struct sockaddr_in *from, char *rhost, char *rname) +getremotename(struct sockaddr_in * from, char *rhost, char *rname) { /* get remote host name */ - + #ifdef FAST_LOGIN - strcpy (rhost, (char *) inet_ntoa (from->sin_addr)); + strcpy(rhost, (char *)inet_ntoa(from->sin_addr)); #else struct sockaddr_in our_sin; struct sockaddr_in rmt_sin; - unsigned rmt_port, rmt_pt; - unsigned our_port, our_pt; - FILE *fp; - char buffer[512], user[80], *cp; - int s; + unsigned rmt_port, rmt_pt; + unsigned our_port, our_pt; + FILE *fp; + char buffer[512], user[80], *cp; + int s; static struct hostent *hp; - - + + hp = NULL; - if (setjmp (byebye) == 0){ - signal (SIGALRM, timeout); - alarm (3); - hp = gethostbyaddr ((char *) &from->sin_addr, sizeof (struct in_addr), - from->sin_family); - alarm (0); + if (setjmp(byebye) == 0) { + signal(SIGALRM, timeout); + alarm(3); + hp = gethostbyaddr((char *)&from->sin_addr, sizeof(struct in_addr), + from->sin_family); + alarm(0); } - strcpy (rhost, hp ? hp->h_name : (char *) inet_ntoa (from->sin_addr)); - -/* - * Use one unbuffered stdio stream for writing to and for reading from the - * RFC931 etc. server. This is done because of a bug in the SunOS 4.1.x - * stdio library. The bug may live in other stdio implementations, too. - * When we use a single, buffered, bidirectional stdio stream ("r+" or "w+" - * mode) we read our own output. Such behaviour would make sense with - * resources that support random-access operations, but not with sockets. - */ + strcpy(rhost, hp ? hp->h_name : (char *)inet_ntoa(from->sin_addr)); + + /* + * Use one unbuffered stdio stream for writing to and for reading from + * the RFC931 etc. server. This is done because of a bug in the SunOS + * 4.1.x stdio library. The bug may live in other stdio implementations, + * too. When we use a single, buffered, bidirectional stdio stream ("r+" + * or "w+" mode) we read our own output. Such behaviour would make sense + * with resources that support random-access operations, but not with + * sockets. + */ - s = sizeof (our_sin); - if (getsockname (0, (struct sockaddr *) &our_sin, &s) < 0) + s = sizeof(our_sin); + if (getsockname(0, (struct sockaddr *) & our_sin, &s) < 0) return; - - if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) + + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) return; - - if (!(fp = fdopen (s, "r+"))){ - close (s); + + if (!(fp = fdopen(s, "r+"))) { + close(s); return; } /* Set up a timer so we won't get stuck while waiting for the server. */ - if (setjmp (byebye) == 0){ - signal (SIGALRM, timeout); - alarm (RFC931_TIMEOUT); - -/* - * Bind the local and remote ends of the query socket to the same IP - * addresses as the connection under investigation. We go through all - * this trouble because the local or remote system might have more than - * one network address. The RFC931 etc. client sends only port numbers; - * the server takes the IP addresses from the query socket. - */ - our_pt = ntohs (our_sin.sin_port); - our_sin.sin_port = htons (ANY_PORT); - - rmt_sin = *from; - rmt_pt = ntohs (rmt_sin.sin_port); - rmt_sin.sin_port = htons (RFC931_PORT); - - setbuf (fp, (char *) 0); - s = fileno (fp); - - if (bind (s, (struct sockaddr *) &our_sin, sizeof (our_sin)) >= 0 && - connect (s, (struct sockaddr *) &rmt_sin, sizeof (rmt_sin)) >= 0){ -/* - * Send query to server. Neglect the risk that a 13-byte write would - * have to be fragmented by the local system and cause trouble with - * buggy System V stdio libraries. - */ - fprintf (fp, "%u,%u\r\n", rmt_pt, our_pt); - fflush (fp); -/* - * Read response from server. Use fgets()/sscanf() so we can work - * around System V stdio libraries that incorrectly assume EOF when a - * read from a socket returns less than requested. - */ - if (fgets (buffer, sizeof (buffer), fp) && !ferror (fp) - && !feof (fp) - && sscanf (buffer, "%u , %u : USERID :%*[^:]:%79s", &rmt_port, - &our_port, user) == 3 && rmt_pt == rmt_port - && our_pt == our_port){ + if (setjmp(byebye) == 0) { + signal(SIGALRM, timeout); + alarm(RFC931_TIMEOUT); + + /* + * Bind the local and remote ends of the query socket to the same IP + * addresses as the connection under investigation. We go through all + * this trouble because the local or remote system might have more + * than one network address. The RFC931 etc. client sends only port + * numbers; the server takes the IP addresses from the query socket. + */ + our_pt = ntohs(our_sin.sin_port); + our_sin.sin_port = htons(ANY_PORT); -/* - * Strip trailing carriage return. It is part of the protocol, not - * part of the data. - */ - if ((cp = (char *) strchr (user, '\r'))) + rmt_sin = *from; + rmt_pt = ntohs(rmt_sin.sin_port); + rmt_sin.sin_port = htons(RFC931_PORT); + + setbuf(fp, (char *)0); + s = fileno(fp); + + if (bind(s, (struct sockaddr *) & our_sin, sizeof(our_sin)) >= 0 && + connect(s, (struct sockaddr *) & rmt_sin, sizeof(rmt_sin)) >= 0) { + /* + * Send query to server. Neglect the risk that a 13-byte write + * would have to be fragmented by the local system and cause + * trouble with buggy System V stdio libraries. + */ + fprintf(fp, "%u,%u\r\n", rmt_pt, our_pt); + fflush(fp); + /* + * Read response from server. Use fgets()/sscanf() so we can work + * around System V stdio libraries that incorrectly assume EOF + * when a read from a socket returns less than requested. + */ + if (fgets(buffer, sizeof(buffer), fp) && !ferror(fp) + && !feof(fp) + && sscanf(buffer, "%u , %u : USERID :%*[^:]:%79s", &rmt_port, + &our_port, user) == 3 && rmt_pt == rmt_port + && our_pt == our_port) { + + /* + * Strip trailing carriage return. It is part of the + * protocol, not part of the data. + */ + if ((cp = (char *)strchr(user, '\r'))) *cp = 0; - strcpy (rname, user); + strcpy(rname, user); } } - alarm (0); + alarm(0); } - fclose (fp); + fclose(fp); #endif } static int -bind_port (int port) +bind_port(int port) { - int sock, on; - - sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); - + int sock, on; + + sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + on = 1; - setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof (on)); - setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof (on)); - + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); + setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof(on)); + on = 0; - setsockopt (sock, SOL_SOCKET, SO_LINGER, (char *) &on, sizeof (on)); - - xsin.sin_port = htons (port); - if (bind (sock, (struct sockaddr *) &xsin, sizeof xsin) < 0){ - syslog (LOG_INFO, "bbsd bind_port can't bind to %d", port); - exit (1); + setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&on, sizeof(on)); + + xsin.sin_port = htons(port); + if (bind(sock, (struct sockaddr *) & xsin, sizeof xsin) < 0) { + syslog(LOG_INFO, "bbsd bind_port can't bind to %d", port); + exit(1); } - if (listen (sock, SOCKET_QLEN) < 0){ - syslog (LOG_INFO, "bbsd bind_port can't listen to %d", port); - exit (1); + if (listen(sock, SOCKET_QLEN) < 0) { + syslog(LOG_INFO, "bbsd bind_port can't listen to %d", port); + exit(1); } return sock; } @@ -1167,136 +1154,132 @@ bind_port (int port) /*******************************************************/ -static void shell_login (int argc, char *argv[], char *envp[]); -static void daemon_login (int argc, char *argv[], char *envp[]); -static int check_ban_and_load (int fd); +static void shell_login(int argc, char *argv[], char *envp[]); +static void daemon_login(int argc, char *argv[], char *envp[]); +static int check_ban_and_load(int fd); int -main (int argc, char *argv[], char *envp[]) +main(int argc, char *argv[], char *envp[]) { start_time = time(NULL); /* avoid SIGPIPE */ - signal (SIGPIPE, SIG_IGN); - + signal(SIGPIPE, SIG_IGN); + /* avoid erroneous signal from other mbbsd */ - signal (SIGUSR1, SIG_IGN); - signal (SIGUSR2, SIG_IGN); - + signal(SIGUSR1, SIG_IGN); + signal(SIGUSR2, SIG_IGN); + /* check if invoked as "bbs" */ if (argc == 3) - shell_login (argc, argv, envp); + shell_login(argc, argv, envp); else - daemon_login (argc, argv, envp); - + daemon_login(argc, argv, envp); + return 0; } static void -shell_login (int argc, char *argv[], char *envp[]) +shell_login(int argc, char *argv[], char *envp[]) { - + /* Give up root privileges: no way back from here */ - setgid (BBSGID); - setuid (BBSUID); - chdir (BBSHOME); - - + setgid(BBSGID); + setuid(BBSUID); + chdir(BBSHOME); + + use_shell_login_mode = 1; - initsetproctitle (argc, argv, envp); - - /* copy fromindent: Standard input:1138: Error:Unexpected end of file - the original "bbs" */ - if (argc > 1){ - strcpy (fromhost, argv[1]); + initsetproctitle(argc, argv, envp); + + /* + * copy fromindent: Standard input:1138: Error:Unexpected end of file the + * original "bbs" + */ + if (argc > 1) { + strcpy(fromhost, argv[1]); if (argc > 3) - strcpy (remoteusername, argv[3]); + strcpy(remoteusername, argv[3]); } - - close (2); + close(2); /* don't close fd 1, at least init_tty need it */ - - init_tty (); - if (check_ban_and_load (0)){ - exit (0); + + init_tty(); + if (check_ban_and_load(0)) { + exit(0); } - start_client (); + start_client(); } static void -daemon_login (int argc, char *argv[], char *envp[]) +daemon_login(int argc, char *argv[], char *envp[]) { - int msock, csock; /* socket for Master and Child */ - FILE *fp; - int listen_port = 23; - int len_of_sock_addr; - char buf[256]; - + int msock, csock; /* socket for Master and Child */ + FILE *fp; + int listen_port = 23; + int len_of_sock_addr; + char buf[256]; + /* setup standalone */ start_daemon(); - + signal_restart(SIGCHLD, reapchild); - + /* choose port */ - if(argc == 1) + if (argc == 1) listen_port = 3006; - else if(argc >= 2) + else if (argc >= 2) listen_port = atoi(argv[1]); - sprintf(margs, "%s %d ", argv[0],listen_port); + sprintf(margs, "%s %d ", argv[0], listen_port); /* port binding */ xsin.sin_family = AF_INET; msock = bind_port(listen_port); - if(msock<0) { + if (msock < 0) { syslog(LOG_INFO, "mbbsd bind_port failed.\n"); exit(1); } - - initsetproctitle(argc, argv, envp); setproctitle("%s: listening ", margs); - + /* Give up root privileges: no way back from here */ setgid(BBSGID); setuid(BBSUID); chdir(BBSHOME); - + sprintf(buf, "run/mbbsd.%d.pid", listen_port); - if((fp = fopen(buf, "w"))) { + if ((fp = fopen(buf, "w"))) { fprintf(fp, "%d\n", getpid()); fclose(fp); } - /* main loop */ - for(;;) { + for (;;) { len_of_sock_addr = sizeof(xsin); - csock = accept(msock, (struct sockaddr *)&xsin, (socklen_t *)&len_of_sock_addr); + csock = accept(msock, (struct sockaddr *) & xsin, (socklen_t *) & len_of_sock_addr); - if(csock < 0) { - if(errno!=EINTR) sleep(1); + if (csock < 0) { + if (errno != EINTR) + sleep(1); continue; } - - if(check_ban_and_load(csock)) - { + if (check_ban_and_load(csock)) { close(csock); continue; } - #ifdef NO_FORK break; #else - if(fork()==0) + if (fork() == 0) break; else close(csock); #endif - } + } /* here is only child running */ - + setproctitle("%s: ...login wait... ", margs); close(msock); dup2(csock, 0); @@ -1309,35 +1292,34 @@ daemon_login (int argc, char *argv[], char *envp[]) close(1); } -/* check if we're banning login and if the load is too high. - if login is permitted, return 0; - else return -1; - approriate message is output to fd. -*/ -static int check_ban_and_load(int fd) +/* + * check if we're banning login and if the load is too high. if login is + * permitted, return 0; else return -1; approriate message is output to fd. + */ +static int +check_ban_and_load(int fd) { - FILE *fp; - static char buf[256]; - static time_t chkload_time = 0; - static int overload = 0; /* overload or banned, update every 1 sec */ - static int banned = 0; - - if((time(0) - chkload_time) > 1) { + FILE *fp; + static char buf[256]; + static time_t chkload_time = 0; + static int overload = 0; /* overload or banned, update every 1 + * sec */ + static int banned = 0; + + if ((time(0) - chkload_time) > 1) { overload = chkload(buf); - banned = !access(BBSHOME "/BAN",R_OK) && + banned = !access(BBSHOME "/BAN", R_OK) && (strcmp(fromhost, "localhost") != 0); chkload_time = time(0); } - write(fd, buf, strlen(buf)); - if(banned && (fp = fopen(BBSHOME "/BAN", "r"))) { - while(fgets(buf, 256, fp)) + if (banned && (fp = fopen(BBSHOME "/BAN", "r"))) { + while (fgets(buf, 256, fp)) write(fd, buf, strlen(buf)); fclose(fp); } - - if(banned || overload) + if (banned || overload) return -1; #ifdef INSCREEN diff --git a/mbbsd/menu.c b/mbbsd/menu.c index d06481b0..9379c28f 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -1,83 +1,86 @@ -/* $Id: menu.c,v 1.12 2002/06/26 09:49:37 ptt Exp $ */ +/* $Id: menu.c,v 1.13 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" /* help & menu processring */ -static int refscreen = NA; -extern char *boardprefix; +static int refscreen = NA; +extern char *boardprefix; extern struct utmpfile_t *utmpshm; -int egetch() { - int rval; - - while(1) { - rval = igetkey(); - if(talkrequest) { - talkreply(); - refscreen = YEA; - return rval; - } - if(rval != Ctrl('L')) - return rval; - redoscr(); +int +egetch() +{ + int rval; + + while (1) { + rval = igetkey(); + if (talkrequest) { + talkreply(); + refscreen = YEA; + return rval; + } + if (rval != Ctrl('L')) + return rval; + redoscr(); } } extern userec_t cuser; -extern char *fn_board; -extern char board_hidden_status; +extern char *fn_board; +extern char board_hidden_status; -void showtitle(char *title, char *mid) { - char buf[40], numreg[50]; - int nreg, spc = 0, pad, bid; +void +showtitle(char *title, char *mid) +{ + char buf[40], numreg[50]; + int nreg, spc = 0, pad, bid; boardheader_t bh; - static char lastboard[16] = {0}; + static char lastboard[16] = {0}; spc = strlen(mid); - if(title[0] == 0) - title++; + if (title[0] == 0) + title++; #ifdef DEBUG - else{ + else { sprintf(numreg, "\033[41;5m current pid: %6d " TITLE_COLOR, getpid()); mid = numreg; spc = 22; } #else - else if(currutmp->mailalert) { - mid = "\033[41;5m ¶l®t¨Ó«ö¹aÅo " TITLE_COLOR; - spc = 22; - } else if(HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register)/163) > 10) { + else if (currutmp->mailalert) { + mid = "\033[41;5m ¶l®t¨Ó«ö¹aÅo " TITLE_COLOR; + spc = 22; + } else if (HAS_PERM(PERM_SYSOP) && (nreg = dashs(fn_register) / 163) > 10) { sprintf(numreg, "\033[41;5m ¦³%03d/%03d¥¼¼f®Ö " TITLE_COLOR, nreg, (int)dashs("register.new.tmp") / 163); - mid = numreg; - spc = 22; + mid = numreg; + spc = 22; } #endif spc = 66 - strlen(title) - spc - strlen(currboard); - if(spc < 0) - spc = 0; + if (spc < 0) + spc = 0; pad = 1 - (spc & 1); memset(buf, ' ', spc >>= 1); buf[spc] = '\0'; - + clear(); prints(TITLE_COLOR "¡i%s¡j%s\033[33m%s%s%s\033[3%s¡m", - title, buf, mid, buf, " " + pad, - currmode & MODE_SELECT ? "6m¨t¦C" : currmode & MODE_ETC ? "5m¨ä¥L" : - currmode & MODE_DIGEST ? "2m¤åºK" : "7m¬ÝªO"); + title, buf, mid, buf, " " + pad, + currmode & MODE_SELECT ? "6m¨t¦C" : currmode & MODE_ETC ? "5m¨ä¥L" : + currmode & MODE_DIGEST ? "2m¤åºK" : "7m¬ÝªO"); - if( strcmp(currboard, lastboard) ){ /* change board */ - if( currboard[0] != 0 && + if (strcmp(currboard, lastboard)) { /* change board */ + if (currboard[0] != 0 && (bid = getbnum(currboard)) > 0 && - (get_record(fn_board, &bh, sizeof(bh), bid) != -1) ){ + (get_record(fn_board, &bh, sizeof(bh), bid) != -1)) { board_hidden_status = ((bh.brdattr & BRD_HIDE) && (bh.brdattr & BRD_POSTMASK)); strncpy(lastboard, currboard, sizeof(lastboard)); } } - - if( board_hidden_status ) + if (board_hidden_status) prints("\033[32m%s", currboard); else prints("%s", currboard); @@ -89,91 +92,99 @@ void showtitle(char *title, char *mid) { #define FILMROW 11 static unsigned char menu_row = 12; static unsigned char menu_column = 20; -static char mystatus[160]; +static char mystatus[160]; -static int u_movie() { +static int +u_movie() +{ cuser.uflag ^= MOVIE_FLAG; return 0; } -void movie(int i) { - static short history[MAX_HISTORY]; - static char myweek[] = "¤Ñ¤@¤G¤T¥|¤¤»"; - const char *msgs[] = {"Ãö³¬", "¥´¶}", "©Þ±¼", "¨¾¤ô","¦n¤Í"}; - struct tm *ptime = localtime(&now); - int j; - - if((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && - !SHM->Pbusystate && SHM->max_film > 0) { - if(currstat == PSALE) { - i = PSALE; - reload_money(); - } else { - do { - if(!i) - i = 1 + (int)(((float)SHM->max_film * - rand()) / (RAND_MAX + 1.0)); - - for(j = SHM->max_history; j >= 0; j--) - if(i == history[j]) { - i = 0; - break; - } - } while(i == 0); - } - - memcpy(history, &history[1], SHM->max_history * sizeof(short)); - history[SHM->max_history] = j = i; - - if(i == 999) /* Goodbye my friend */ - i = 0; - - move(1, 0); - clrtoline(1 + FILMROW); /* ²M±¼¤W¦¸ªº */ - Jaky_outs(SHM->notes[i], 11); /* ¥u¦L11¦æ´N¦n */ - outs(reset_color); +void +movie(int i) +{ + static short history[MAX_HISTORY]; + static char myweek[] = "¤Ñ¤@¤G¤T¥|¤¤»"; + const char *msgs[] = {"Ãö³¬", "¥´¶}", "©Þ±¼", "¨¾¤ô", "¦n¤Í"}; + struct tm *ptime = localtime(&now); + int j; + + if ((currstat != CLASS) && (cuser.uflag & MOVIE_FLAG) && + !SHM->Pbusystate && SHM->max_film > 0) { + if (currstat == PSALE) { + i = PSALE; + reload_money(); + } else { + do { + if (!i) + i = 1 + (int)(((float)SHM->max_film * + rand()) / (RAND_MAX + 1.0)); + + for (j = SHM->max_history; j >= 0; j--) + if (i == history[j]) { + i = 0; + break; + } + } while (i == 0); + } + + memcpy(history, &history[1], SHM->max_history * sizeof(short)); + history[SHM->max_history] = j = i; + + if (i == 999) /* Goodbye my friend */ + i = 0; + + move(1, 0); + clrtoline(1 + FILMROW); /* ²M±¼¤W¦¸ªº */ + Jaky_outs(SHM->notes[i], 11); /* ¥u¦L11¦æ´N¦n */ + outs(reset_color); } i = ptime->tm_wday << 1; sprintf(mystatus, "\033[34;46m[%d/%d ¬P´Á%c%c %d:%02d]\033[1;33;45m%-14s" - "\033[30;47m ¥Ø«e§{¸Ì¦³ \033[31m%d\033[30m¤H, §Ú¬O\033[31m%-12s" - "\033[30m[¦©¾÷]\033[31m%s\033[0m", - ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], - ptime->tm_hour, ptime->tm_min, currutmp->birth ? - "¥Í¤én½Ð«Èò" : SHM->today_is, - SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); + "\033[30;47m ¥Ø«e§{¸Ì¦³ \033[31m%d\033[30m¤H, §Ú¬O\033[31m%-12s" + "\033[30m[¦©¾÷]\033[31m%s\033[0m", + ptime->tm_mon + 1, ptime->tm_mday, myweek[i], myweek[i + 1], + ptime->tm_hour, ptime->tm_min, currutmp->birth ? + "¥Í¤én½Ð«Èò" : SHM->today_is, + SHM->UTMPnumber, cuser.userid, msgs[currutmp->pager]); outmsg(mystatus); refresh(); } -static int show_menu(commands_t *p) { - register int n = 0; - register char *s; - const char *state[4]={"¥Î¥\\«¬", "¦w¶h«¬", "¦Û©w«¬", "SHUTUP"}; - char buf[80]; +static int +show_menu(commands_t * p) +{ + register int n = 0; + register char *s; + const char *state[4] = {"¥Î¥\\«¬", "¦w¶h«¬", "¦Û©w«¬", "SHUTUP"}; + char buf[80]; movie(currstat); move(menu_row, 0); - while((s = p[n].desc)) { - if(HAS_PERM(p[n].level)) { - sprintf(buf, s + 2, state[cuser.proverb % 4]); - prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], - buf); - } - n++; + while ((s = p[n].desc)) { + if (HAS_PERM(p[n].level)) { + sprintf(buf, s + 2, state[cuser.proverb % 4]); + prints("%*s (\033[1;36m%c\033[0m)%s\n", menu_column, "", s[1], + buf); + } + n++; } return n - 1; } -void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { - int lastcmdptr; - int n, pos, total, i; - int err; - int chkmailbox(); - static char cmd0[LOGIN]; +void +domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) +{ + int lastcmdptr; + int n, pos, total, i; + int err; + int chkmailbox(); + static char cmd0[LOGIN]; - if(cmd0[cmdmode]) - cmd = cmd0[cmdmode]; + if (cmd0[cmdmode]) + cmd = cmd0[cmdmode]; setutmpmode(cmdmode); @@ -185,118 +196,116 @@ void domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) { lastcmdptr = pos = 0; do { - i = -1; - switch(cmd) { - case Ctrl('C'): - cal(); - i = lastcmdptr; - refscreen = YEA; - break; - case Ctrl('I'): - t_idle(); - refscreen = YEA; - i = lastcmdptr; - break; - case Ctrl('N'): - New(); - refscreen = YEA; - i = lastcmdptr; - break; - case Ctrl('A'): - if(mail_man() == FULLUPDATE) - refscreen = YEA; - i = lastcmdptr; - break; - case KEY_DOWN: - i = lastcmdptr; - case KEY_HOME: - case KEY_PGUP: - do { - if(++i > total) - i = 0; - } while(!HAS_PERM(cmdtable[i].level)); - break; - case KEY_END: - case KEY_PGDN: - i = total; - break; - case KEY_UP: - i = lastcmdptr; - do { - if(--i < 0) - i = total; - } while(!HAS_PERM(cmdtable[i].level)); - break; - case KEY_LEFT: - case 'e': - case 'E': - if(cmdmode == MMENU) - cmd = 'G'; - else if((cmdmode == MAIL) && chkmailbox()) - cmd = 'R'; - else - return; - default: - if((cmd == 's' || cmd == 'r') && - (currstat == MMENU || currstat == TMENU || currstat == XMENU)) { - if(cmd == 's') - ReadSelect(); - else - Read(); - refscreen = YEA; - i = lastcmdptr; - break; - } - - if(cmd == '\n' || cmd == '\r' || cmd == KEY_RIGHT) { - move(b_lines, 0); - clrtoeol(); - - currstat = XMODE; - - if((err = (*cmdtable[lastcmdptr].cmdfunc) ()) == QUIT) - return; - currutmp->mode = currstat = cmdmode; - - if(err == XEASY) { - refresh(); - safe_sleep(1); - } else if(err != XEASY + 1 || err == FULLUPDATE) - refscreen = YEA; - - if(err != -1) - cmd = cmdtable[lastcmdptr].desc[0]; - else - cmd = cmdtable[lastcmdptr].desc[1]; - cmd0[cmdmode] = cmdtable[lastcmdptr].desc[0]; - } - - if(cmd >= 'a' && cmd <= 'z') - cmd &= ~0x20; - while(++i <= total) - if(cmdtable[i].desc[1] == cmd) - break; - } - - if(i > total || !HAS_PERM(cmdtable[i].level)) - continue; - - if(refscreen) { - showtitle(cmdtitle, BBSName); - - show_menu(cmdtable); - - outmsg(mystatus); - refscreen = NA; - } - cursor_clear(menu_row + pos, menu_column); - n = pos = -1; - while(++n <= (lastcmdptr = i)) - if(HAS_PERM(cmdtable[n].level)) - pos++; - - cursor_show(menu_row + pos, menu_column); - } while(((cmd = egetch()) != EOF) || refscreen); + i = -1; + switch (cmd) { + case Ctrl('C'): + cal(); + i = lastcmdptr; + refscreen = YEA; + break; + case Ctrl('I'): + t_idle(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('N'): + New(); + refscreen = YEA; + i = lastcmdptr; + break; + case Ctrl('A'): + if (mail_man() == FULLUPDATE) + refscreen = YEA; + i = lastcmdptr; + break; + case KEY_DOWN: + i = lastcmdptr; + case KEY_HOME: + case KEY_PGUP: + do { + if (++i > total) + i = 0; + } while (!HAS_PERM(cmdtable[i].level)); + break; + case KEY_END: + case KEY_PGDN: + i = total; + break; + case KEY_UP: + i = lastcmdptr; + do { + if (--i < 0) + i = total; + } while (!HAS_PERM(cmdtable[i].level)); + break; + case KEY_LEFT: + case 'e': + case 'E': + if (cmdmode == MMENU) + cmd = 'G'; + else if ((cmdmode == MAIL) && chkmailbox()) + cmd = 'R'; + else + return; + default: + if ((cmd == 's' || cmd == 'r') && + (currstat == MMENU || currstat == TMENU || currstat == XMENU)) { + if (cmd == 's') + ReadSelect(); + else + Read(); + refscreen = YEA; + i = lastcmdptr; + break; + } + if (cmd == '\n' || cmd == '\r' || cmd == KEY_RIGHT) { + move(b_lines, 0); + clrtoeol(); + + currstat = XMODE; + + if ((err = (*cmdtable[lastcmdptr].cmdfunc) ()) == QUIT) + return; + currutmp->mode = currstat = cmdmode; + + if (err == XEASY) { + refresh(); + safe_sleep(1); + } else if (err != XEASY + 1 || err == FULLUPDATE) + refscreen = YEA; + + if (err != -1) + cmd = cmdtable[lastcmdptr].desc[0]; + else + cmd = cmdtable[lastcmdptr].desc[1]; + cmd0[cmdmode] = cmdtable[lastcmdptr].desc[0]; + } + if (cmd >= 'a' && cmd <= 'z') + cmd &= ~0x20; + while (++i <= total) + if (cmdtable[i].desc[1] == cmd) + break; + } + + if (i > total || !HAS_PERM(cmdtable[i].level)) + continue; + + if (refscreen) { + showtitle(cmdtitle, BBSName); + + show_menu(cmdtable); + + outmsg(mystatus); + refscreen = NA; + } + cursor_clear(menu_row + pos, menu_column); + n = pos = -1; + while (++n <= (lastcmdptr = i)) + if (HAS_PERM(cmdtable[n].level)) + pos++; + + cursor_show(menu_row + pos, menu_column); + } while (((cmd = egetch()) != EOF) || refscreen); abort_bbs(0); } @@ -573,3 +582,4 @@ int Name_Menu() return 0; } + diff --git a/mbbsd/more.c b/mbbsd/more.c index 1d6b173a..56efeb57 100644 --- a/mbbsd/more.c +++ b/mbbsd/more.c @@ -1,15 +1,15 @@ -/* $Id: more.c,v 1.14 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: more.c,v 1.15 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 #define STR_ANSICODE "[0123456789;," -static int more_base, more_size, more_head; +static int more_base, more_size, more_head; static unsigned char more_pool[MORE_BUFSIZE]; #define MAXPATHLEN 256 -static char *more_help[] = { +static char *more_help[] = { "\0¾\\Ū¤å³¹¥\\¯àÁä¨Ï¥Î»¡©ú", "\01´å¼Ð²¾°Ê¥\\¯àÁä", "(¡ô) ¤W±²¤@¦æ", @@ -34,229 +34,193 @@ static char *more_help[] = { NULL }; -int beep = 0; +int beep = 0; static void -more_goto (int fd, off_t off) -{ - int base = more_base; - - if (off < base || off >= base + more_size) - { - more_base = base = off & (-MORE_WINSIZE); - lseek (fd, base, SEEK_SET); - more_size = read (fd, more_pool, MORE_BUFSIZE); - } - more_head = off - base; -} - -static int -more_readln (int fd, unsigned char *buf) +more_goto(int fd, off_t off) { - int ch; - - unsigned char *data, *tail, *cc; - int len, bytes, in_ansi; - int size, head, ansilen; - - len = bytes = in_ansi = ansilen = 0; - tail = buf + ANSILINELEN - 1; - size = more_size; - head = more_head; - data = &more_pool[head]; - - do - { - if (head >= size) - { - more_base += size; - data = more_pool; - more_size = size = read (fd, data, MORE_BUFSIZE); - if (size == 0) - break; - head = 0; - } + int base = more_base; - ch = *data++; - head++; - bytes++; - if (ch == '\n') - { - break; - } - if (ch == '\t') - { - do - { - *buf++ = ' '; - } - while ((++len & 7) && len < 80); - } - else if (ch == '\033') - { - if (atoi ((char *)(data + 1)) > 47) - { - if ((cc = (unsigned char *)strchr ((char *)(data + 1), 'm')) != NULL) - { - ch = cc - data + 1; - - data += ch; - head += ch; - bytes += ch; - } - } - else - { - if (showansi) - *buf++ = ch; - in_ansi = 1; - } - } - else if (in_ansi) - { - if (showansi) - *buf++ = ch; - if (!strchr (STR_ANSICODE, ch)) - in_ansi = 0; - } - else if (isprint2 (ch)) - { - len++; - *buf++ = ch; + if (off < base || off >= base + more_size) { + more_base = base = off & (-MORE_WINSIZE); + lseek(fd, base, SEEK_SET); + more_size = read(fd, more_pool, MORE_BUFSIZE); } - } - while (len < 80 && buf < tail); - *buf = '\0'; - more_head = head; - return bytes; + more_head = off - base; } -/* not used -static int readln(FILE *fp, char *buf) { - register int ch, i, len, bytes, in_ansi; - - len = bytes = in_ansi = i = 0; - while(len < 80 && i < ANSILINELEN && (ch = getc(fp)) != EOF) { +static int +more_readln(int fd, unsigned char *buf) +{ + int ch; + + unsigned char *data, *tail, *cc; + int len, bytes, in_ansi; + int size, head, ansilen; + + len = bytes = in_ansi = ansilen = 0; + tail = buf + ANSILINELEN - 1; + size = more_size; + head = more_head; + data = &more_pool[head]; + + do { + if (head >= size) { + more_base += size; + data = more_pool; + more_size = size = read(fd, data, MORE_BUFSIZE); + if (size == 0) + break; + head = 0; + } + ch = *data++; + head++; bytes++; - if(ch == '\n') + if (ch == '\n') { break; - else if(ch == '\t') + } + if (ch == '\t') { do { - buf[i++] = ' '; - } while((++len & 7) && len < 80); - else if(ch == '\a') - beep = 1; - else if(ch == '\033') { - if(showansi) - buf[i++] = ch; - in_ansi = 1; - } else if(in_ansi) { - if(showansi) - buf[i++] = ch; - if(!strchr("[0123456789;,", ch)) + *buf++ = ' '; + } + while ((++len & 7) && len < 80); + } else if (ch == '\033') { + if (atoi((char *)(data + 1)) > 47) { + if ((cc = (unsigned char *)strchr((char *)(data + 1), 'm')) != NULL) { + ch = cc - data + 1; + + data += ch; + head += ch; + bytes += ch; + } + } else { + if (showansi) + *buf++ = ch; + in_ansi = 1; + } + } else if (in_ansi) { + if (showansi) + *buf++ = ch; + if (!strchr(STR_ANSICODE, ch)) in_ansi = 0; - } else if(isprint2(ch)) { + } else if (isprint2(ch)) { len++; - buf[i++] = ch; + *buf++ = ch; } } - buf[i] = '\0'; + while (len < 80 && buf < tail); + *buf = '\0'; + more_head = head; return bytes; } -*/ - -static int more_web(char *fpath, int promptend); -int more(char *fpath, int promptend) { - static char *head[4] = {"§@ªÌ", "¼ÐÃD", "®É¶¡" ,"Âà«H"}; - char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; - struct stat st; - -/* rocker */ - //FILE *fp; - int fd, fsize; - - unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; - int line, ch, viewed, pos, numbytes; - int header = 0; - int local = 0; - char search_char0=0; - static char search_str[81]=""; - typedef char* (*FPTR)(); - static FPTR fptr; - int searching = 0; - int scrollup = 0; - char *printcolor[3]= {"44","33;45","0;34;46"}, color =0; - char *http[80]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, - NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; + +/* + * not used static int readln(FILE *fp, char *buf) { register int ch, i, len, + * bytes, in_ansi; + * + * len = bytes = in_ansi = i = 0; while(len < 80 && i < ANSILINELEN && (ch = + * getc(fp)) != EOF) { bytes++; if(ch == '\n') break; else if(ch == '\t') do + * { buf[i++] = ' '; } while((++len & 7) && len < 80); else if(ch == '\a') + * beep = 1; else if(ch == '\033') { if(showansi) buf[i++] = ch; in_ansi = 1; + * } else if(in_ansi) { if(showansi) buf[i++] = ch; + * if(!strchr("[0123456789;,", ch)) in_ansi = 0; } else if(isprint2(ch)) { + * len++; buf[i++] = ch; } } buf[i] = '\0'; return bytes; } + */ + +static int more_web(char *fpath, int promptend); +int +more(char *fpath, int promptend) +{ + static char *head[4] = {"§@ªÌ", "¼ÐÃD", "®É¶¡", "Âà«H"}; + char *ptr, *word = NULL, buf[ANSILINELEN + 1], *ch1; + struct stat st; + + /* rocker */ + //FILE * fp; + int fd, fsize; + + unsigned int pagebreak[MAX_PAGES], pageno, lino = 0; + int line, ch, viewed, pos, numbytes; + int header = 0; + int local = 0; + char search_char0 = 0; + static char search_str[81] = ""; + typedef char *(*FPTR) (); + static FPTR fptr; + int searching = 0; + int scrollup = 0; + char *printcolor[3] = {"44", "33;45", "0;34;46"}, color = 0; + char *http[80] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; /* Ptt */ - char pagemode = 0; - char pagecount = 0; + char pagemode = 0; + char pagecount = 0; memset(pagebreak, 0, sizeof(pagebreak)); - if(*search_str) + if (*search_str) search_char0 = *search_str; *search_str = 0; #ifdef MDCACHE fd = mdcacheopen(fpath); -#else - fd = open (fpath, O_RDONLY, 0600); +#else + fd = open(fpath, O_RDONLY, 0600); #endif - if (fd < 0) return -1; - - if(fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR (st.st_mode)) - { - close(fd); //Ptt + if (fd < 0) return -1; - } + + if (fstat(fd, &st) || ((fsize = st.st_size) <= 0) || S_ISDIR(st.st_mode)) { + close(fd); + //Ptt + return -1; + } pagebreak[0] = pageno = viewed = line = pos = 0; clear(); -/* rocker */ + /* rocker */ - more_base = more_head = more_size = 0; - - while((numbytes = more_readln(fd, (unsigned char *)buf)) || (line == t_lines)) { - if(scrollup) { + more_base = more_head = more_size = 0; + + while ((numbytes = more_readln(fd, (unsigned char *)buf)) || (line == t_lines)) { + if (scrollup) { rscroll(); move(0, 0); } - if(numbytes) { /* ¤@¯ë¸ê®Æ³B²z */ - if(!viewed) { /* begin of file */ - if(showansi) { /* header processing */ - if(!strncmp(buf, str_author1, LEN_AUTHOR1)) { + if (numbytes) { /* ¤@¯ë¸ê®Æ³B²z */ + if (!viewed) { /* begin of file */ + if (showansi) { /* header processing */ + if (!strncmp(buf, str_author1, LEN_AUTHOR1)) { line = 3; word = buf + LEN_AUTHOR1; local = 1; - } else if(!strncmp(buf, str_author2, LEN_AUTHOR2)) { + } else if (!strncmp(buf, str_author2, LEN_AUTHOR2)) { line = 4; word = buf + LEN_AUTHOR2; } - - while(pos < line) { - if(!pos && ((ptr = strstr(word, str_post1)) || - (ptr = strstr(word, str_post2)))) { + while (pos < line) { + if (!pos && ((ptr = strstr(word, str_post1)) || + (ptr = strstr(word, str_post2)))) { ptr[-1] = '\0'; prints("\033[47;34m %s \033[44;37m%-53.53s" - "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", + "\033[47;34m %.4s \033[44;37m%-13s\033[m\n", head[0], word, ptr, ptr + 5); } else if (pos < line) prints("\033[47;34m %s \033[44;37m%-72.72s" "\033[m\n", head[pos], word); - + viewed += numbytes; numbytes = more_readln(fd, (unsigned char *)buf); - - /* ²Ä¤@¦æ¤Óªø¤F */ - if(!pos && viewed > 79) { - /* ²Ä¤G¦æ¤£¬O [¼Ð....] */ - if(memcmp( buf, head[1], 2)) { + + /* ²Ä¤@¦æ¤Óªø¤F */ + if (!pos && viewed > 79) { + /* ²Ä¤G¦æ¤£¬O [¼Ð....] */ + if (memcmp(buf, head[1], 2)) { /* Ū¤U¤@¦æ¶i¨Ó³B²z */ viewed += numbytes; numbytes = more_readln(fd, (unsigned char *)buf); @@ -264,91 +228,87 @@ int more(char *fpath, int promptend) { } pos++; } - if(pos) { + if (pos) { header = 1; - + prints("\033[36m%s\033[m\n", msg_seperator); - ++line; ++pos; + ++line; + ++pos; } } lino = pos; word = NULL; } - /* ¡°³B²z¤Þ¥ÎªÌ & ¤Þ¨¥ */ - if((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) + if ((buf[1] == ' ') && (buf[0] == ':' || buf[0] == '>')) word = "\033[36m"; - else if(!strncmp(buf, "¡°", 2) || !strncmp(buf, "==>", 3)) + else if (!strncmp(buf, "¡°", 2) || !strncmp(buf, "==>", 3)) word = "\033[32m"; - + ch1 = buf; - while(1) { - int i; - char e,*ch2; - - if((ch2 = strstr(ch1, "http://"))) - ; - else if((ch2 = strstr(ch1,"gopher://"))) - ; - else if((ch2 = strstr(ch1,"mailto:"))) - ; + while (1) { + int i; + char e, *ch2; + + if ((ch2 = strstr(ch1, "http://"))); + else if ((ch2 = strstr(ch1, "gopher://"))); + else if ((ch2 = strstr(ch1, "mailto:"))); else break; - for(e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && - ch2[(int)e] != '\0' && ch2[(int)e] != '"' && - ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); - for(i = 0; http[i] && i < 80; i++) - if(!strncmp(http[i], ch2, e) && http[(int)e] == 0) + for (e = 0; ch2[(int)e] != ' ' && ch2[(int)e] != '\n' && + ch2[(int)e] != '\0' && ch2[(int)e] != '"' && + ch2[(int)e] != ';' && ch2[(int)e] != ']'; e++); + for (i = 0; http[i] && i < 80; i++) + if (!strncmp(http[i], ch2, e) && http[(int)e] == 0) break; - if(!http[i]) { + if (!http[i]) { http[i] = (char *)malloc(e + 1); strncpy(http[i], ch2, e); http[i][(int)e] = 0; pagecount++; - } + } ch1 = &ch2[7]; } - if(word) + if (word) outs(word); { - char msg[500], *pos; - - if(*search_str && (pos = fptr(buf, search_str))) { - char SearchStr[81]; - char buf1[100], *pos1; - + char msg[500], *pos; + + if (*search_str && (pos = fptr(buf, search_str))) { + char SearchStr[81]; + char buf1[100], *pos1; + strncpy(SearchStr, pos, strlen(search_str)); SearchStr[strlen(search_str)] = 0; searching = 0; sprintf(msg, "%.*s\033[7m%s\033[m", pos - buf, buf, SearchStr); - while((pos = fptr(pos1 = pos + strlen(search_str), - search_str))) { + while ((pos = fptr(pos1 = pos + strlen(search_str), + search_str))) { sprintf(buf1, "%.*s\033[7m%s\033[m", pos - pos1, pos1, SearchStr); strcat(msg, buf1); } strcat(msg, pos1); - outs(Ptt_prints(msg,NO_RELOAD)); + outs(Ptt_prints(msg, NO_RELOAD)); } else - outs(Ptt_prints(buf,NO_RELOAD)); + outs(Ptt_prints(buf, NO_RELOAD)); } - if(word) { + if (word) { outs("\033[m"); word = NULL; } outch('\n'); - - if(beep) { + + if (beep) { bell(); beep = 0; } - - if(line < b_lines) /* ¤@¯ë¸ê®ÆŪ¨ú */ + if (line < b_lines) /* ¤@¯ë¸ê®ÆŪ¨ú */ line++; - - if(line == b_lines && searching == -1) { - if(pageno > 0) + + if (line == b_lines && searching == -1) { + if (pageno > 0) more_goto(fd, viewed = pagebreak[--pageno]); else searching = 0; @@ -356,104 +316,102 @@ int more(char *fpath, int promptend) { clear(); continue; } - - if(scrollup) { + if (scrollup) { move(line = b_lines, 0); clrtoeol(); - for(pos = 1; pos < b_lines; pos++) + for (pos = 1; pos < b_lines; pos++) viewed += more_readln(fd, (unsigned char *)buf); - } else if(pos == b_lines) /* ±²°Ê¿Ã¹õ */ + } else if (pos == b_lines) /* ±²°Ê¿Ã¹õ */ scroll(); else pos++; - if(!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { + if (!scrollup && ++lino >= b_lines && pageno < MAX_PAGES - 1) { pagebreak[++pageno] = viewed; lino = 1; } - - if(scrollup) { + if (scrollup) { lino = scrollup; scrollup = 0; } - viewed += numbytes; /* ²ÖpŪ¹L¸ê®Æ */ + viewed += numbytes; /* ²ÖpŪ¹L¸ê®Æ */ } else - line = b_lines; /* end of END */ - - if(promptend && - ((!searching && line == b_lines) || viewed == fsize)) { + line = b_lines; /* end of END */ + + if (promptend && + ((!searching && line == b_lines) || viewed == fsize)) { /* Kaede è¦n 100% ®É¤£°± */ move(b_lines, 0); - if(viewed == fsize) { - if(searching == 1) + if (viewed == fsize) { + if (searching == 1) searching = 0; color = 0; - } else if(pageno == 1 && lino == 1) { - if(searching == -1) + } else if (pageno == 1 && lino == 1) { + if (searching == -1) searching = 0; color = 1; } else color = 2; prints("\033[m\033[%sm ÂsÄý P.%d(%d%%) %s %-30.30s%s", - printcolor[(int)color], - pageno, + printcolor[(int)color], + pageno, (int)((viewed * 100) / fsize), pagemode ? "\033[30;47m" : "\033[31;47m", - pagemode ? http[pagemode-1] : "(h)\033[30m¨D§U \033[31m¡÷¡õ[PgUp][", + pagemode ? http[pagemode - 1] : "(h)\033[30m¨D§U \033[31m¡÷¡õ[PgUp][", pagemode ? "\033[31m[TAB]\033[30m¤Á´« \033[31m[Enter]\033[30m¿ï©w \033[31m¡ö\033[30m©ñ±ó\033[m" : "PgDn][Home][End]\033[30m´å¼Ð²¾°Ê \033[31m¡ö[q]\033[30mµ²§ô \033[m"); - - - while(line == b_lines || (line > 0 && viewed == fsize)) { - switch((ch = egetch())) { + + + while (line == b_lines || (line > 0 && viewed == fsize)) { + switch ((ch = egetch())) { case ':': - { - char buf[10]; - int i = 0; - - getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO); - sscanf(buf, "%d", &i); - if(0 < i && i < MAX_PAGES && (i == 1 || pagebreak[i - 1])) - pageno = i - 1; - else if(pageno) - pageno--; - lino = line = 0; - break; - } + { + char buf[10]; + int i = 0; + + getdata(b_lines - 1, 0, "Goto Page: ", buf, 5, DOECHO); + sscanf(buf, "%d", &i); + if (0 < i && i < MAX_PAGES && (i == 1 || pagebreak[i - 1])) + pageno = i - 1; + else if (pageno) + pageno--; + lino = line = 0; + break; + } case '/': - { - char ans[4] = "n"; - - *search_str = search_char0; - getdata_buf(b_lines - 1, 0,"[·j´M]ÃöÁä¦r:", search_str, - 40, DOECHO); - if(*search_str) { - searching = 1; - if(getdata(b_lines - 1, 0, "°Ï¤À¤j¤p¼g(Y/N/Q)? [N] ", + { + char ans[4] = "n"; + + *search_str = search_char0; + getdata_buf(b_lines - 1, 0, "[·j´M]ÃöÁä¦r:", search_str, + 40, DOECHO); + if (*search_str) { + searching = 1; + if (getdata(b_lines - 1, 0, "°Ï¤À¤j¤p¼g(Y/N/Q)? [N] ", ans, sizeof(ans), LCECHO) && *ans == 'y') - fptr = strstr; - else - fptr = strcasestr; + fptr = strstr; + else + fptr = strcasestr; + } + if (*ans == 'q') + searching = 0; + if (pageno) + pageno--; + lino = line = 0; + break; } - if(*ans == 'q') - searching = 0; - if(pageno) - pageno--; - lino = line = 0; - break; - } case 'n': - if(*search_str) { + if (*search_str) { searching = 1; - if(pageno) + if (pageno) pageno--; lino = line = 0; } break; case 'N': - if(*search_str) { + if (*search_str) { searching = -1; - if(pageno) + if (pageno) pageno--; lino = line = 0; } @@ -479,10 +437,10 @@ int more(char *fpath, int promptend) { close(fd); return 12; case KEY_LEFT: - if(pagemode) { + if (pagemode) { pagemode = 0; *search_str = 0; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -498,13 +456,13 @@ int more(char *fpath, int promptend) { case 'f': close(fd); return 3; - case ']': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ + case ']': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ close(fd); return 4; - case '[': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ + case '[': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ close(fd); return 2; - case '=': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ + case '=': /* Kaede ¬°¤F¥DÃD¾\Ū¤è«K */ close(fd); return 5; case Ctrl('F'): @@ -512,21 +470,21 @@ int more(char *fpath, int promptend) { line = 1; break; case 't': - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 4; } line = 1; break; case ' ': - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 3; } line = 1; break; case KEY_RIGHT: - if(viewed == fsize) { + if (viewed == fsize) { close(fd); return 0; } @@ -534,18 +492,18 @@ int more(char *fpath, int promptend) { break; case '\r': case '\n': - if(pagemode) { - more_web(http[pagemode-1],YEA); + if (pagemode) { + more_web(http[pagemode - 1], YEA); pagemode = 0; *search_str = 0; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; } case KEY_DOWN: - if(viewed == fsize || - (promptend == 2 && (ch == '\r' || ch == '\n'))) { + if (viewed == fsize || + (promptend == 2 && (ch == '\r' || ch == '\n'))) { close(fd); return 3; } @@ -566,12 +524,12 @@ int more(char *fpath, int promptend) { case '?': /* Kaede Buggy ... */ show_help(more_help); - if(pageno) + if (pageno) pageno--; lino = line = 0; break; case 'E': - if(HAS_PERM(PERM_SYSOP) && strcmp(fpath, "etc/ve.hlp")) { + if (HAS_PERM(PERM_SYSOP) && strcmp(fpath, "etc/ve.hlp")) { close(fd); vedit(fpath, NA, NULL); return 0; @@ -579,7 +537,7 @@ int more(char *fpath, int promptend) { break; case Ctrl('C'): cal(); - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -587,26 +545,26 @@ int more(char *fpath, int promptend) { case Ctrl('T'): getdata(b_lines - 2, 0, "§â³o½g¤å³¹¦¬¤J¨ì¼È¦sÀÉ¡H[y/N] ", buf, 4, LCECHO); - if(buf[0] == 'y') { - char tmpbuf[128]; - + if (buf[0] == 'y') { + char tmpbuf[128]; + setuserfile(tmpbuf, ask_tmpbuf(b_lines - 1)); sprintf(buf, "cp -f %s %s", fpath, tmpbuf); system(buf); } - if(pageno) + if (pageno) pageno--; lino = line = 0; break; #if 0 case Ctrl('I'): - if(!pagecount) + if (!pagecount) break; pagemode = (pagemode % pagecount) + 1; - strncpy(search_str,http[pagemode-1],80); - search_str[80] =0; + strncpy(search_str, http[pagemode - 1], 80); + search_str[80] = 0; fptr = strstr; - if(pageno) + if (pageno) pageno--; lino = line = 0; break; @@ -616,23 +574,23 @@ int more(char *fpath, int promptend) { break; case Ctrl('B'): case KEY_PGUP: - if(pageno > 1) { - if(lino < 2) + if (pageno > 1) { + if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; - } else if(pageno && lino > 1) + } else if (pageno && lino > 1) pageno = line = 0; break; case Ctrl('H'): - if(pageno > 1) { - if(lino < 2) + if (pageno > 1) { + if (lino < 2) pageno -= 2; else pageno--; lino = line = 0; - } else if(pageno && lino > 1) + } else if (pageno && lino > 1) pageno = line = 0; else { close(fd); @@ -640,50 +598,50 @@ int more(char *fpath, int promptend) { } } } - - if(line > 0) { + + if (line > 0) { move(b_lines, 0); clrtoeol(); refresh(); - } else if(line < 0) { /* Line scroll up */ - if(pageno <= 1) { - if(lino == 1 || !pageno) { + } else if (line < 0) { /* Line scroll up */ + if (pageno <= 1) { + if (lino == 1 || !pageno) { close(fd); return 1; } - if(header && lino <= 5) { + if (header && lino <= 5) { more_goto(fd, viewed = pagebreak[scrollup = lino = - pageno = 0] = 0); + pageno = 0] = 0); clear(); } } - if(pageno && lino > 1 + local) { - line = (lino - 2) - local; - if(pageno > 1 && viewed == fsize) + if (pageno && lino > 1 + local) { + line = (lino - 2) - local; + if (pageno > 1 && viewed == fsize) line += local; scrollup = lino - 1; more_goto(fd, viewed = pagebreak[pageno - 1]); - while(line--) + while (line--) viewed += more_readln(fd, (unsigned char *)buf); - } else if(pageno > 1) { + } else if (pageno > 1) { scrollup = b_lines - 1; line = (b_lines - 2) - local; more_goto(fd, viewed = pagebreak[--pageno - 1]); - while(line--) + while (line--) viewed += more_readln(fd, (unsigned char *)buf); } line = pos = 0; } else { pos = 0; - more_goto (fd, viewed = pagebreak[pageno]); - move(0,0); + more_goto(fd, viewed = pagebreak[pageno]); + move(0, 0); clear(); } } } close(fd); - if(promptend) { + if (promptend) { pressanykey(); clear(); } else @@ -691,54 +649,56 @@ int more(char *fpath, int promptend) { return 0; } -static int more_web(char *fpath, int promptend) { - char *ch, *ch1 = NULL; - char *hostname = fpath,userfile[MAXPATHLEN],file[MAXPATHLEN]="/"; - char genbuf[200]; - time_t dtime; +static int +more_web(char *fpath, int promptend) +{ + char *ch, *ch1 = NULL; + char *hostname = fpath, userfile[MAXPATHLEN], file[MAXPATHLEN] = "/"; + char genbuf[200]; + time_t dtime; #if !defined(USE_LYNX) && defined(USE_PROXY) - int a; - FILE *fp; + int a; + FILE *fp; struct hostent *h; struct sockaddr_in sin; #endif - if((ch = strstr(fpath, "mailto:"))) { - if(!HAS_PERM(PERM_LOGINOK)) { - move(b_lines - 1,0); + if ((ch = strstr(fpath, "mailto:"))) { + if (!HAS_PERM(PERM_LOGINOK)) { + move(b_lines - 1, 0); outs("\033[41m ±zªºÅv¤£¨¬µLªk¨Ï¥Îinternet mail... \033[m"); refresh(); return 0; } - if(!invalidaddr(&ch[7]) && - getdata(b_lines - 1, 0, "[±H«H]¥DÃD¡G", genbuf, 40, DOECHO)) + if (!invalidaddr(&ch[7]) && + getdata(b_lines - 1, 0, "[±H«H]¥DÃD¡G", genbuf, 40, DOECHO)) do_send(&ch[7], genbuf); else { - move(b_lines - 1,0); + move(b_lines - 1, 0); outs("\033[41m ¦¬«H¤Hemail ©Î ¼ÐÃD ¦³»~... \033[m"); refresh(); } - return 0; + return 0; } - if((ch = strstr(fpath, "gopher://"))) { - item_t item; + if ((ch = strstr(fpath, "gopher://"))) { + item_t item; strcpy(item.X.G.server, &ch[9]); strcpy(item.X.G.path, "1/"); item.X.G.port = 70; - gem(fpath , &item, 0); - return 0; + gem(fpath, &item, 0); + return 0; } - if((ch = strstr(fpath, "http://"))) - hostname=&ch[7]; - if((ch = strchr(hostname, '/'))) { - *ch = 0; - if(&ch1[1]) - strcat(file,&ch[1]); + if ((ch = strstr(fpath, "http://"))) + hostname = &ch[7]; + if ((ch = strchr(hostname, '/'))) { + *ch = 0; + if (&ch1[1]) + strcat(file, &ch[1]); } - if(file[strlen(file) - 1] == '/') - strcat(file,"index.html"); - move(b_lines-1,0); + if (file[strlen(file) - 1] == '/') + strcat(file, "index.html"); + move(b_lines - 1, 0); clrtoeol(); #ifdef USE_PROXY sprintf(genbuf, "\033[33;44m ¥¿¦b³s©¹%s.(proxy:%s).....½ÐµyÔ....\033[m", @@ -750,65 +710,65 @@ static int more_web(char *fpath, int promptend) { refresh(); #ifdef LOCAL_PROXY -/* ¥ý§ä local disk ªº proxy */ - dtime=now; - sprintf(userfile,"hproxy/%s%s",hostname,file); - if(dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 - && more(userfile,promptend)) { - return 1; + /* ¥ý§ä local disk ªº proxy */ + dtime = now; + sprintf(userfile, "hproxy/%s%s", hostname, file); + if (dashf(userfile) && (dtime - dasht(userfile)) < HPROXYDAY * 24 * 60 + && more(userfile, promptend)) { + return 1; } - ch=userfile - 1; - while((ch1 = strchr(ch + 1,'/'))) { - *ch1 = 0; - if(!dashd(ch)) - mkdir(ch+1,0755); - chdir(ch+1); - *ch1 = '/'; - ch = ch1; + ch = userfile - 1; + while ((ch1 = strchr(ch + 1, '/'))) { + *ch1 = 0; + if (!dashd(ch)) + mkdir(ch + 1, 0755); + chdir(ch + 1); + *ch1 = '/'; + ch = ch1; } chdir(BBSHOME); #endif #ifndef USE_LYNX #ifdef USE_PROXY - if(!(h = gethostbyname(PROXYSERVER))) { + if (!(h = gethostbyname(PROXYSERVER))) { outs("\033[33;44m §ä¤£¨ì³oÓproxy server!..\033[m"); refresh(); return; } - ()memset((char *)&sin, 0, sizeof(sin)); + () memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - if(h == NULL) + if (h == NULL) sin.sin_addr.s_addr = inet_addr(PROXYSERVER); else - ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - sin.sin_port = htons((ushort)PROXYPORT); /* HTTP port */ + sin.sin_port = htons((ushort) PROXYPORT); /* HTTP port */ a = socket(AF_INET, SOCK_STREAM, 0); - if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { outs("\033[1;44m ³s±µ¨ìproxy¨ü¨ì©Úµ´ ! \033[m"); refresh(); return; } - sprintf(genbuf,"GET http://%s/%s HTTP/1.1\n",hostname,file); + sprintf(genbuf, "GET http://%s/%s HTTP/1.1\n", hostname, file); #else - if(!(h = gethostbyname(hostname))) { + if (!(h = gethostbyname(hostname))) { outs("\033[33;44m §ä¤£¨ì³oÓserver!..\033[m"); refresh(); return; } - ()memset((char *) &sin, 0, sizeof(sin)); + () memset((char *)&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - - if(h == NULL) + + if (h == NULL) sin.sin_addr.s_addr = inet_addr(hostname); else - ()memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); - - sin.sin_port = htons((ushort)80); + () memcpy(&sin.sin_addr.s_addr, h->h_addr, h->h_length); + + sin.sin_port = htons((ushort) 80); a = socket(AF_INET, SOCK_STREAM, 0); - if((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { + if ((connect(a, (struct sockaddr *) & sin, sizeof sin)) < 0) { outs("\033[1;44m ³s±µ¨ü¨ì©Úµ´ ! \033[m"); refresh(); return; @@ -816,7 +776,7 @@ static int more_web(char *fpath, int promptend) { sprintf(genbuf, "GET %s\n", file); #endif - for(i = strlen(file); file[i - 1] != '/' && i > 0 ; i--); + for (i = strlen(file); file[i - 1] != '/' && i > 0; i--); file[i] = 0; i = strlen(genbuf); @@ -826,70 +786,70 @@ static int more_web(char *fpath, int promptend) { #define ISPRINT 002 #define PRE 004 #define CENTER 010 - if((fp = fopen(userfile,"w"))) { - int flag = 2, c; - char path[MAXPATHLEN]; - unsigned char j, k; + if ((fp = fopen(userfile, "w"))) { + int flag = 2, c; + char path[MAXPATHLEN]; + unsigned char j, k; - while((i = read(a,genbuf,200))) { - if(i < 0) + while ((i = read(a, genbuf, 200))) { + if (i < 0) return; - genbuf[i]=0; - - for(j = 0, k = 0; genbuf[j] && j < i; j++) { - if((flag & ISPRINT) && genbuf[j] == '<') + genbuf[i] = 0; + + for (j = 0, k = 0; genbuf[j] && j < i; j++) { + if ((flag & ISPRINT) && genbuf[j] == '<') flag |= BLANK; - else if((flag & ISPRINT) && genbuf[j] == '>') + else if ((flag & ISPRINT) && genbuf[j] == '>') flag &= ~BLANK; else { - if(!(flag & BLANK)) { - if(j != k && (genbuf[j] != '\n' || flag & PRE)) + if (!(flag & BLANK)) { + if (j != k && (genbuf[j] != '\n' || flag & PRE)) genbuf[k++] = genbuf[j]; } else { - switch(char_lower(genbuf[j])) { + switch (char_lower(genbuf[j])) { case 'a': break; case 'b': - if(genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') + if (genbuf[j + 1] == 'r' && genbuf[j + 2] == '>') genbuf[k++] = '\n'; break; case 'h': - if(genbuf[j + 1] == 'r' && - (genbuf[j + 2] == '>' || - genbuf[j + 2] == 's')) { + if (genbuf[j + 1] == 'r' && + (genbuf[j + 2] == '>' || + genbuf[j + 2] == 's')) { strncpy(&genbuf[k], "\n--\n", 4); k += 4; } break; case 'l': - if(genbuf[j + 1] == 'i' && genbuf[j + 2]=='>') { + if (genbuf[j + 1] == 'i' && genbuf[j + 2] == '>') { strncpy(&genbuf[k], "\n¡· ", 4); k += 4; } break; case 'p': - if(genbuf[j + 1]=='>') { + if (genbuf[j + 1] == '>') { genbuf[k++] = '\n'; genbuf[k++] = '\n'; - } else if(genbuf[j + 1] == 'r' && - genbuf[j + 2] == 'e') + } else if (genbuf[j + 1] == 'r' && + genbuf[j + 2] == 'e') flag ^= PRE; break; case 't': - if(genbuf[j + 1] == 'd' && genbuf[j + 2]=='>') { + if (genbuf[j + 1] == 'd' && genbuf[j + 2] == '>') { strncpy(&genbuf[k], "\n-\n", 3); k += 3; } break; } } - if((genbuf[j] & 0x80) && (flag & ISPRINT)) + if ((genbuf[j] & 0x80) && (flag & ISPRINT)) flag &= ~ISPRINT; else flag |= ISPRINT; - } + } } - genbuf[k]=0; + genbuf[k] = 0; fputs(genbuf, fp); } fclose(fp); @@ -897,7 +857,7 @@ static int more_web(char *fpath, int promptend) { return more(userfile, promptend); } return 0; -#else /* use lynx dump */ +#else /* use lynx dump */ sprintf(genbuf, "lynx -dump http://%s%s > %s", hostname, file, userfile); system(genbuf); return more(userfile, promptend); diff --git a/mbbsd/name.c b/mbbsd/name.c index af32daa5..d87d8175 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -1,17 +1,19 @@ -/* $Id: name.c,v 1.9 2002/07/02 13:01:43 in2 Exp $ */ +/* $Id: name.c,v 1.10 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -static word_t *current = NULL; -static char *msg_more = "\033[7m-- More --\033[m"; +static word_t *current = NULL; +static char *msg_more = "\033[7m-- More --\033[m"; -typedef char (*arrptr)[]; +typedef char (*arrptr)[]; /* name complete for user ID */ -static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, - int count) { - int len, max = 0; - - while(count-- > 0 && morenum < cwnum) { +static int +UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, + int count) +{ + int len, max = 0; + + while (count-- > 0 && morenum < cwnum) { len = strlen(cwlist[morenum++]); if (len > max) max = len; @@ -19,66 +21,76 @@ static int UserMaxLen(char cwlist[][IDLEN + 1], int cwnum, int morenum, return max; } -static int UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], - int cwnum, int key, int pos) { - int key2, num = 0; - int n, ch; +static int +UserSubArray(char cwbuf[][IDLEN + 1], char cwlist[][IDLEN + 1], + int cwnum, int key, int pos) +{ + int key2, num = 0; + int n, ch; key = chartoupper(key); - if(key >= 'A' && key <= 'Z') + if (key >= 'A' && key <= 'Z') key2 = key | 0x20; else - key2 = key ; + key2 = key; - for(n = 0; n < cwnum; n++) { + for (n = 0; n < cwnum; n++) { ch = cwlist[n][pos]; - if(ch == key || ch == key2) + if (ch == key || ch == key2) strcpy(cwbuf[num++], cwlist[n]); } return num; } -static void FreeNameList() { - word_t *p, *temp; - - for(p = toplev; p; p = temp) { +static void +FreeNameList() +{ + word_t *p, *temp; + + for (p = toplev; p; p = temp) { temp = p->next; free(p->word); free(p); } } -void CreateNameList() { - if(toplev) +void +CreateNameList() +{ + if (toplev) FreeNameList(); toplev = current = NULL; } -void AddNameList(char *name) { - word_t *node; - - node = (word_t *)malloc(sizeof(word_t)); +void +AddNameList(char *name) +{ + word_t *node; + + node = (word_t *) malloc(sizeof(word_t)); node->next = NULL; node->word = (char *)malloc(strlen(name) + 1); strcpy(node->word, name); - if(toplev) + if (toplev) current = current->next = node; else current = toplev = node; } -int RemoveNameList(char *name) { - word_t *curr, *prev = NULL; +int +RemoveNameList(char *name) +{ + word_t *curr, *prev = NULL; - for(curr = toplev; curr; curr = curr->next) { - if(!strcmp(curr->word, name)) { - if(prev == NULL) + for (curr = toplev; curr; curr = curr->next) { + if (!strcmp(curr->word, name)) { + if (prev == NULL) toplev = curr->next; else prev->next = curr->next; - if(curr == current) + if (curr == current) current = prev; free(curr->word); free(curr); @@ -89,26 +101,30 @@ int RemoveNameList(char *name) { return 0; } -int InNameList(char *name) { - word_t *p; +int +InNameList(char *name) +{ + word_t *p; - for(p = toplev; p; p = p->next) - if(!strcmp(p->word, name)) + for (p = toplev; p; p = p->next) + if (!strcmp(p->word, name)) return 1; return 0; } -void ShowNameList(int row, int column, char *prompt) { - word_t *p; - +void +ShowNameList(int row, int column, char *prompt) +{ + word_t *p; + move(row, column); clrtobot(); outs(prompt); column = 80; - for(p = toplev; p; p = p->next) { + for (p = toplev; p; p = p->next) { row = strlen(p->word) + 1; - if(column + row > 76) { + if (column + row > 76) { column = row; outc('\n'); } else { @@ -119,14 +135,16 @@ void ShowNameList(int row, int column, char *prompt) { } } -void ToggleNameList(int *reciper, char *listfile, char *msg) { - FILE *fp; - char genbuf[200]; +void +ToggleNameList(int *reciper, char *listfile, char *msg) +{ + FILE *fp; + char genbuf[200]; - if((fp = fopen(listfile, "r"))) { - while(fgets(genbuf, STRLEN, fp)) { + if ((fp = fopen(listfile, "r"))) { + while (fgets(genbuf, STRLEN, fp)) { strtok(genbuf, str_space); - if(!InNameList(genbuf)) { + if (!InNameList(genbuf)) { AddNameList(genbuf); (*reciper)++; } else { @@ -139,46 +157,52 @@ void ToggleNameList(int *reciper, char *listfile, char *msg) { } } -static int NumInList(word_t *list) { - register int i; +static int +NumInList(word_t * list) +{ + register int i; - for(i = 0; list; i++) + for (i = 0; list; i++) list = list->next; return i; } -int chkstr(char *otag, char *tag, char *name) { - char ch, *oname = name; +int +chkstr(char *otag, char *tag, char *name) +{ + char ch, *oname = name; - while(*tag) { + while (*tag) { ch = *name++; - if(*tag != chartoupper(ch)) + if (*tag != chartoupper(ch)) return 0; tag++; } - if(*tag && *name == '\0') + if (*tag && *name == '\0') strcpy(otag, oname); return 1; } -static word_t *GetSubList(char *tag, word_t *list) { - word_t *wlist, *wcurr; - char tagbuf[STRLEN]; - int n; +static word_t * +GetSubList(char *tag, word_t * list) +{ + word_t *wlist, *wcurr; + char tagbuf[STRLEN]; + int n; wlist = wcurr = NULL; - for(n = 0; tag[n]; n++) + for (n = 0; tag[n]; n++) tagbuf[n] = chartoupper(tag[n]); tagbuf[n] = '\0'; - while(list) { - if(chkstr(tag, tagbuf, list->word)) { + while (list) { + if (chkstr(tag, tagbuf, list->word)) { register word_t *node; - node = (word_t *)malloc(sizeof(word_t)); + node = (word_t *) malloc(sizeof(word_t)); node->word = list->word; node->next = NULL; - if(wlist) + if (wlist) wcurr->next = node; else wlist = node; @@ -189,22 +213,26 @@ static word_t *GetSubList(char *tag, word_t *list) { return wlist; } -static void ClearSubList(word_t *list) { - struct word_t *tmp_list; +static void +ClearSubList(word_t * list) +{ + struct word_t *tmp_list; - while(list) { + while (list) { tmp_list = list->next; free(list); list = tmp_list; } } -static int MaxLen(word_t *list, int count) { - int len = strlen(list->word); - int t; +static int +MaxLen(word_t * list, int count) +{ + int len = strlen(list->word); + int t; - while(list && count) { - if((t = strlen(list->word)) > len) + while (list && count) { + if ((t = strlen(list->word)) > len) len = t; list = list->next; count--; @@ -212,20 +240,22 @@ static int MaxLen(word_t *list, int count) { return len; } -void namecomplete(char *prompt, char *data) { - char *temp; - word_t *cwlist, *morelist; - int x, y, origx, origy; - int ch; - int count = 0; - int clearbot = NA; - - if(toplev == NULL) +void +namecomplete(char *prompt, char *data) +{ + char *temp; + word_t *cwlist, *morelist; + int x, y, origx, origy; + int ch; + int count = 0; + int clearbot = NA; + + if (toplev == NULL) AddNameList(""); cwlist = GetSubList("", toplev); morelist = NULL; temp = data; - + outs(prompt); clrtoeol(); getyx(&y, &x); @@ -235,20 +265,20 @@ void namecomplete(char *prompt, char *data) { standend(); move(y, x); refresh(); - - while((ch = igetch()) != EOF) { - if(ch == '\n' || ch == '\r') { + + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { *temp = '\0'; outc('\n'); - if(NumInList(cwlist) == 1) + if (NumInList(cwlist) == 1) strcpy(data, cwlist->word); ClearSubList(cwlist); break; } - if(ch == ' ') { - int col, len; - - if(NumInList(cwlist) == 1) { + if (ch == ' ') { + int col, len; + + if (NumInList(cwlist) == 1) { strcpy(data, cwlist->word); move(y, x); outs(data + count); @@ -259,34 +289,34 @@ void namecomplete(char *prompt, char *data) { } clearbot = YEA; col = 0; - if(!morelist) + if (!morelist) morelist = cwlist; len = MaxLen(morelist, p_lines); move(2, 0); clrtobot(); printdash("¬ÛÃö¸ê°T¤@Äýªí"); - while(len + col < 80) { - int i; - - for(i = p_lines; (morelist) && (i > 0); i--) { + while (len + col < 80) { + int i; + + for (i = p_lines; (morelist) && (i > 0); i--) { move(3 + (p_lines - i), col); outs(morelist->word); morelist = morelist->next; } col += len + 2; - if(!morelist) + if (!morelist) break; len = MaxLen(morelist, p_lines); } - if(morelist) { + if (morelist) { move(b_lines, 0); outs(msg_more); } move(y, x); continue; } - if(ch == '\177' || ch == '\010') { - if(temp == data) + if (ch == '\177' || ch == '\010') { + if (temp == data) continue; temp--; count--; @@ -300,15 +330,14 @@ void namecomplete(char *prompt, char *data) { move(y, x); continue; } - - if(count < STRLEN && isprint(ch)) { - word_t *node; + if (count < STRLEN && isprint(ch)) { + word_t *node; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); - if(node == NULL) { + if (node == NULL) { temp--; *temp = '\0'; count--; @@ -322,33 +351,36 @@ void namecomplete(char *prompt, char *data) { x++; } } - if(ch == EOF) + if (ch == EOF) /* longjmp(byebye, -1); */ - raise(SIGHUP); /* jochang: don't know if this is necessary... */ + raise(SIGHUP); /* jochang: don't know if this is + * necessary... */ outc('\n'); refresh(); - if(clearbot) { + if (clearbot) { move(2, 0); clrtobot(); } - if(*data) { + if (*data) { move(origy, origx); outs(data); outc('\n'); } } -void usercomplete(char *prompt, char *data) { - char *temp; - char *cwbuf, *cwlist; - int cwnum, x, y, origx, origy; - int clearbot = NA, count = 0, morenum = 0; - char ch; +void +usercomplete(char *prompt, char *data) +{ + char *temp; + char *cwbuf, *cwlist; + int cwnum, x, y, origx, origy; + int clearbot = NA, count = 0, morenum = 0; + char ch; cwbuf = malloc(MAX_USERS * (IDLEN + 1)); - cwlist = u_namearray((arrptr)cwbuf, &cwnum, ""); + cwlist = u_namearray((arrptr) cwbuf, &cwnum, ""); temp = data; - + outs(prompt); clrtoeol(); getyx(&y, &x); @@ -357,24 +389,24 @@ void usercomplete(char *prompt, char *data) { prints("%*s", IDLEN + 1, ""); standend(); move(y, x); - while((ch = igetch()) != EOF) { - if(ch == '\n' || ch == '\r') { - int i; - char *ptr; - + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { + int i; + char *ptr; + *temp = '\0'; outc('\n'); ptr = (char *)cwlist; - for(i = 0; i < cwnum; i++) { - if(strncasecmp(data, ptr, IDLEN + 1) == 0) + for (i = 0; i < cwnum; i++) { + if (strncasecmp(data, ptr, IDLEN + 1) == 0) strcpy(data, ptr); ptr += IDLEN + 1; } break; - } else if(ch == ' ') { - int col, len; - - if(cwnum == 1) { + } else if (ch == ' ') { + int col, len; + + if (cwnum == 1) { strcpy(data, (char *)cwlist); move(y, x); outs(data + count); @@ -385,49 +417,49 @@ void usercomplete(char *prompt, char *data) { } clearbot = YEA; col = 0; - len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines); move(2, 0); clrtobot(); printdash("¨Ï¥ÎªÌ¥N¸¹¤@Äýªí"); - while(len + col < 79) { - int i; - - for(i = 0; morenum < cwnum && i < p_lines; i++) { + while (len + col < 79) { + int i; + + for (i = 0; morenum < cwnum && i < p_lines; i++) { move(3 + i, col); prints("%s ", cwlist + (IDLEN + 1) * morenum++); } col += len + 2; - if(morenum >= cwnum) + if (morenum >= cwnum) break; - len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); + len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines); } - if(morenum < cwnum) { + if (morenum < cwnum) { move(b_lines, 0); outs(msg_more); } else morenum = 0; move(y, x); continue; - } else if(ch == '\177' || ch == '\010') { - if(temp == data) + } else if (ch == '\177' || ch == '\010') { + if (temp == data) continue; temp--; count--; *temp = '\0'; - cwlist = u_namearray((arrptr)cwbuf, &cwnum, data); + cwlist = u_namearray((arrptr) cwbuf, &cwnum, data); morenum = 0; x--; move(y, x); outc(' '); move(y, x); continue; - } else if(count < STRLEN && isprint(ch)) { - int n; - + } else if (count < STRLEN && isprint(ch)) { + int n; + *temp++ = ch; *temp = '\0'; - n = UserSubArray((arrptr)cwbuf, (arrptr)cwlist, cwnum, ch, count); - if(n == 0) { + n = UserSubArray((arrptr) cwbuf, (arrptr) cwlist, cwnum, ch, count); + if (n == 0) { temp--; *temp = '\0'; continue; @@ -442,231 +474,218 @@ void usercomplete(char *prompt, char *data) { } } free(cwbuf); - if(ch == EOF) + if (ch == EOF) /* longjmp(byebye, -1); */ - raise(SIGHUP); /* jochang: don't know if this is necessary */ + raise(SIGHUP); /* jochang: don't know if this is necessary */ outc('\n'); refresh(); - if(clearbot) { + if (clearbot) { move(2, 0); clrtobot(); } - if(*data) { + if (*data) { move(origy, origx); outs(data); outc('\n'); } } -int gnc_findbound(char *str, int *START, int *END, - size_t nmemb, int (*compar)(int, char *, int)) +int +gnc_findbound(char *str, int *START, int *END, + size_t nmemb, int (*compar) (int, char *, int)) { - int start, end, mid, cmp, strl; + int start, end, mid, cmp, strl; strl = strlen(str); start = 0, end = nmemb - 1; - while( start != end && ((mid = (start + end) / 2) != start) ){ + while (start != end && ((mid = (start + end) / 2) != start)) { cmp = compar(mid, str, strl); //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); - if( cmp >= 0 ) + if (cmp >= 0) end = mid; else start = mid; } ++start; - //if( strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0 ){ - if( compar(start, str, strl) != 0 ){ - *START = *END = -1; - return -1; - } - *START = start; - - end = nmemb - 1; - while( start != end && ((mid = (start + end) / 2) != start) ){ - cmp = compar(mid, str, strl); - //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); - if( cmp <= 0 ) - start = mid; - else - end = mid; - } - *END = start; - return 0; -} - -int gnc_completeone(char *data, int start, int end, - int (*permission)(int), char* (*getname)(int)) -{ - int i, count, at; - if( start < 0 || end < 0 ) - return -1; - for( i = start, at = count = 0 ; i <= end && count < 2 ; ++i ) - if( permission(i) ){ - at = i; - ++count; + //if (strncasecmp(brdshm->sorted[0][start]->brdname, str, strl) != 0) { + if (compar(start, str, strl) != 0) { + *START = *END = -1; + return -1; } - if( count == 1 ){ - strcpy(data, getname(at)); - return at; + *START = start; + + end = nmemb - 1; + while (start != end && ((mid = (start + end) / 2) != start)) { + cmp = compar(mid, str, strl); + //cmp = strncasecmp(brdshm->sorted[0][mid]->brdname, str, strl); + if (cmp <= 0) + start = mid; + else + end = mid; + } + *END = start; + return 0; } - return -1; -} - - -int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, - int (*compar)(int, char *, int), - int (*permission)(int), char* (*getname)(int)) -{ - int x, y, origx, origy, ch, i, morelist = -1, col, ret = -1; - int start, end, ptr; - int clearbot = NA; - - outs(prompt); - clrtoeol(); - getyx(&y, &x); - getyx(&origy, &origx); - standout(); - prints("%*s", IDLEN + 1, ""); - standend(); - move(y, x); - refresh(); - ptr = 0; - data[ptr] = 0; - - while( (ch = igetch()) != EOF ){ - if( ch == '\n' || ch == '\r' ){ - data[ptr] = 0; - outc('\n'); - if( ptr != 0 ){ - gnc_findbound(data, &start, &end, nmemb, compar); - ret = gnc_completeone(data, start, end, permission, getname); + int gnc_completeone(char *data, int start, int end, + int (*permission) (int), char *(*getname) (int)){ + int i, count, at; + if (start < 0 || end < 0) + return -1; + for (i = start, at = count = 0; i <= end && count < 2; ++i) + if (permission(i)) { + at = i; + ++count; } - else - ptr = -1; - break; + if (count == 1) { + strcpy(data, getname(at)); + return at; } - else if( ch == ' ' ){ - if( ptr == 0 ) - continue; + return -1; + } - if( morelist == -1 ){ - if( gnc_findbound(data, &start, &end, nmemb, compar) == -1 ) - continue; - if( gnc_completeone(data, start, end, - permission, getname) >= 0 ){ - move(origy, origx); - outs(data); - ptr = strlen(data); - getyx(&y, &x); - continue; - } - morelist = start; - } - else if( morelist > end ) - continue; - clearbot = YEA; - move(2, 0); - clrtobot(); - printdash("¬ÛÃö¸ê°T¤@Äýªí"); + int generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, + int (*compar) (int, char *, int), + int (*permission) (int), char *(*getname) (int)){ + int x, y, origx, origy, ch, i, morelist = -1, col, + ret = -1; + int start, end, ptr; + int clearbot = NA; + + outs(prompt); + clrtoeol(); + getyx(&y, &x); + getyx(&origy, &origx); + standout(); + prints("%*s", IDLEN + 1, ""); + standend(); + move(y, x); + refresh(); + ptr = 0; + data[ptr] = 0; + + while ((ch = igetch()) != EOF) { + if (ch == '\n' || ch == '\r') { + data[ptr] = 0; + outc('\n'); + if (ptr != 0) { + gnc_findbound(data, &start, &end, nmemb, compar); + ret = gnc_completeone(data, start, end, permission, getname); + } else + ptr = -1; + break; + } else if (ch == ' ') { + if (ptr == 0) + continue; - col = 0; - while(len + col < 79) { - for( i = 0 ; morelist <= end && i < p_lines ; ++morelist){ - if( permission(morelist) ){ - move(3 + i, col); - prints("%s ", getname(morelist)); - ++i; + if (morelist == -1) { + if (gnc_findbound(data, &start, &end, nmemb, compar) == -1) + continue; + if (gnc_completeone(data, start, end, + permission, getname) >= 0) { + move(origy, origx); + outs(data); + ptr = strlen(data); + getyx(&y, &x); + continue; + } + morelist = start; + } else if (morelist > end) + continue; + clearbot = YEA; + move(2, 0); + clrtobot(); + printdash("¬ÛÃö¸ê°T¤@Äýªí"); + + col = 0; + while (len + col < 79) { + for (i = 0; morelist <= end && i < p_lines; ++morelist) { + if (permission(morelist)) { + move(3 + i, col); + prints("%s ", getname(morelist)); + ++i; + } } - } - col += len + 2; - } - if( morelist != end + 1 ){ - move(b_lines, 0); - outs(msg_more); - } - move(y, x); - continue; + col += len + 2; + } + if (morelist != end + 1) { + move(b_lines, 0); + outs(msg_more); + } + move(y, x); + continue; - } - else if(ch == '\177' || ch == '\010') { /* backspace */ - if( ptr == 0 ) + } else if (ch == '\177' || ch == '\010') { /* backspace */ + if (ptr == 0) + continue; + morelist = -1; + --ptr; + --x; + data[ptr] = 0; + move(y, x); + outc(' '); + move(y, x); continue; - morelist = -1; - --ptr; --x; - data[ptr] = 0; - move(y, x); - outc(' '); - move(y, x); - continue; - } - else if( isprint(ch) && ptr <= (len - 2) ){ - morelist = -1; - data[ptr] = ch; - ++ptr; - data[ptr] = 0; - if( gnc_findbound(data, &start, &end, nmemb, compar) < 0 ) - data[--ptr] = 0; - else{ - for( i = start ; i <= end ; ++i ) - if( permission(i) ) - break; - if( i == end + 1 ) + } else if (isprint(ch) && ptr <= (len - 2)) { + morelist = -1; + data[ptr] = ch; + ++ptr; + data[ptr] = 0; + if (gnc_findbound(data, &start, &end, nmemb, compar) < 0) data[--ptr] = 0; - else{ - move(y, x); - outc(ch); - x++; + else { + for (i = start; i <= end; ++i) + if (permission(i)) + break; + if (i == end + 1) + data[--ptr] = 0; + else { + move(y, x); + outc(ch); + x++; + } } } } - } - outc('\n'); - refresh(); - if(clearbot) { - move(2, 0); - clrtobot(); - } - if(*data) { - move(origy, origx); - outs(data); outc('\n'); + refresh(); + if (clearbot) { + move(2, 0); + clrtobot(); + } + if (*data) { + move(origy, origx); + outs(data); + outc('\n'); + } + return ret; } - return ret; -} - -/* general complete functions (brdshm) */ -int completeboard_compar(int where, char *str, int len) -{ - return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); -} -int completeboard_permission(int where) -{ - return Ben_Perm(SHM->bsorted[0][where]); -} + /* general complete functions (brdshm) */ + int completeboard_compar(int where, char *str, int len){ + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); + } -char *completeboard_getname(int where) -{ - return SHM->bsorted[0][where]->brdname; -} + int completeboard_permission(int where){ + return Ben_Perm(SHM->bsorted[0][where]); + } -/* general complete functions (utmpshm) */ -int completeutmp_compar(int where, char *str, int len) -{ - return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, - str, len); -} + char *completeboard_getname(int where){ + return SHM->bsorted[0][where]->brdname; + } -int completeutmp_permission(int where) -{ - return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || - !SHM->sorted[SHM->currsorted][0][where]->invisible); -} + /* general complete functions (utmpshm) */ + int completeutmp_compar(int where, char *str, int len){ + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, + str, len); + } -char *completeutmp_getname(int where) -{ - return SHM->sorted[SHM->currsorted][0][where]->userid; -} + int completeutmp_permission(int where){ + return (HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK) || + !SHM->sorted[SHM->currsorted][0][where]->invisible); + } + char *completeutmp_getname(int where){ + return SHM->sorted[SHM->currsorted][0][where]->userid; + } diff --git a/mbbsd/osdep.c b/mbbsd/osdep.c index 315cdb51..d99395c7 100644 --- a/mbbsd/osdep.c +++ b/mbbsd/osdep.c @@ -1,17 +1,19 @@ -/* $Id: osdep.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: osdep.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#if __FreeBSD__ +#if __FreeBSD__ #include <kvm.h> -int cpuload(char *str) { - double l[3] = {-1, -1, -1}; - if(getloadavg(l, 3) != 3) +int +cpuload(char *str) +{ + double l[3] = {-1, -1, -1}; + if (getloadavg(l, 3) != 3) l[0] = -1; - - if(str) { - if(l[0] != -1) + + if (str) { + if (l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); else strcpy(str, " (unknown) "); @@ -19,19 +21,21 @@ int cpuload(char *str) { return (int)l[0]; } -double swapused(long *total, long *used) { - double percent = -1; - kvm_t *kd; +double +swapused(long *total, long *used) +{ + double percent = -1; + kvm_t *kd; struct kvm_swap swapinfo; - int pagesize; - + int pagesize; + kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); - if(kd) { - if(kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { + if (kd) { + if (kvm_getswapinfo(kd, &swapinfo, 1, 0) == 0) { pagesize = getpagesize(); *total = swapinfo.ksw_total * pagesize; *used = swapinfo.ksw_used * pagesize; - if(*total != 0) + if (*total != 0) percent = (double)*used / (double)*total; } kvm_close(kd); @@ -40,17 +44,19 @@ double swapused(long *total, long *used) { } #else -int cpuload(char *str) { - double l[3] = {-1, -1, -1}; - FILE *fp; - - if((fp = fopen("/proc/loadavg", "r"))) { - if(fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) +int +cpuload(char *str) +{ + double l[3] = {-1, -1, -1}; + FILE *fp; + + if ((fp = fopen("/proc/loadavg", "r"))) { + if (fscanf(fp, "%lf %lf %lf", &l[0], &l[1], &l[2]) != 3) l[0] = -1; fclose(fp); } - if(str) { - if(l[0] != -1) + if (str) { + if (l[0] != -1) sprintf(str, " %.2f %.2f %.2f", l[0], l[1], l[2]); else strcpy(str, " (unknown) "); @@ -58,15 +64,17 @@ int cpuload(char *str) { return (int)l[0]; } -double swapused(long *total, long *used) { - double percent = -1; - char buf[101]; - FILE *fp; - - if((fp = fopen("/proc/meminfo","r"))) { - while(fgets(buf, 100, fp) && buf[0] != 'S'); - if(sscanf(buf + 6, "%ld %ld", total, used) == 2) - if(*total != 0) +double +swapused(long *total, long *used) +{ + double percent = -1; + char buf[101]; + FILE *fp; + + if ((fp = fopen("/proc/meminfo", "r"))) { + while (fgets(buf, 100, fp) && buf[0] != 'S'); + if (sscanf(buf + 6, "%ld %ld", total, used) == 2) + if (*total != 0) percent = (double)*used / (double)*total; fclose(fp); } diff --git a/mbbsd/othello.c b/mbbsd/othello.c index 4a146f77..76cd2f8c 100644 --- a/mbbsd/othello.c +++ b/mbbsd/othello.c @@ -1,4 +1,4 @@ -/* $Id: othello.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: othello.c,v 1.4 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" #define LOGFILE "etc/othello.log" @@ -20,67 +20,71 @@ #define INVERT(COLOR) (((COLOR))==WHITE?BLACK:WHITE) -static char nowx = 3, nowy = 3; -static char *CHESS_TYPE[] = {NONE_CHESS, HINT_CHESS, BLACK_CHESS, WHITE_CHESS}; -static char DIRX[] = {-1,-1,-1, 0, 1, 1, 1, 0}; -static char DIRY[] = {-1, 0, 1, 1, 1, 0,-1,-1}; -static char number[2]; - -static char pass = 0; -static char if_hint = 0; -static int think, which_table; - -static char nowboard[10][10]= -{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; -static char init_table[NR_TABLE+1][5][5] = { - {{ 0, 0, 0, 0, 0}, - { 0,30,-3, 2, 2}, - { 0,-3,-3,-1,-1}, - { 0, 2,-1, 1, 1}, - { 0, 2,-1, 1, 0}}, - - {{ 0, 0, 0, 0, 0}, - { 0,70, 5,20,30}, - { 0, 5,-5, 3, 3}, - { 0,20, 3, 5, 5}, - { 0,30, 3, 5, 5}}, - - {{ 0, 0, 0, 0, 0}, - { 0, 5, 2, 2, 2}, - { 0, 2, 1, 1, 1}, - { 0, 2, 1, 1, 1}, - { 0, 2, 1, 1, 1}} +static char nowx = 3, nowy = 3; +static char *CHESS_TYPE[] = {NONE_CHESS, HINT_CHESS, BLACK_CHESS, WHITE_CHESS}; +static char DIRX[] = {-1, -1, -1, 0, 1, 1, 1, 0}; +static char DIRY[] = {-1, 0, 1, 1, 1, 0, -1, -1}; +static char number[2]; + +static char pass = 0; +static char if_hint = 0; +static int think, which_table; + +static char nowboard[10][10] = +{{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, -1}, +{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; +static char init_table[NR_TABLE + 1][5][5] = { + {{0, 0, 0, 0, 0}, + {0, 30, -3, 2, 2}, + {0, -3, -3, -1, -1}, + {0, 2, -1, 1, 1}, + {0, 2, -1, 1, 0}}, + + {{0, 0, 0, 0, 0}, + {0, 70, 5, 20, 30}, + {0, 5, -5, 3, 3}, + {0, 20, 3, 5, 5}, + {0, 30, 3, 5, 5}}, + + {{0, 0, 0, 0, 0}, + {0, 5, 2, 2, 2}, + {0, 2, 1, 1, 1}, + {0, 2, 1, 1, 1}, + {0, 2, 1, 1, 1}} }; -static char table[NR_TABLE + 1][10][10]; -static void print_chess(int x, int y, char chess) { +static char table[NR_TABLE + 1][10][10]; +static void +print_chess(int x, int y, char chess) +{ move(STARTX - 1 + x * 2, STARTY - 2 + y * 4); - if(chess != HINT || if_hint == 1) + if (chess != HINT || if_hint == 1) prints(CHESS_TYPE[(int)chess]); else prints(CHESS_TYPE[NONE]); refresh(); } -static void printboard() { - int i; - +static void +printboard() +{ + int i; + move(STARTX, STARTY); prints("¢z¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢s¢w¢{"); - for(i = 0; i < 7; i++) { + for (i = 0; i < 7; i++) { move(STARTX + 1 + i * 2, STARTY); - prints ("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); + prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); move(STARTX + 2 + i * 2, STARTY); - prints ("¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t"); + prints("¢u¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢q¢w¢t"); } move(STARTX + 1 + i * 2, STARTY); prints("¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x ¢x"); @@ -91,7 +95,7 @@ static void printboard() { print_chess(4, 5, BLACK); print_chess(5, 4, BLACK); move(3, 56); - prints("(¶Â)%s",cuser.userid); + prints("(¶Â)%s", cuser.userid); move(3, 72); prints(": 02"); move(4, 56); @@ -102,7 +106,7 @@ static void printboard() { prints("[q] °h¥X"); move(8, 56); prints("[h] ¶}±Ò/Ãö³¬ ´£¥Ü"); - move(9,56); + move(9, 56); prints("[Enter][Space] ¤U´Ñ"); move(10, 56); prints("¤W:¡ô, i"); @@ -114,39 +118,43 @@ static void printboard() { prints("¥k:¡÷, l"); } -static int get_key(char nowx, char nowy) { - int ch; - +static int +get_key(char nowx, char nowy) +{ + int ch; + move(STARTX - 1 + nowx * 2, STARTY - 1 + nowy * 4); ch = igetkey(); move(STARTX - 1 + nowx * 2, STARTY - 2 + nowy * 4); - if(nowboard[(int)nowx][(int)nowy] != HINT || if_hint==1) + if (nowboard[(int)nowx][(int)nowy] != HINT || if_hint == 1) outs(CHESS_TYPE[(int)nowboard[(int)nowx][(int)nowy]]); else outs(CHESS_TYPE[NONE]); return ch; } -static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { - int tmpx,tmpy; - char tmpchess; - +static int +eatline(int i, int j, char color, int dir, char chessboard[][10]) +{ + int tmpx, tmpy; + char tmpchess; + tmpx = i + DIRX[dir]; tmpy = j + DIRY[dir]; tmpchess = chessboard[tmpx][tmpy]; - if(tmpchess == -1) + if (tmpchess == -1) return false; - if(tmpchess != INVERT(color)) + if (tmpchess != INVERT(color)) return false; - + tmpx += DIRX[dir]; tmpy += DIRY[dir]; tmpchess = chessboard[tmpx][tmpy]; - while(tmpchess != -1) { - if(tmpchess < BLACK) + while (tmpchess != -1) { + if (tmpchess < BLACK) return false; - if(tmpchess == color) { - while(i != tmpx || j != tmpy) { + if (tmpchess == color) { + while (i != tmpx || j != tmpy) { chessboard[i][j] = color; i += DIRX[dir]; j += DIRY[dir]; @@ -160,32 +168,36 @@ static int eatline(int i, int j, char color, int dir, char chessboard[][10]) { return false; } -static int if_can_put(int x, int y, char color, char chessboard[][10]) { - int i, temp, checkx, checky; - - if(chessboard[x][y]<BLACK) - for(i = 0; i < 8; i++) { +static int +if_can_put(int x, int y, char color, char chessboard[][10]) +{ + int i, temp, checkx, checky; + + if (chessboard[x][y] < BLACK) + for (i = 0; i < 8; i++) { checkx = x + DIRX[i]; checky = y + DIRY[i]; temp = chessboard[checkx][checky]; - if(temp < BLACK) + if (temp < BLACK) continue; - if(temp != color) - while(chessboard[checkx += DIRX[i]][checky += DIRY[i]] > HINT) - if(chessboard[checkx][checky] == color) + if (temp != color) + while (chessboard[checkx += DIRX[i]][checky += DIRY[i]] > HINT) + if (chessboard[checkx][checky] == color) return true; } return false; } -static int get_hint(char color) { - int i, j, temp = 0; - - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) { - if(nowboard[i][j] == HINT) +static int +get_hint(char color) +{ + int i, j, temp = 0; + + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { + if (nowboard[i][j] == HINT) nowboard[i][j] = NONE; - if(if_can_put(i, j, color, nowboard)) { + if (if_can_put(i, j, color, nowboard)) { nowboard[i][j] = HINT; temp++; } @@ -194,89 +206,96 @@ static int get_hint(char color) { return temp; } -static void eat(int x, int y, int color, char chessboard[][10]) { - int k; - - for(k = 0; k < 8; k++) +static void +eat(int x, int y, int color, char chessboard[][10]) +{ + int k; + + for (k = 0; k < 8; k++) eatline(x, y, color, k, chessboard); } -static void end_of_game(int quit) { - FILE *fp,*fp1; - char *opponent[] = {"","CD-65","","À¦¨à","¤p«Ä","","¤j¤H","±M®a"}; - +static void +end_of_game(int quit) +{ + FILE *fp, *fp1; + char *opponent[] = {"", "CD-65", "", "À¦¨à", "¤p«Ä", "", "¤j¤H", "±M®a"}; + move(STARTX - 1, 30); - prints (" "); + prints(" "); move(22, 35); fp = fopen(LOGFILE, "a"); - if(!quit) { + if (!quit) { fp1 = fopen(SECRET, "a"); - if(fp1) { + if (fp1) { fprintf(fp1, "%d,%d,%s,%02d,%02d\n", think, which_table, - cuser.userid, number[0], number[1]); + cuser.userid, number[0], number[1]); fclose(fp1); } } - - if(quit) { - if(number[0] == 2 && number[1] == 2) { - if(fp) + if (quit) { + if (number[0] == 2 && number[1] == 2) { + if (fp) fclose(fp); return; } fprintf(fp, "¦b%s¯Å¤¤, %sÁ{°}²æ°k\n", opponent[think], cuser.userid); - if(fp) - fclose(fp); + if (fp) + fclose(fp); return; - } - if(number[0] > number[1]) { + } + if (number[0] > number[1]) { prints("§AŤF¹q¸£%02d¤l", number[0] - number[1]); - if(think == 6 && number[0] - number[1] >= 50) + if (think == 6 && number[0] - number[1] >= 50) demoney(200); - if(think == 7 && number[0] - number[1] >= 40) + if (think == 7 && number[0] - number[1] >= 40) demoney(200); - if(fp) + if (fp) fprintf(fp, "¦b%s¯Å¤¤, %s¥H %02d:%02d ŤF¹q¸£%02d¤l\n", opponent[think], cuser.userid, number[0], number[1], number[0] - number[1]); - } else if(number[1] > number[0]) { + } else if (number[1] > number[0]) { prints("¹q¸£Ä¹¤F§A%02d¤l", number[1] - number[0]); - if(fp) { + if (fp) { fprintf(fp, "¦b%s¯Å¤¤, ", opponent[think]); - if(number[1] - number[0] > 20) + if (number[1] - number[0] > 20) fprintf(fp, "¹q¸£¥H %02d:%02d ºG¹q%s %02d¤l\n", number[1], number[0], cuser.userid, number[1] - number[0]); else fprintf(fp, "¹q¸£¥H %02d:%02d ŤF%s %02d¤l\n", number[1], number[0], cuser.userid, number[1] - number[0]); - } + } } else { prints("§A©M¹q¸£¥´¦¨¥¤â!!"); - if(fp) + if (fp) fprintf(fp, "¦b%s¯Å¤¤, %s©M¹q¸£¥H %02d:%02d ¥´¦¨¤F¥¤â\n", opponent[think], cuser.userid, number[1], number[0]); } - if(fp) + if (fp) fclose(fp); - move(1,1); + move(1, 1); igetkey(); } -static void othello_redraw() { - int i, j; - - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) +static void +othello_redraw() +{ + int i, j; + + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) print_chess(i, j, nowboard[i][j]); } -static int player(char color) { - int ch; - - if(get_hint(color)) { - while(true) { - ch = get_key(nowx,nowy); - switch(ch) { +static int +player(char color) +{ + int ch; + + if (get_hint(color)) { + while (true) { + ch = get_key(nowx, nowy); + switch (ch) { case 'J': case 'j': case KEY_LEFT: @@ -296,10 +315,10 @@ static int player(char color) { case 'k': case KEY_DOWN: nowx++; - break; + break; case ' ': case '\r': - if(nowboard[(int)nowx][(int)nowy] != HINT) + if (nowboard[(int)nowx][(int)nowy] != HINT) break; pass = 0; nowboard[(int)nowx][(int)nowy] = color; @@ -311,26 +330,26 @@ static int player(char color) { return false; case 'H': case 'h': - if_hint = if_hint^1; + if_hint = if_hint ^ 1; othello_redraw(); break; } - if(nowx == 9) - nowx=1; - if(nowx == 0) - nowx=8; - if(nowy == 9) - nowy=1; - if(nowy == 0) - nowy=8; + if (nowx == 9) + nowx = 1; + if (nowx == 0) + nowx = 8; + if (nowy == 9) + nowy = 1; + if (nowy == 0) + nowy = 8; } } else { pass++; - if(pass == 1) { + if (pass == 1) { move(23, 34); prints("§A¥²»Ý©ñ±ó³o¤@¨B!!"); igetch(); - move(28,23); + move(28, 23); prints(" "); } else { end_of_game(0); @@ -340,35 +359,39 @@ static int player(char color) { return 0; } -static void init() { - int i, j, i1, j1; - +static void +init() +{ + int i, j, i1, j1; + nowx = 4; nowy = 4; number[0] = number[1] = 2; - for(i = 1; i <= 8; i++) - for(j = 1;j <= 8; j++) { + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { i1 = 4.5 - abs(4.5 - i); j1 = 4.5 - abs(4.5 - j); table[0][i][j] = init_table[0][i1][j1]; table[1][i][j] = init_table[1][i1][j1]; } - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) nowboard[i][j] = NONE; nowboard[4][4] = nowboard[5][5] = WHITE; nowboard[4][5] = nowboard[5][4] = BLACK; } -static void report() { - int i, j; - +static void +report() +{ + int i, j; + number[0] = number[1] = 0; - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) - if(nowboard[i][j] == BLACK) + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) + if (nowboard[i][j] == BLACK) number[0]++; - else if(nowboard[i][j] == WHITE) + else if (nowboard[i][j] == WHITE) number[1]++; move(3, 60); prints("%s", cuser.userid); @@ -378,12 +401,14 @@ static void report() { prints("¹q¸£ : %02d", number[1]); } -static int EVL(char chessboard[][10], int color, int table_number) { - int points = 0,a,b; - for(a = 1; a <= 8; a++) - for(b = 1; b <= 8; b++) - if(chessboard[a][b] > HINT) { - if(chessboard[a][b] == BLACK) +static int +EVL(char chessboard[][10], int color, int table_number) +{ + int points = 0, a, b; + for (a = 1; a <= 8; a++) + for (b = 1; b <= 8; b++) + if (chessboard[a][b] > HINT) { + if (chessboard[a][b] == BLACK) points += table[table_number][a][b]; else points -= table[table_number][a][b]; @@ -391,57 +416,61 @@ static int EVL(char chessboard[][10], int color, int table_number) { return ((color == BLACK) ? points : -points); } -static int alphabeta(int alpha, int beta, int level, char chessboard[][10], - int thinkstep, int color, int table) { - int i, j, k, flag = 1; - char tempboard[10][10]; - if(level == thinkstep+1) +static int +alphabeta(int alpha, int beta, int level, char chessboard[][10], + int thinkstep, int color, int table) +{ + int i, j, k, flag = 1; + char tempboard[10][10]; + if (level == thinkstep + 1) return EVL(chessboard, (level & 1 ? color : ((color - 2) ^ 1) + 2), table); - for(i = 1; i <= 8; i++) { - for(j = 1; j <= 8; j++) { - if(if_can_put(i, j, color, chessboard)) { + for (i = 1; i <= 8; i++) { + for (j = 1; j <= 8; j++) { + if (if_can_put(i, j, color, chessboard)) { flag = 0; memcpy(tempboard, chessboard, sizeof(char) * 100); eat(i, j, color, tempboard); - + k = alphabeta(alpha, beta, level + 1, tempboard, thinkstep, ((color - 2) ^ 1) + 2, table); - if(((level & 1) && k > alpha)) + if (((level & 1) && k > alpha)) alpha = k; - else if(!(level & 1) && k < beta) + else if (!(level & 1) && k < beta) beta = k; - if(alpha >= beta) + if (alpha >= beta) break; } } } - if(flag) + if (flag) return EVL(chessboard, color, table); return ((level & 1) ? alpha : beta); } -static int Computer(int thinkstep, int table) { - int i, j, maxi = 0, maxj = 0, level = 1; - char chessboard[10][10]; - int alpha = -10000, k; - if((number[0] + number[1]) > 44) +static int +Computer(int thinkstep, int table) +{ + int i, j, maxi = 0, maxj = 0, level = 1; + char chessboard[10][10]; + int alpha = -10000, k; + if ((number[0] + number[1]) > 44) table = NR_TABLE; - for(i = 1; i <= 8; i++) - for(j = 1; j <= 8; j++) { - if(if_can_put(i,j,WHITE,nowboard)) { + for (i = 1; i <= 8; i++) + for (j = 1; j <= 8; j++) { + if (if_can_put(i, j, WHITE, nowboard)) { memcpy(chessboard, nowboard, sizeof(char) * 100); eat(i, j, WHITE, chessboard); k = alphabeta(alpha, 10000, level + 1, chessboard, thinkstep, BLACK, table); - if(k > alpha) { + if (k > alpha) { alpha = k; maxi = i; maxj = j; } } } - if(alpha != -10000) { + if (alpha != -10000) { eat(maxi, maxj, WHITE, nowboard); pass = 0; nowx = maxi; @@ -450,7 +479,7 @@ static int Computer(int thinkstep, int table) { move(23, 30); prints("¹q¸£©ñ±ó³o¤@¨B´Ñ!!"); pass++; - if(pass == 2) { + if (pass == 2) { move(23, 24); prints(" "); end_of_game(0); @@ -458,26 +487,28 @@ static int Computer(int thinkstep, int table) { } igetch(); move(23, 24); - prints(" "); + prints(" "); } return true; } -static int choose() { - char thinkstep[2]; - +static int +choose() +{ + char thinkstep[2]; + move(2, 0); prints("½Ð¿ï¾ÜÃø«×:"); move(5, 0); - prints("(1) CD-65\n"); /* ·Q 1 ¨B */ - prints("(2) À¦¨à\n"); /* ·Q 3 ¨B */ - prints("(3) ¤p«Ä\n"); /* ·Q 4 ¨B */ + prints("(1) CD-65\n"); /* ·Q 1 ¨B */ + prints("(2) À¦¨à\n"); /* ·Q 3 ¨B */ + prints("(3) ¤p«Ä\n"); /* ·Q 4 ¨B */ do { getdata(4, 0, "½Ð¿ï¾Ü¤@Ó¹ï¶H©M±z¹ï¥´:(1~5)", thinkstep, sizeof(thinkstep), LCECHO); - } while(thinkstep[0] < '1' || thinkstep[0] > '3'); + } while (thinkstep[0] < '1' || thinkstep[0] > '3'); clear(); - switch(thinkstep[0]) { + switch (thinkstep[0]) { case '2': thinkstep[0] = '3'; break; @@ -493,33 +524,35 @@ static int choose() { #define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0 -int othello_main() { +int +othello_main() +{ lockreturn0(OTHELLO, LOCK_MULTI); clear(); init(); think = choose(); - showtitle("¶Â¥Õ´Ñ", BBSName); + showtitle("¶Â¥Õ´Ñ", BBSName); printboard(); which_table = rand() % NR_TABLE; - while(true) { + while (true) { move(STARTX - 1, 30); prints("½ü¨ì§A¤U¤F..."); - if(!player(BLACK)) + if (!player(BLACK)) break; report(); othello_redraw(); - if(number[0] + number[1] == 64) { + if (number[0] + number[1] == 64) { end_of_game(0); break; } move(STARTX - 1, 30); prints("¹q¸£«ä¦Ò¤¤..."); refresh(); - if(!Computer(think, which_table)) + if (!Computer(think, which_table)) break; report(); othello_redraw(); - if(number[0] + number[1] == 64) { + if (number[0] + number[1] == 64) { end_of_game(0); break; } diff --git a/mbbsd/page.c b/mbbsd/page.c index b39f7d7e..6e8489e2 100644 --- a/mbbsd/page.c +++ b/mbbsd/page.c @@ -1,19 +1,21 @@ -/* $Id: page.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: page.c,v 1.6 2002/07/05 17:10:27 in2 Exp $ */ #include "bbs.h" -#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} -static void filt_railway(char* fpath) { - char buf[256], tmppath[32]; - FILE* fp = fopen(fpath, "w"), *tp; +#define hpressanykey(a) {move(22, 0); prints(a); pressanykey();} +static void +filt_railway(char *fpath) +{ + char buf[256], tmppath[32]; + FILE *fp = fopen(fpath, "w"), *tp; sprintf(tmppath, "%s.railway", fpath); - if(!fp || !(tp = fopen(tmppath, "r"))) + if (!fp || !(tp = fopen(tmppath, "r"))) return; - while(fgets(buf, 255, tp)) { - if(strstr(buf, "INLINE")) + while (fgets(buf, 255, tp)) { + if (strstr(buf, "INLINE")) continue; - if(strstr(buf, "LINK")) + if (strstr(buf, "LINK")) break; fprintf(fp, "%s", buf); } @@ -22,13 +24,15 @@ static void filt_railway(char* fpath) { unlink(tmppath); } -int main_railway() { - fileheader_t mhdr; - char genbuf[200]; - int from, to, time_go, time_reach; - char tt[2], type[2]; - char command[256], buf[8]; - char *addr[]= { +int +main_railway() +{ + fileheader_t mhdr; + char genbuf[200]; + int from, to, time_go, time_reach; + char tt[2], type[2]; + char command[256], buf[8]; + char *addr[] = { "°ò¶©", "¤K°ô", "¤C°ô", "¤°ô", "¦Á¤î", "«n´ä", "ªQ¤s", "¥x¥_", "¸UµØ", "ªO¾ô", "¾ðªL", "¤s¨Î", "Åaºq", "®ç¶é", "¤ºÃc", "¤¤Ãc", "®H¤ß", "·¨±ö", "´ò¤f", "·sÂ×", "¦Ë¥_", "·s¦Ë", "»¤s", "±T³»", "¦Ë«n", "³y¾ô", "Â×´I", @@ -37,81 +41,81 @@ int main_railway() { "]®ß", "«n¶Õ", "»ÉÆr", "¤T¸q", "³Ó¿³", "®õ¦w", "¦Z¨½", "Â×ì", "¼æ¤l", "¥x¤¤", "¯Q¤é", "¦¨¥\\", "¹ü¤Æ", "ªá¾Â", "ûªL", "¥Ã¹t", "ªÀÀY", "¥Ð¤¤", "¤G¤ô", "ªL¤º", "¥Ûºh", "¤æ¤»", "¤æ«n", "¥ÛÀt", "¤jªL", - "¥Á¶¯", "¹Å¸q", "¤ô¤W", "«n¹t", "«á¾À", "·sÀç", "¬hÀç", "ªL»ñÀç", - "¶©¥Ð", "©ÞªL", "µ½¤Æ", "·s¥«", "¥Ã±d", "¥x«n", "«O¦w", "¤¤¬w", - "¤j´ò", "¸ô¦Ë", "©£¤s", "¾ôÀY", "·£±ê", "¥ªÀç", "°ª¶¯", "»ñ¤s", + "¥Á¶¯", "¹Å¸q", "¤ô¤W", "«n¹t", "«á¾À", "·sÀç", "¬hÀç", "ªL»ñÀç", + "¶©¥Ð", "©ÞªL", "µ½¤Æ", "·s¥«", "¥Ã±d", "¥x«n", "«O¦w", "¤¤¬w", + "¤j´ò", "¸ô¦Ë", "©£¤s", "¾ôÀY", "·£±ê", "¥ªÀç", "°ª¶¯", "»ñ¤s", "¤E¦±°ó", "«ÌªF", NULL, NULL }; - + setutmpmode(RAIL_WAY); clear(); - move(0,25); + move(0, 25); prints("\033[1;37;45m ¤õ¨®¬d¸ß¨t²Î \033[1;44;33m§@ªÌ:Heat\033[m"); - move(1,0); + move(1, 0); outs("\033[1;33m\n" -" 1.°ò¶© 16.¤¤Ãc 31.Às´ä 46.»ÉÆr 61.¥Ð¤¤ 76.ªL»ñÀç 91.°ª¶¯\n" -" 2.¤K°ô 17.®H¤ß 32.¥Õ¨F¤Ù 47.¤T¸q 62.¤G¤ô 77.¶©¥Ð 92.»ñ¤s\n" -" 3.¤C°ô 18.·¨±ö 33.·s®H 48.³Ó¿³ 63.ªL¤º 78.©ÞªL 93.¤E¦±°ó\n" -" 4.¤°ô 19.´ò¤f 34.³q¾] 49.®õ¦w 64.¥Ûºh 79.µ½¤Æ 94.«ÌªF\n" -" 5.¦Á¤î 20.·sÂ× 35.b¸Ì 50.¦Z¨½ 65.¤æ¤» 80.·s¥«\n" -" 6.«n´ä 21.¦Ë¥_ 36.¤é«n 51.Â×ì 66.¤æ«n 81.¥Ã±d\n" -" 7.ªQ¤s 22.·s¦Ë 37.¤j¥Ò 52.¼æ¤l 67.¥ÛÀt 82.¥x«n\n" -" 8.¥x¥_ 23.»¤s 38.»O¤¤´ä 53.¥x¤¤ 68.¤jªL 83.«O¦w\n" -" 9.¸UµØ 24.±T³» 39.²M¤ô 54.¯Q¤é 69.¥Á¶¯ 84.¤¤¬w\n" -"10.ªO¾ô 25.¦Ë«n 40.¨F³À 55.¦¨¥\\ 70.¹Å¸q 85.¤j´ò\n" -"11.¾ðªL 26.³y¾ô 41.Às¤« 56.¹ü¤Æ 71.¤ô¤W 86.¸ô¦Ë\n" -"12.¤s¨Î 27.Â×´I 42.¤j¨{ 57.ªá¾Â 72.«n¹t 87.©£¤s\n" -"13.Åaºq 28.½Í¤å 43.°l¤À 58.ûªL 73.«á¾À 88.¾ôÀY\n" -"14.®ç¶é 29.¤j¤s 44.]®ß 59.¥Ã¹t 74.·sÀç 89.·£±ê\n" -"15.¤ºÃc 30.«áÀs 45.«n¶Õ 60.ªÀÀY 75.¬hÀç 90.¥ªÀç\033[m"); + " 1.°ò¶© 16.¤¤Ãc 31.Às´ä 46.»ÉÆr 61.¥Ð¤¤ 76.ªL»ñÀç 91.°ª¶¯\n" + " 2.¤K°ô 17.®H¤ß 32.¥Õ¨F¤Ù 47.¤T¸q 62.¤G¤ô 77.¶©¥Ð 92.»ñ¤s\n" + " 3.¤C°ô 18.·¨±ö 33.·s®H 48.³Ó¿³ 63.ªL¤º 78.©ÞªL 93.¤E¦±°ó\n" + " 4.¤°ô 19.´ò¤f 34.³q¾] 49.®õ¦w 64.¥Ûºh 79.µ½¤Æ 94.«ÌªF\n" + " 5.¦Á¤î 20.·sÂ× 35.b¸Ì 50.¦Z¨½ 65.¤æ¤» 80.·s¥«\n" + " 6.«n´ä 21.¦Ë¥_ 36.¤é«n 51.Â×ì 66.¤æ«n 81.¥Ã±d\n" + " 7.ªQ¤s 22.·s¦Ë 37.¤j¥Ò 52.¼æ¤l 67.¥ÛÀt 82.¥x«n\n" + " 8.¥x¥_ 23.»¤s 38.»O¤¤´ä 53.¥x¤¤ 68.¤jªL 83.«O¦w\n" + " 9.¸UµØ 24.±T³» 39.²M¤ô 54.¯Q¤é 69.¥Á¶¯ 84.¤¤¬w\n" + "10.ªO¾ô 25.¦Ë«n 40.¨F³À 55.¦¨¥\\ 70.¹Å¸q 85.¤j´ò\n" + "11.¾ðªL 26.³y¾ô 41.Às¤« 56.¹ü¤Æ 71.¤ô¤W 86.¸ô¦Ë\n" + "12.¤s¨Î 27.Â×´I 42.¤j¨{ 57.ªá¾Â 72.«n¹t 87.©£¤s\n" + "13.Åaºq 28.½Í¤å 43.°l¤À 58.ûªL 73.«á¾À 88.¾ôÀY\n" + "14.®ç¶é 29.¤j¤s 44.]®ß 59.¥Ã¹t 74.·sÀç 89.·£±ê\n" + "15.¤ºÃc 30.«áÀs 45.«n¶Õ 60.ªÀÀY 75.¬hÀç 90.¥ªÀç\033[m"); getdata(17, 0, "\033[1;35m§A½T©wn·j´M¶Ü?[y/n]:\033[m", buf, 2, LCECHO); - if(buf[0] != 'y' && buf[0] != 'Y') + if (buf[0] != 'y' && buf[0] != 'Y') return 0; - while(1) - if(getdata(18, 0, "\033[1;35m½Ð¿é¤J°_¯¸(1-94):\033[m", buf, 3, LCECHO) && - (from = atoi(buf)) >= 1 && from <= 94) + while (1) + if (getdata(18, 0, "\033[1;35m½Ð¿é¤J°_¯¸(1-94):\033[m", buf, 3, LCECHO) && + (from = atoi(buf)) >= 1 && from <= 94) break; - while(1) - if(getdata(18, 40, "\033[1;35m½Ð¿é¤J¥Øªº¦a(1-94):\033[m", - buf, 3, LCECHO) && - (to = atoi(buf)) >= 1 && to <= 94) + while (1) + if (getdata(18, 40, "\033[1;35m½Ð¿é¤J¥Øªº¦a(1-94):\033[m", + buf, 3, LCECHO) && + (to = atoi(buf)) >= 1 && to <= 94) break; - while(1) - if(getdata(19, 0, "\033[1;35m½Ð¿é¤J®É¶¡°Ï¬q(0-23) ¥Ñ:\033[m", - buf,3,LCECHO) && - (time_go = atoi(buf)) >= 0 && time_go <= 23) + while (1) + if (getdata(19, 0, "\033[1;35m½Ð¿é¤J®É¶¡°Ï¬q(0-23) ¥Ñ:\033[m", + buf, 3, LCECHO) && + (time_go = atoi(buf)) >= 0 && time_go <= 23) break; - while(1) - if(getdata(19, 40, "\033[1;35m¨ì:\033[m", buf, 3, LCECHO) && - (time_reach=atoi(buf)) >= 0 && time_reach <= 23) + while (1) + if (getdata(19, 40, "\033[1;35m¨ì:\033[m", buf, 3, LCECHO) && + (time_reach = atoi(buf)) >= 0 && time_reach <= 23) break; - while(1) - if(getdata(20, 0, "\033[1;35m·Q¬d¸ß 1:¹ï¸¹§Ö¨® 2:´¶³q¥§Ö\033[m", - type,2,LCECHO) && (type[0] == '1' || type[0] == '2')) + while (1) + if (getdata(20, 0, "\033[1;35m·Q¬d¸ß 1:¹ï¸¹§Ö¨® 2:´¶³q¥§Ö\033[m", + type, 2, LCECHO) && (type[0] == '1' || type[0] == '2')) break; - while(1) - if(getdata(21, 0, "\033[1;35m±ý¬d¸ß 1:¥Xµo®É¶¡ 2:¨ì¹F®É¶¡\033[m", - tt, sizeof(tt), LCECHO) && - (tt[0]=='1' || tt[0]=='2')) + while (1) + if (getdata(21, 0, "\033[1;35m±ý¬d¸ß 1:¥Xµo®É¶¡ 2:¨ì¹F®É¶¡\033[m", + tt, sizeof(tt), LCECHO) && + (tt[0] == '1' || tt[0] == '2')) break; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mhdr); strcpy(mhdr.owner, "Ptt·j´M¾¹"); strncpy(mhdr.title, "¤õ¨®®É¨è·j´Mµ²ªG", TTLEN); - sprintf(command,"echo \"from-station=%s&to-station=%s" + sprintf(command, "echo \"from-station=%s&to-station=%s" "&from-time=%02d00&to-time=%02d00&tt=%s&type=%s\" | " "lynx -dump -post_data " "\"http://www.railway.gov.tw/cgi-bin/timetk.cgi\" > %s.railway", addr[from - 1], addr[to - 1], time_go, time_reach, (tt[0] == '1') ? "start" : "arriv", (type[0] == '1') ? "fast" : "slow", genbuf); - + system(command); filt_railway(genbuf); sethomedir(genbuf, cuser.userid); - if(append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) + if (append_record(genbuf, &mhdr, sizeof(mhdr)) == -1) return -1; hpressanykey("\033[1;31m§ÚÌ·|§â·j´Mµ²ªG«Ü§Ö´N±Hµ¹§Aò ^_^\033[m"); return 0; diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 06a26d32..9c129dc0 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -1,7 +1,7 @@ -/* $Id: passwd.c,v 1.6 2002/07/04 19:46:16 in2 Exp $ */ +/* $Id: passwd.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static int semid = -1; +static int semid = -1; #ifndef SEM_R #define SEM_R 0400 @@ -13,19 +13,21 @@ static int semid = -1; #ifndef __FreeBSD__ union semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ - u_short *array; /* array for GETALL & SETALL */ - struct seminfo *__buf; /* buffer for IPC_INFO */ + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ + u_short *array; /* array for GETALL & SETALL */ + struct seminfo *__buf; /* buffer for IPC_INFO */ }; #endif -int passwd_init() { +int +passwd_init() +{ semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A | IPC_CREAT | IPC_EXCL); - if(semid == -1) { - if(errno == EEXIST) { + if (semid == -1) { + if (errno == EEXIST) { semid = semget(PASSWDSEM_KEY, 1, SEM_R | SEM_A); - if(semid == -1) { + if (semid == -1) { perror("semget"); exit(1); } @@ -34,10 +36,10 @@ int passwd_init() { exit(1); } } else { - union semun s; - + union semun s; + s.val = 1; - if(semctl(semid, 0, SETVAL, s) == -1) { + if (semctl(semid, 0, SETVAL, s) == -1) { perror("semctl"); exit(1); } @@ -46,23 +48,27 @@ int passwd_init() { return 0; } -int passwd_update_money(int num) { - userec_t user; - if(num < 1 || num > MAX_USERS) - return -1; +int +passwd_update_money(int num) +{ + userec_t user; + if (num < 1 || num > MAX_USERS) + return -1; passwd_query(num, &user); - if( SHM->loaded ) + if (SHM->loaded) user.money = moneyof(num); passwd_update(num, &user); return 0; -} +} -int passwd_update(int num, userec_t *buf) { - int pwdfd; - if(num < 1 || num > MAX_USERS) +int +passwd_update(int num, userec_t * buf) +{ + int pwdfd; + if (num < 1 || num > MAX_USERS) return -1; buf->money = moneyof(num); - if( (pwdfd = open(fn_passwd, O_RDWR)) < 0 ) + if ((pwdfd = open(fn_passwd, O_RDWR)) < 0) exit(1); lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); write(pwdfd, buf, sizeof(userec_t)); @@ -70,11 +76,13 @@ int passwd_update(int num, userec_t *buf) { return 0; } -int passwd_query(int num, userec_t *buf) { - int pwdfd; - if(num < 1 || num > MAX_USERS) +int +passwd_query(int num, userec_t * buf) +{ + int pwdfd; + if (num < 1 || num > MAX_USERS) return -1; - if( (pwdfd = open(fn_passwd, O_RDONLY)) < 0 ) + if ((pwdfd = open(fn_passwd, O_RDONLY)) < 0) exit(1); lseek(pwdfd, sizeof(userec_t) * (num - 1), SEEK_SET); read(pwdfd, buf, sizeof(userec_t)); @@ -82,30 +90,36 @@ int passwd_query(int num, userec_t *buf) { return 0; } -int passwd_apply(int (*fptr)(userec_t *)) { - int i; - userec_t user; - for(i = 0; i < MAX_USERS; i++){ +int +passwd_apply(int (*fptr) (userec_t *)) +{ + int i; + userec_t user; + for (i = 0; i < MAX_USERS; i++) { passwd_query(i + 1, &user); - if((*fptr)(&user) == QUIT) + if ((*fptr) (&user) == QUIT) return QUIT; } return 0; } -void passwd_lock() { - struct sembuf buf = { 0, -1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { +void +passwd_lock() +{ + struct sembuf buf = {0, -1, SEM_UNDO}; + + if (semop(semid, &buf, 1)) { perror("semop"); exit(1); } } -void passwd_unlock() { - struct sembuf buf = { 0, 1, SEM_UNDO }; - - if(semop(semid, &buf, 1)) { +void +passwd_unlock() +{ + struct sembuf buf = {0, 1, SEM_UNDO}; + + if (semop(semid, &buf, 1)) { perror("semop"); exit(1); } diff --git a/mbbsd/read.c b/mbbsd/read.c index fe8c871d..3d661479 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -1,11 +1,11 @@ -/* $Id: read.c,v 1.7 2002/07/02 16:13:37 in2 Exp $ */ +/* $Id: read.c,v 1.8 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define MAXPATHLEN 256 static fileheader_t *headers = NULL; -static int last_line; -static int hit_thread; +static int last_line; +static int hit_thread; #include <sys/mman.h> @@ -13,88 +13,76 @@ static int hit_thread; /* Tag List ¼ÐÅÒ */ /* ----------------------------------------------------- */ void -UnTagger (int locus) +UnTagger(int locus) { - if (locus > TagNum) return; + if (locus > TagNum) + return; - TagNum--; + TagNum--; - if (TagNum > locus) - memcpy(&TagList[locus], &TagList[locus + 1], - (TagNum - locus) * sizeof(TagItem)); + if (TagNum > locus) + memcpy(&TagList[locus], &TagList[locus + 1], + (TagNum - locus) * sizeof(TagItem)); } int Tagger(time_t chrono, int recno, int mode) -{ - int head, tail, posi = 0, comp; - - for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) - { - posi = (head + tail) >> 1; - comp = TagList[posi].chrono - chrono; - if (!comp) - { - break; - } - else if (comp < 0) - { - head = posi + 1; - } - else - { - tail = posi - 1; - } - } - - if (mode == TAG_NIN) - { - if (!comp && recno) /* µ´¹ïÄYÂÔ¡G³s recno ¤@°_¤ñ¹ï */ - comp = recno - TagList[posi].recno; - return comp; +{ + int head, tail, posi = 0, comp; - } + for (head = 0, tail = TagNum - 1, comp = 1; head <= tail;) { + posi = (head + tail) >> 1; + comp = TagList[posi].chrono - chrono; + if (!comp) { + break; + } else if (comp < 0) { + head = posi + 1; + } else { + tail = posi - 1; + } + } - if (!comp) - { - if (mode != TAG_TOGGLE) - return NA; + if (mode == TAG_NIN) { + if (!comp && recno) /* µ´¹ïÄYÂÔ¡G³s recno ¤@°_¤ñ¹ï */ + comp = recno - TagList[posi].recno; + return comp; - TagNum--; - memcpy(&TagList[posi], &TagList[posi + 1], - (TagNum - posi) * sizeof(TagItem)); - } - else if (TagNum < MAXTAGS) - { - TagItem *tagp, buf[MAXTAGS]; - - tail = (TagNum - head) * sizeof(TagItem); - tagp = &TagList[head]; - memcpy(buf, tagp, tail); - tagp->chrono = chrono; - tagp->recno = recno; - memcpy(++tagp, buf, tail); - TagNum++; - } - else - { - bell(); - return 0; /* full */ - } - return YEA; + } + if (!comp) { + if (mode != TAG_TOGGLE) + return NA; + + TagNum--; + memcpy(&TagList[posi], &TagList[posi + 1], + (TagNum - posi) * sizeof(TagItem)); + } else if (TagNum < MAXTAGS) { + TagItem *tagp, buf[MAXTAGS]; + + tail = (TagNum - head) * sizeof(TagItem); + tagp = &TagList[head]; + memcpy(buf, tagp, tail); + tagp->chrono = chrono; + tagp->recno = recno; + memcpy(++tagp, buf, tail); + TagNum++; + } else { + bell(); + return 0; /* full */ + } + return YEA; } void -EnumTagName( char *fname, int locus) -{ - sprintf(fname, "M.%d.A", (int) TagList[locus].chrono); +EnumTagName(char *fname, int locus) +{ + sprintf(fname, "M.%d.A", (int)TagList[locus].chrono); } void -EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus) -{ - get_record(direct, fhdr, sizeof(fileheader_t), TagList[locus].recno); +EnumTagFhdr(fileheader_t * fhdr, char *direct, int locus) +{ + get_record(direct, fhdr, sizeof(fileheader_t), TagList[locus].recno); } /* -1 : ¨ú®ø */ @@ -103,21 +91,20 @@ EnumTagFhdr(fileheader_t *fhdr, char *direct, int locus) int AskTag(char *msg) -{ - char buf[80]; - int num; - - num = TagNum; - sprintf(buf, "¡» %s A)¤å³¹ T)¼Ð°O Q)uit?", msg); - switch (rget(b_lines-1, buf)) - { - case 'q': - num = -1; - break; - case 'a': - num = 0; - } - return num; +{ + char buf[80]; + int num; + + num = TagNum; + sprintf(buf, "¡» %s A)¤å³¹ T)¼Ð°O Q)uit?", msg); + switch (rget(b_lines - 1, buf)) { + case 'q': + num = -1; + break; + case 'a': + num = 0; + } + return num; } @@ -125,98 +112,95 @@ AskTag(char *msg) #define BATCH_SIZE 65536 -char * -f_map (char *fpath, int *fsize) +char * +f_map(char *fpath, int *fsize) { - int fd, size; - struct stat st; - - if ((fd = open(fpath, O_RDONLY)) < 0) - return (char *) -1; - - if (fstat(fd, &st) || !S_ISREG(st.st_mode) || (size = st.st_size) <= 0) - { - close(fd); - return (char *) -1; - } + int fd, size; + struct stat st; + + if ((fd = open(fpath, O_RDONLY)) < 0) + return (char *)-1; - fpath = (char *) mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); - close(fd); - *fsize = size; - return fpath; + if (fstat(fd, &st) || !S_ISREG(st.st_mode) || (size = st.st_size) <= 0) { + close(fd); + return (char *)-1; + } + fpath = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); + close(fd); + *fsize = size; + return fpath; } static int TagThread(char *direct) -{ - int fsize, count; - char *title, *fimage; - fileheader_t *head, *tail; +{ + int fsize, count; + char *title, *fimage; + fileheader_t *head, *tail; - fimage = f_map(direct, &fsize); - if ( fimage == (char *) -1) - return DONOTHING; + fimage = f_map(direct, &fsize); + if (fimage == (char *)-1) + return DONOTHING; - head = (fileheader_t *) fimage; - tail = (fileheader_t *) (fimage + fsize); - count = 0; - do - { - count++; - title = subject(head->title); - if (!strncmp( currtitle, title,TTLEN)) - { - if (!Tagger(atoi (head->filename + 2), count, TAG_INSERT)) - break; - } - } while (++head < tail); + head = (fileheader_t *) fimage; + tail = (fileheader_t *) (fimage + fsize); + count = 0; + do { + count++; + title = subject(head->title); + if (!strncmp(currtitle, title, TTLEN)) { + if (!Tagger(atoi(head->filename + 2), count, TAG_INSERT)) + break; + } + } while (++head < tail); - munmap(fimage, fsize); - return FULLUPDATE; + munmap(fimage, fsize); + return FULLUPDATE; } int TagPruner(int bid) -{ - boardheader_t *bp; - bp = getbcache(bid); - if ( strcmp(bp->brdname, "Security" ) == 0 ) +{ + boardheader_t *bp; + bp = getbcache(bid); + if (strcmp(bp->brdname, "Security") == 0) return DONOTHING; - if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) - { - if(getans("§R°£©Ò¦³¼Ð°O[N]?") != 'y') - return FULLUPDATE; - delete_range(currdirect, 0, 0); - TagNum = 0; - if(bid>0); - setbtotal(bid); - return NEWDIRECT; - } - return DONOTHING; + if (TagNum && ((currstat != READING) || (currmode & MODE_BOARD))) { + if (getans("§R°£©Ò¦³¼Ð°O[N]?") != 'y') + return FULLUPDATE; + delete_range(currdirect, 0, 0); + TagNum = 0; + if (bid > 0); + setbtotal(bid); + return NEWDIRECT; + } + return DONOTHING; } /* ----------------------------------------------------- */ /* cursor & reading record position control */ /* ----------------------------------------------------- */ -keeploc_t *getkeep(char *s, int def_topline, int def_cursline) { +keeploc_t * +getkeep(char *s, int def_topline, int def_cursline) +{ static struct keeploc_t *keeplist = NULL; struct keeploc_t *p; - void *malloc(); + void *malloc(); - if(def_cursline >= 0) - for(p = keeplist; p; p = p->next) { - if(!strcmp(s, p->key)) { - if(p->crs_ln < 1) + if (def_cursline >= 0) + for (p = keeplist; p; p = p->next) { + if (!strcmp(s, p->key)) { + if (p->crs_ln < 1) p->crs_ln = 1; return p; } } else def_cursline = -def_cursline; - p = (keeploc_t *)malloc(sizeof(keeploc_t)); + p = (keeploc_t *) malloc(sizeof(keeploc_t)); p->key = (char *)malloc(strlen(s) + 1); strcpy(p->key, s); p->top_ln = def_topline; @@ -225,66 +209,71 @@ keeploc_t *getkeep(char *s, int def_topline, int def_cursline) { return (keeplist = p); } -void fixkeep(char *s, int first) { - keeploc_t *k; - +void +fixkeep(char *s, int first) +{ + keeploc_t *k; + k = getkeep(s, 1, 1); - if(k->crs_ln >= first) { + if (k->crs_ln >= first) { k->crs_ln = (first == 1 ? 1 : first - 1); k->top_ln = (first < 11 ? 1 : first - 10); } } /* calc cursor pos and show cursor correctly */ -static int cursor_pos(keeploc_t *locmem, int val, int from_top) { - int top; - - if(val > last_line) { +static int +cursor_pos(keeploc_t * locmem, int val, int from_top) +{ + int top; + + if (val > last_line) { bell(); val = last_line; } - if(val <= 0) { + if (val <= 0) { bell(); val = 1; } - top = locmem->top_ln; - if(val >= top && val < top + p_lines) { + if (val >= top && val < top + p_lines) { cursor_clear(3 + locmem->crs_ln - top, 0); locmem->crs_ln = val; cursor_show(3 + val - top, 0); return DONOTHING; } locmem->top_ln = val - from_top; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = val; return PARTUPDATE; } -static int move_cursor_line(keeploc_t *locmem, int mode) { - int top, crs; - int reload = 0; +static int +move_cursor_line(keeploc_t * locmem, int mode) +{ + int top, crs; + int reload = 0; top = locmem->top_ln; crs = locmem->crs_ln; - if(mode == READ_PREV) { - if(crs <= top) { + if (mode == READ_PREV) { + if (crs <= top) { top -= p_lines - 1; - if(top < 1) + if (top < 1) top = 1; reload = 1; } - if(--crs < 1) { + if (--crs < 1) { crs = 1; reload = -1; } - } else if(mode == READ_NEXT) { - if(crs >= top + p_lines - 1) { + } else if (mode == READ_NEXT) { + if (crs >= top + p_lines - 1) { top += p_lines - 1; reload = 1; } - if(++crs > last_line) { + if (++crs > last_line) { crs = last_line; reload = -1; } @@ -294,86 +283,87 @@ static int move_cursor_line(keeploc_t *locmem, int mode) { return reload; } -static int thread(keeploc_t *locmem, int stype) { - static char a_ans[32], t_ans[32]; - char ans[32], s_pmt[64]; - register char *tag, *query = NULL; - register int now, pos, match, near = 0; - fileheader_t fh; - int circulate_flag = 1; /* circulate at end or begin */ +static int +thread(keeploc_t * locmem, int stype) +{ + static char a_ans[32], t_ans[32]; + char ans[32], s_pmt[64]; + register char *tag, *query = NULL; + register int now, pos, match, near = 0; + fileheader_t fh; + int circulate_flag = 1; /* circulate at end or begin */ match = hit_thread = 0; now = pos = locmem->crs_ln; - if(stype == 'A') { - if(!*currowner) + if (stype == 'A') { + if (!*currowner) return DONOTHING; str_lower(a_ans, currowner); query = a_ans; circulate_flag = 0; stype = 0; - } else if(stype == 'a') { - if(!*currowner) + } else if (stype == 'a') { + if (!*currowner) return DONOTHING; str_lower(a_ans, currowner); query = a_ans; circulate_flag = 0; stype = RS_FORWARD; - } else if(stype == '/') { - if(!*t_ans) + } else if (stype == '/') { + if (!*t_ans) return DONOTHING; query = t_ans; circulate_flag = 0; stype = RS_TITLE | RS_FORWARD; - } else if(stype == '?') { - if(!*t_ans) + } else if (stype == '?') { + if (!*t_ans) return DONOTHING; circulate_flag = 0; query = t_ans; stype = RS_TITLE; - } else if(stype & RS_RELATED) { + } else if (stype & RS_RELATED) { tag = headers[pos - locmem->top_ln].title; - if(stype & RS_CURRENT) { - if(stype & RS_FIRST) { - if(!strncmp(currtitle, tag, TTLEN)) + if (stype & RS_CURRENT) { + if (stype & RS_FIRST) { + if (!strncmp(currtitle, tag, TTLEN)) return DONOTHING; near = 0; } query = currtitle; } else { query = subject(tag); - if(stype & RS_FIRST) { - if(query == tag) + if (stype & RS_FIRST) { + if (query == tag) return DONOTHING; near = 0; } } - } else if(!(stype & RS_THREAD)) { + } else if (!(stype & RS_THREAD)) { query = (stype & RS_TITLE) ? t_ans : a_ans; - if(!*query && query == a_ans) { - if(*currowner) + if (!*query && query == a_ans) { + if (*currowner) strcpy(a_ans, currowner); else if (*currauthor) strcpy(a_ans, currauthor); } - sprintf(s_pmt, "%s·j´M%s [%s] ",(stype & RS_FORWARD) ? "©¹«á":"©¹«e", + sprintf(s_pmt, "%s·j´M%s [%s] ", (stype & RS_FORWARD) ? "©¹«á" : "©¹«e", (stype & RS_TITLE) ? "¼ÐÃD" : "§@ªÌ", query); getdata(b_lines - 1, 0, s_pmt, ans, sizeof(ans), DOECHO); - if(*ans) + if (*ans) strcpy(query, ans); - else if(*query == '\0') + else if (*query == '\0') return DONOTHING; } - tag = fh.owner; do { - if(!circulate_flag || stype & RS_RELATED) { - if(stype & RS_FORWARD) { - if(++now > last_line) + if (!circulate_flag || stype & RS_RELATED) { + if (stype & RS_FORWARD) { + if (++now > last_line) return DONOTHING; } else { - if(--now <= 0 || now < pos - 300) { - if((stype & RS_FIRST) && (near)) { + if (--now <= 0 || now < pos - 300) { + if ((stype & RS_FIRST) && (near)) { hit_thread = 1; return cursor_pos(locmem, near, 10); } @@ -381,64 +371,64 @@ static int thread(keeploc_t *locmem, int stype) { } } } else { - if(stype & RS_FORWARD) { - if(++now > last_line) + if (stype & RS_FORWARD) { + if (++now > last_line) now = 1; - } else if(--now <= 0) + } else if (--now <= 0) now = last_line; } - + get_record(currdirect, &fh, sizeof(fileheader_t), now); - - if(fh.owner[0] == '-') + + if (fh.owner[0] == '-') continue; - - if(stype & RS_THREAD) { - if(strncasecmp(fh.title, str_reply, 3)) { + + if (stype & RS_THREAD) { + if (strncasecmp(fh.title, str_reply, 3)) { hit_thread = 1; return cursor_pos(locmem, now, 10); } continue; } - - if(stype & RS_TITLE) + if (stype & RS_TITLE) tag = subject(fh.title); - - if(((stype & RS_RELATED) && !strncmp(tag, query, 40)) || - (!(stype & RS_RELATED) && ((query == currowner) ? - !strcmp(tag, query) : - strstr_lower(tag, query)))) { - if((stype & RS_FIRST) && tag != fh.title) { + + if (((stype & RS_RELATED) && !strncmp(tag, query, 40)) || + (!(stype & RS_RELATED) && ((query == currowner) ? + !strcmp(tag, query) : + strstr_lower(tag, query)))) { + if ((stype & RS_FIRST) && tag != fh.title) { near = now; continue; } - hit_thread = 1; match = cursor_pos(locmem, now, 10); - if((!(stype & RS_CURRENT)) && - (stype & RS_RELATED) && - strncmp(currtitle, query, TTLEN)) { + if ((!(stype & RS_CURRENT)) && + (stype & RS_RELATED) && + strncmp(currtitle, query, TTLEN)) { strncpy(currtitle, query, TTLEN); match = PARTUPDATE; } break; } - } while(now != pos); - + } while (now != pos); + return match; } #ifdef INTERNET_EMAIL -static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { - int i; - char buf[STRLEN]; - char *p; - +static void +mail_forward(fileheader_t * fhdr, char *direct, int mode) +{ + int i; + char buf[STRLEN]; + char *p; + strncpy(buf, direct, sizeof(buf)); - if((p = strrchr(buf, '/'))) + if ((p = strrchr(buf, '/'))) *p = '\0'; - switch(i = doforward(buf, fhdr, mode)) { + switch (i = doforward(buf, fhdr, mode)) { case 0: outmsg(msg_fwd_ok); break; @@ -456,150 +446,144 @@ static void mail_forward(fileheader_t *fhdr, char *direct, int mode) { } #endif -static int select_read(keeploc_t *locmem, int sr_mode) { - register char *tag,*query,*temp; - fileheader_t fh; - char fpath[80], genbuf[MAXPATHLEN], buf3[5]; - char static t_ans[TTLEN+1]=""; - char static a_ans[TTLEN+1]=""; - int fd, fr, size = sizeof(fileheader_t); - struct stat st; -/* rocker.011018: make a reference number for process article */ - int reference = 0; - - if((currmode & MODE_SELECT)) +static int +select_read(keeploc_t * locmem, int sr_mode) +{ + register char *tag, *query, *temp; + fileheader_t fh; + char fpath[80], genbuf[MAXPATHLEN], buf3[5]; + char static t_ans[TTLEN + 1] = ""; + char static a_ans[TTLEN + 1] = ""; + int fd, fr, size = sizeof(fileheader_t); + struct stat st; + /* rocker.011018: make a reference number for process article */ + int reference = 0; + + if ((currmode & MODE_SELECT)) return -1; - if(sr_mode == RS_TITLE) + if (sr_mode == RS_TITLE) query = subject(headers[locmem->crs_ln - locmem->top_ln].title); - else if(sr_mode == RS_NEWPOST) - { + else if (sr_mode == RS_NEWPOST) { strcpy(buf3, "Re: "); query = buf3; - } - else - { - char buff[80]; - char newdata[35]; + } else { + char buff[80]; + char newdata[35]; query = (sr_mode == RS_RELATED) ? t_ans : a_ans; sprintf(buff, "·j´M%s [%s] ", (sr_mode == RS_RELATED) ? "¼ÐÃD" : "§@ªÌ", query); getdata(b_lines, 0, buff, newdata, sizeof(newdata), DOECHO); - if( newdata[0] ) + if (newdata[0]) strcpy(query, newdata); - if(!(*query)) + if (!(*query)) return DONOTHING; } - if((fd = open(currdirect, O_RDONLY, 0)) != -1) { - sprintf(genbuf,"SR.%s",cuser.userid); - if(currstat==RMAIL) - sethomefile(fpath,cuser.userid,genbuf); + if ((fd = open(currdirect, O_RDONLY, 0)) != -1) { + sprintf(genbuf, "SR.%s", cuser.userid); + if (currstat == RMAIL) + sethomefile(fpath, cuser.userid, genbuf); else - setbfile(fpath,currboard,genbuf); - if(((fr = open(fpath,O_WRONLY | O_CREAT | O_TRUNC,0600)) != -1)) { - switch(sr_mode) { + setbfile(fpath, currboard, genbuf); + if (((fr = open(fpath, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1)) { + switch (sr_mode) { case RS_TITLE: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = subject(fh.title); - if(!strncmp(tag, query, 40)) - { + if (!strncmp(tag, query, 40)) { fh.money = reference | FHR_REFERENCE; - write(fr,&fh,size); + write(fr, &fh, size); } } break; case RS_RELATED: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.title; - if(strcasestr(tag,query)) - { + if (strcasestr(tag, query)) { fh.money = reference | FHR_REFERENCE; - write(fr,&fh,size); + write(fr, &fh, size); } } break; case RS_NEWPOST: - while(read(fd, &fh, size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.title; temp = strstr(tag, query); - if(temp == NULL || temp != tag) - { + if (temp == NULL || temp != tag) { write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; } } case RS_AUTHOR: - while(read(fd,&fh,size) == size) { + while (read(fd, &fh, size) == size) { ++reference; tag = fh.owner; - if(strcasestr(tag,query)) - { - write(fr,&fh,size); + if (strcasestr(tag, query)) { + write(fr, &fh, size); fh.money = reference | FHR_REFERENCE; } } break; } - fstat(fr,&st); + fstat(fr, &st); close(fr); } close(fd); - if(st.st_size) { + if (st.st_size) { currmode |= MODE_SELECT; - strcpy(currdirect,fpath); + strcpy(currdirect, fpath); } } return st.st_size; } -static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { - int i, mode = DONOTHING; - - switch(ch) { +static int +i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int ch, int bid) +{ + int i, mode = DONOTHING; + + switch (ch) { case 'q': case 'e': case KEY_LEFT: return (currmode & MODE_SELECT) ? board_select() : (currmode & MODE_ETC) ? board_etc() : - (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; + (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; case Ctrl('L'): redoscr(); break; -/* - case Ctrl('C'): - cal(); - return FULLUPDATE; - break; -*/ + /* + * case Ctrl('C'): cal(); return FULLUPDATE; break; + */ case KEY_ESC: - if(KEY_ESC_arg == 'i') { + if (KEY_ESC_arg == 'i') { t_idle(); return FULLUPDATE; } break; case Ctrl('H'): - if(select_read(locmem, RS_NEWPOST)) + if (select_read(locmem, RS_NEWPOST)) return NEWDIRECT; else return READ_REDRAW; case 'a': case 'A': - if(select_read(locmem,RS_AUTHOR)) + if (select_read(locmem, RS_AUTHOR)) return NEWDIRECT; else return READ_REDRAW; case '/': case '?': - if(select_read(locmem,RS_RELATED)) + if (select_read(locmem, RS_RELATED)) return NEWDIRECT; else return READ_REDRAW; case 'S': - if(select_read(locmem,RS_TITLE)) + if (select_read(locmem, RS_TITLE)) return NEWDIRECT; else return READ_REDRAW; @@ -636,8 +620,8 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { case KEY_PGDN: case 'N': case Ctrl('F'): - if(last_line >= locmem->top_ln + p_lines) { - if(last_line > locmem->top_ln + p_lines) + if (last_line >= locmem->top_ln + p_lines) { + if (last_line > locmem->top_ln + p_lines) locmem->top_ln += p_lines; else locmem->top_ln += p_lines - 1; @@ -651,9 +635,9 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { case KEY_PGUP: case Ctrl('B'): case 'P': - if(locmem->top_ln > 1) { + if (locmem->top_ln > 1) { locmem->top_ln -= p_lines; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = locmem->top_ln; return PARTUPDATE; @@ -661,9 +645,9 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { break; case KEY_END: case '$': - if(last_line >= locmem->top_ln + p_lines) { + if (last_line >= locmem->top_ln + p_lines) { locmem->top_ln = last_line - p_lines + 1; - if(locmem->top_ln <= 0) + if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = last_line; return PARTUPDATE; @@ -674,24 +658,24 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { break; case 'F': case 'U': - if(HAS_PERM(PERM_FORWARD)) { + if (HAS_PERM(PERM_FORWARD)) { mail_forward(&headers[locmem->crs_ln - locmem->top_ln], - currdirect, ch /*== 'U'*/); - /*by CharlieL*/ + currdirect, ch /* == 'U' */ ); + /* by CharlieL */ return FULLUPDATE; } break; case Ctrl('Q'): return my_query(headers[locmem->crs_ln - locmem->top_ln].owner); case Ctrl('S'): - if(HAS_PERM(PERM_ACCOUNTS)) { - int id; - userec_t muser; + if (HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; strcpy(currauthor, headers[locmem->crs_ln - locmem->top_ln].owner); stand_title("¨Ï¥ÎªÌ³]©w"); move(1, 0); - if((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))){ + if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))) { memcpy(&muser, &xuser, sizeof(muser)); user_display(&muser, 1); uinfo_query(&muser, 1, id); @@ -700,109 +684,108 @@ static int i_read_key(onekey_t *rcmdlist, keeploc_t *locmem, int ch, int bid) { } break; -/* rocker.011018: ±Ä¥Î·sªºtag¼Ò¦¡ */ + /* rocker.011018: ±Ä¥Î·sªºtag¼Ò¦¡ */ case 't': -/* rocker.011112: ¸Ñ¨M¦Aselect mode¼Ð°O¤å³¹ªº°ÝÃD */ - if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), - (currmode & MODE_SELECT) ? - (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : - locmem->crs_ln, TAG_TOGGLE)) - return POS_NEXT; - return DONOTHING; + /* rocker.011112: ¸Ñ¨M¦Aselect mode¼Ð°O¤å³¹ªº°ÝÃD */ + if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), + (currmode & MODE_SELECT) ? + (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : + locmem->crs_ln, TAG_TOGGLE)) + return POS_NEXT; + return DONOTHING; case Ctrl('C'): - if (TagNum) - { - TagNum = 0; - return FULLUPDATE; - } - return DONOTHING; + if (TagNum) { + TagNum = 0; + return FULLUPDATE; + } + return DONOTHING; case Ctrl('T'): - return TagThread(currdirect); + return TagThread(currdirect); case Ctrl('D'): - return TagPruner(bid); + return TagPruner(bid); case '\n': case '\r': case 'l': case KEY_RIGHT: ch = 'r'; default: - for(i = 0; rcmdlist[i].fptr; i++) { - if(rcmdlist[i].key == ch) { - mode = (*(rcmdlist[i].fptr))(locmem->crs_ln, - &headers[locmem->crs_ln - - locmem->top_ln], currdirect); + for (i = 0; rcmdlist[i].fptr; i++) { + if (rcmdlist[i].key == ch) { + mode = (*(rcmdlist[i].fptr)) (locmem->crs_ln, + &headers[locmem->crs_ln - + locmem->top_ln], currdirect); break; } - if(rcmdlist[i].key == 'h') - if(currmode & (MODE_ETC | MODE_DIGEST)) + if (rcmdlist[i].key == 'h') + if (currmode & (MODE_ETC | MODE_DIGEST)) return DONOTHING; } } return mode; } -void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), onekey_t *rcmdlist, int bidcache) { - keeploc_t *locmem = NULL; - int recbase = 0, mode, ch; - int num = 0, entries = 0; - int i; - int jump = 0; - char genbuf[4]; - char currdirect0[64]; - int last_line0 = last_line; - int hit_thread0 = hit_thread; - fileheader_t *headers0 = headers; - - strcpy(currdirect0 ,currdirect); +void i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache){ + keeploc_t *locmem = NULL; + int recbase = 0, mode, ch; + int num = 0, entries = 0; + int i; + int jump = 0; + char genbuf[4]; + char currdirect0[64]; + int last_line0 = last_line; + int hit_thread0 = hit_thread; + fileheader_t *headers0 = headers; + + strcpy(currdirect0, currdirect); #define FHSZ sizeof(fileheader_t) -// Ptt:³oÃäheaders ¥i¥H°w¹ï¬ÝªOªº³Ì«á60½g°µcache - headers = (fileheader_t *)calloc(p_lines, FHSZ); +//Ptt:³o à äheaders ¥ i ¥ H ° w ¹ ï¬ÝªO ª º³Ì«á60 ½ g ° µcache + headers = (fileheader_t *) calloc(p_lines, FHSZ); strcpy(currdirect, direct); mode = NEWDIRECT; -/* rocker.011018: ¥[¤J·sªºtag¾÷¨î */ + /* rocker.011018: ¥[¤J·sªºtag¾÷¨î */ TagNum = 0; do { /* ¨Ì¾Ú mode Åã¥Ü fileheader */ setutmpmode(cmdmode); - switch(mode) { - case NEWDIRECT: /* ²Ä¤@¦¸¸ü¤J¦¹¥Ø¿ý */ + switch (mode) { + case NEWDIRECT: /* ²Ä¤@¦¸¸ü¤J¦¹¥Ø¿ý */ case DIRCHANGED: - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) ) - last_line=getbtotal(currbid); - else - last_line= get_num_records(currdirect, FHSZ); - - if(mode == NEWDIRECT) { - if(last_line == 0) { - if(curredit & EDIT_ITEM) { + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) + last_line = getbtotal(currbid); + else + last_line = get_num_records(currdirect, FHSZ); + + if (mode == NEWDIRECT) { + if (last_line == 0) { + if (curredit & EDIT_ITEM) { outs("¨S¦³ª««~"); refresh(); goto return_i_read; - } else if(curredit & EDIT_MAIL) { + } else if (curredit & EDIT_MAIL) { outs("¨S¦³¨Ó«H"); refresh(); goto return_i_read; - } else if(currmode & MODE_ETC) { - board_etc(); /* Kaede */ + } else if (currmode & MODE_ETC) { + board_etc(); /* Kaede */ outmsg("©|¥¼¦¬¿ý¨ä¥¦¤å³¹"); refresh(); - } else if(currmode & MODE_DIGEST) { - board_digest(); /* Kaede */ + } else if (currmode & MODE_DIGEST) { + board_digest(); /* Kaede */ outmsg("©|¥¼¦¬¿ý¤åºK"); refresh(); - } else if(currmode & MODE_SELECT) { - board_select(); /* Leeym */ + } else if (currmode & MODE_SELECT) { + board_select(); /* Leeym */ outmsg("¨S¦³¦¹¨t¦Cªº¤å³¹"); refresh(); } else { getdata(b_lines - 1, 0, "¬ÝªO·s¦¨¥ß (P)µoªí¤å³¹ (Q)Â÷¶}¡H[Q] ", genbuf, 4, LCECHO); - if(genbuf[0] == 'p') + if (genbuf[0] == 'p') do_post(); goto return_i_read; } @@ -811,42 +794,41 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one locmem = getkeep(currdirect, num < 1 ? 1 : num, last_line); } recbase = -1; - + case FULLUPDATE: - (*dotitle)(); - + (*dotitle) (); + case PARTUPDATE: - if(last_line < locmem->top_ln + p_lines) { - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST))) - num=getbtotal(currbid); - else + if (last_line < locmem->top_ln + p_lines) { + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) + num = getbtotal(currbid); + else num = get_num_records(currdirect, FHSZ); - - if(last_line != num) { + + if (last_line != num) { last_line = num; recbase = -1; } } - - if(last_line == 0) + if (last_line == 0) goto return_i_read; - else if(recbase != locmem->top_ln) { + else if (recbase != locmem->top_ln) { recbase = locmem->top_ln; - if(recbase > last_line) { + if (recbase > last_line) { recbase = (last_line - p_lines) >> 1; - if(recbase < 1) + if (recbase < 1) recbase = 1; locmem->top_ln = recbase; } - if(bidcache>0 && !(currmode & (MODE_SELECT| MODE_DIGEST)) - && (last_line - recbase) < DIRCACHESIZE ) - entries = get_fileheader_cache(currbid, currdirect, headers, - recbase, p_lines); + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST)) + && (last_line - recbase) < DIRCACHESIZE) + entries = get_fileheader_cache(currbid, currdirect, headers, + recbase, p_lines); else - entries = get_records(currdirect, headers, FHSZ, recbase, - p_lines); + entries = get_records(currdirect, headers, FHSZ, recbase, + p_lines); } - if(locmem->crs_ln > last_line) + if (locmem->crs_ln > last_line) locmem->crs_ln = last_line; move(3, 0); clrtobot(); @@ -856,7 +838,7 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one (*doentry) (locmem->top_ln + i, &headers[i]); case READ_REDRAW: outmsg(curredit & EDIT_ITEM ? - "\033[44m ¨p¤H¦¬Âà \033[30;47m Ä~Äò? \033[m" : + "\033[44m ¨p¤H¦¬Âà \033[30;47m Ä~Äò? \033[m" : curredit & EDIT_MAIL ? msg_mailer : MSG_POSTER); break; case READ_PREV: @@ -874,73 +856,73 @@ void i_read(int cmdmode, char *direct, void (*dotitle)(), void (*doentry)(), one } /* Ū¨úÁä½L¡A¥[¥H³B²z¡A³]©w mode */ - if(!jump) { + if (!jump) { cursor_show(3 + locmem->crs_ln - locmem->top_ln, 0); ch = egetch(); mode = DONOTHING; } else ch = ' '; - if(mode == POS_NEXT) { + if (mode == POS_NEXT) { mode = cursor_pos(locmem, locmem->crs_ln + 1, 1); - if(mode == DONOTHING) + if (mode == DONOTHING) mode = PART_REDRAW; jump = 0; - } else if(ch >= '0' && ch <= '9') { - if((i = search_num(ch, last_line)) != -1) + } else if (ch >= '0' && ch <= '9') { + if ((i = search_num(ch, last_line)) != -1) mode = cursor_pos(locmem, i + 1, 10); } else { - if(!jump) + if (!jump) mode = i_read_key(rcmdlist, locmem, ch, currbid); - while(mode == READ_NEXT || mode == READ_PREV || - mode == RELATE_FIRST || mode == RELATE_NEXT || - mode == RELATE_PREV || mode == THREAD_NEXT || - mode == THREAD_PREV || mode == 'A' || mode == 'a' || - mode == '/' || mode == '?') { - int reload; - - if(mode == READ_NEXT || mode == READ_PREV) + while (mode == READ_NEXT || mode == READ_PREV || + mode == RELATE_FIRST || mode == RELATE_NEXT || + mode == RELATE_PREV || mode == THREAD_NEXT || + mode == THREAD_PREV || mode == 'A' || mode == 'a' || + mode == '/' || mode == '?') { + int reload; + + if (mode == READ_NEXT || mode == READ_PREV) reload = move_cursor_line(locmem, mode); else { reload = thread(locmem, mode); - if(!hit_thread) { + if (!hit_thread) { mode = FULLUPDATE; break; } } - - if(reload == -1) { + + if (reload == -1) { mode = FULLUPDATE; break; - } else if(reload) { + } else if (reload) { recbase = locmem->top_ln; - if(bidcache>0 && !(currmode &(MODE_SELECT| MODE_DIGEST)) - && last_line-recbase<DIRCACHESIZE ) - entries = get_fileheader_cache(currbid, currdirect, - headers, recbase, p_lines); - else - entries = get_records(currdirect, headers, FHSZ, recbase, - p_lines); + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST)) + && last_line - recbase < DIRCACHESIZE) + entries = get_fileheader_cache(currbid, currdirect, + headers, recbase, p_lines); + else + entries = get_records(currdirect, headers, FHSZ, recbase, + p_lines); - if(entries <= 0) { + if (entries <= 0) { last_line = -1; break; } } num = locmem->crs_ln - locmem->top_ln; - if(headers[num].owner[0] != '-') + if (headers[num].owner[0] != '-') mode = i_read_key(rcmdlist, locmem, ch, bidcache); } } - } while(mode != DOQUIT); + } while (mode != DOQUIT); #undef FHSZ - return_i_read: +return_i_read: free(headers); last_line = last_line0; hit_thread = hit_thread0; headers = headers0; - strcpy(currdirect ,currdirect0); + strcpy(currdirect, currdirect0); return; } diff --git a/mbbsd/record.c b/mbbsd/record.c index 36b48847..bc50cbe1 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -1,58 +1,66 @@ -/* $Id: record.c,v 1.6 2002/06/22 18:01:23 ptt Exp $ */ +/* $Id: record.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #undef HAVE_MMAP #define BUFSIZE 512 -static void PttLock(int fd, int size, int mode) { +static void +PttLock(int fd, int size, int mode) +{ static struct flock lock_it; - int ret; - - lock_it.l_whence = SEEK_CUR; /* from current point */ - lock_it.l_start = 0; /* -"- */ - lock_it.l_len = size; /* length of data */ - lock_it.l_type = mode; /* set exclusive/write lock */ - lock_it.l_pid = 0; /* pid not actually interesting */ - while((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); + int ret; + + lock_it.l_whence = SEEK_CUR;/* from current point */ + lock_it.l_start = 0; /* -"- */ + lock_it.l_len = size; /* length of data */ + lock_it.l_type = mode; /* set exclusive/write lock */ + lock_it.l_pid = 0; /* pid not actually interesting */ + while ((ret = fcntl(fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR); } #define safewrite write -int get_num_records(char *fpath, int size) { - struct stat st; - if(stat(fpath, &st) == -1) +int +get_num_records(char *fpath, int size) +{ + struct stat st; + if (stat(fpath, &st) == -1) return 0; return st.st_size / size; } -int get_sum_records(char* fpath, int size) { - struct stat st; - long ans = 0; - FILE* fp; - fileheader_t fhdr; - char buf[200], *p; +int +get_sum_records(char *fpath, int size) +{ + struct stat st; + long ans = 0; + FILE *fp; + fileheader_t fhdr; + char buf[200], *p; - if(!(fp = fopen(fpath, "r"))) + if (!(fp = fopen(fpath, "r"))) return -1; - + strcpy(buf, fpath); p = strrchr(buf, '/') + 1; - - while(fread(&fhdr, size, 1, fp) == 1) { + + while (fread(&fhdr, size, 1, fp) == 1) { strcpy(p, fhdr.filename); - if(stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) + if (stat(buf, &st) == 0 && S_ISREG(st.st_mode) && st.st_nlink == 1) ans += st.st_size; } fclose(fp); return ans / 1024; } -int get_record(char *fpath, void *rptr, int size, int id) { - int fd = -1; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) != -1) { - if(read(fd, rptr, size) == size) { +int +get_record(char *fpath, void *rptr, int size, int id) +{ + int fd = -1; + + if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) != -1) { + if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) != -1) { + if (read(fd, rptr, size) == size) { close(fd); return 0; } @@ -62,17 +70,19 @@ int get_record(char *fpath, void *rptr, int size, int id) { return -1; } -int get_records(char *fpath, void *rptr, int size, int id, int number) { - int fd; - - if(id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) +int +get_records(char *fpath, void *rptr, int size, int id, int number) +{ + int fd; + + if (id < 1 || (fd = open(fpath, O_RDONLY, 0)) == -1) return -1; - if(lseek(fd, (off_t)(size * (id - 1)), SEEK_SET) == -1) { + if (lseek(fd, (off_t) (size * (id - 1)), SEEK_SET) == -1) { close(fd); return 0; } - if((id = read(fd, rptr, size * number)) == -1) { + if ((id = read(fd, rptr, size * number)) == -1) { close(fd); return -1; } @@ -80,84 +90,90 @@ int get_records(char *fpath, void *rptr, int size, int id, int number) { return id / size; } -int substitute_record(char *fpath, void *rptr, int size, int id) { - int fd; +int +substitute_record(char *fpath, void *rptr, int size, int id) +{ + int fd; - if(id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) + if (id < 1 || (fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) return -1; - + lseek(fd, (off_t) (size * (id - 1)), SEEK_SET); PttLock(fd, size, F_WRLCK); safewrite(fd, rptr, size); PttLock(fd, size, F_UNLCK); close(fd); - + return 0; } /* rocker.011022: ÁקKlockÀɶ}±Ò®É¤£¥¿±`Â_½u,³y¦¨¥Ã¤[lock */ static int -force_open (char *fname) +force_open(char *fname) { - int fd; - time_t expire; + int fd; + time_t expire; + + expire = now - 3600; /* lock ¦s¦b¶W¹L¤@Ó¤p®É´N¬O¦³°ÝÃD! */ - expire = now - 3600; /* lock ¦s¦b¶W¹L¤@Ó¤p®É´N¬O¦³°ÝÃD! */ - - if (dasht (fname) < expire) return -1; - unlink(fname); - fd = open (fname, O_WRONLY|O_TRUNC, 0644); + if (dasht(fname) < expire) + return -1; + unlink(fname); + fd = open(fname, O_WRONLY | O_TRUNC, 0644); - return fd; + return fd; } #if !defined(_BBS_UTIL_C_) /* new/old/lock file processing */ typedef struct nol_t { - char newfn[256]; - char oldfn[256]; - char lockfn[256]; -} nol_t; + char newfn[256]; + char oldfn[256]; + char lockfn[256]; +} nol_t; -static void nolfilename(nol_t *n, char *fpath) { +static void +nolfilename(nol_t * n, char *fpath) +{ sprintf(n->newfn, "%s.new", fpath); sprintf(n->oldfn, "%s.old", fpath); sprintf(n->lockfn, "%s.lock", fpath); } -int delete_record(char fpath[], int size, int id) { - nol_t my; - char abuf[BUFSIZE]; - int fdr, fdw, fd; - int count; - +int +delete_record(char fpath[], int size, int id) +{ + nol_t my; + char abuf[BUFSIZE]; + int fdr, fdw, fd; + int count; + nolfilename(&my, fpath); - if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) return -1; flock(fd, LOCK_EX); - if((fdr = open(fpath, O_RDONLY, 0)) == -1) { - move(10,10); + if ((fdr = open(fpath, O_RDONLY, 0)) == -1) { + move(10, 10); outs("delete_record failed!!! (open)"); pressanykey(); flock(fd, LOCK_UN); close(fd); return -1; } - - if( - ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && - ((fdw = force_open (my.newfn)) == -1)) { + if ( + ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && + ((fdw = force_open(my.newfn)) == -1)) { flock(fd, LOCK_UN); close(fd); close(fdr); return -1; } count = 1; - while(read(fdr, abuf, size) == size) { - if(id != count++ && (safewrite(fdw, abuf, size) == -1)) { + while (read(fdr, abuf, size) == size) { + if (id != count++ && (safewrite(fdw, abuf, size) == -1)) { unlink(my.newfn); close(fdr); close(fdw); @@ -168,7 +184,7 @@ int delete_record(char fpath[], int size, int id) { } close(fdr); close(fdw); - if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + if (Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { flock(fd, LOCK_UN); close(fd); return -1; @@ -179,61 +195,61 @@ int delete_record(char fpath[], int size, int id) { } #if 0 -static char *title_body(char *title) { - if(!strncasecmp(title, str_reply, 3)) { +static char * +title_body(char *title) +{ + if (!strncasecmp(title, str_reply, 3)) { title += 3; - if(*title == ' ') + if (*title == ' ') title++; } return title; } #endif -int delete_range(char *fpath, int id1, int id2) { - fileheader_t fhdr; - nol_t my; - char fullpath[STRLEN], *t; - int fdr, fdw, fd; - int count; - +int +delete_range(char *fpath, int id1, int id2) +{ + fileheader_t fhdr; + nol_t my; + char fullpath[STRLEN], *t; + int fdr, fdw, fd; + int count; + nolfilename(&my, fpath); - - if((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) + + if ((fd = open(my.lockfn, O_RDWR | O_CREAT | O_APPEND, 0644)) == -1) return -1; flock(fd, LOCK_EX); - if((fdr = open(fpath, O_RDONLY, 0)) == -1) { + if ((fdr = open(fpath, O_RDONLY, 0)) == -1) { flock(fd, LOCK_UN); close(fd); return -1; } - - if( + if ( ((fdw = open(my.newfn, O_WRONLY | O_CREAT | O_EXCL, 0644)) == -1) && - ((fdw = force_open (my.newfn)) == -1)) { + ((fdw = force_open(my.newfn)) == -1)) { close(fdr); flock(fd, LOCK_UN); close(fd); return -1; } - count = 1; strcpy(fullpath, fpath); t = strrchr(fullpath, '/') + 1; - while(read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) - { + while (read(fdr, &fhdr, sizeof(fileheader_t)) == sizeof(fileheader_t)) { strcpy(t, fhdr.filename); -/* rocker.011018: add new tag delete */ - if ( - (fhdr.filemode & FILE_MARKED) || /* ¼Ð°O */ - (fhdr.filemode & FILE_DIGEST) || /* ¤åºK */ - (id1 && (count < id1 || count > id2)) || /* range */ - (!id1 && Tagger(atoi (t + 2), count, TAG_NIN))) /* TagList */ - { - if((safewrite(fdw, &fhdr, sizeof(fileheader_t)) == -1)) { + /* rocker.011018: add new tag delete */ + if ( + (fhdr.filemode & FILE_MARKED) || /* ¼Ð°O */ + (fhdr.filemode & FILE_DIGEST) || /* ¤åºK */ + (id1 && (count < id1 || count > id2)) || /* range */ + (!id1 && Tagger(atoi(t + 2), count, TAG_NIN))) { /* TagList */ + if ((safewrite(fdw, &fhdr, sizeof(fileheader_t)) == -1)) { close(fdr); close(fdw); unlink(my.newfn); @@ -241,17 +257,15 @@ int delete_range(char *fpath, int id1, int id2) { close(fd); return -1; } - } - else - { - //if(dashd(fullpath)) - unlink(fullpath); - } + } else { + //if (dashd(fullpath)) + unlink(fullpath); + } ++count; } close(fdr); close(fdw); - if(Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { + if (Rename(fpath, my.oldfn) == -1 || Rename(my.newfn, fpath) == -1) { flock(fd, LOCK_UN); close(fd); return -1; @@ -261,17 +275,19 @@ int delete_range(char *fpath, int id1, int id2) { return 0; } -int search_rec(char* dirname, int (*filecheck)()) { - fileheader_t fhdr; - FILE *fp; - int ans = 0; - - if(!(fp = fopen(dirname, "r"))) +int +search_rec(char *dirname, int (*filecheck) ()) +{ + fileheader_t fhdr; + FILE *fp; + int ans = 0; + + if (!(fp = fopen(dirname, "r"))) return 0; - - while(fread(&fhdr, sizeof(fhdr), 1, fp)) { + + while (fread(&fhdr, sizeof(fhdr), 1, fp)) { ans++; - if((*filecheck) (&fhdr)) { + if ((*filecheck) (&fhdr)) { fclose(fp); return ans; } @@ -280,34 +296,33 @@ int search_rec(char* dirname, int (*filecheck)()) { return 0; } -int delete_files(char* dirname, int (*filecheck)(), int record) { - fileheader_t fhdr; - FILE *fp, *fptmp; - int ans = 0; - char tmpfname[128]; - char genbuf[256]; - char deleted[256]; - fileheader_t delfh; - char deletedDIR[] = "boards/d/deleted/.DIR"; - +int delete_files(char *dirname, int (*filecheck) (), int record){ + fileheader_t fhdr; + FILE *fp, *fptmp; + int ans = 0; + char tmpfname[128]; + char genbuf[256]; + char deleted[256]; + fileheader_t delfh; + char deletedDIR[] = "boards/d/deleted/.DIR"; + strcpy(deleted, "boards/d/deleted"); - - if(!(fp = fopen(dirname, "r"))) + + if (!(fp = fopen(dirname, "r"))) return ans; - + strcpy(tmpfname, dirname); strcat(tmpfname, "_tmp"); - - if(!(fptmp = fopen(tmpfname, "w"))) { + + if (!(fptmp = fopen(tmpfname, "w"))) { fclose(fp); return ans; } - - while(fread(&fhdr, sizeof(fhdr), 1, fp)){ - if((*filecheck)(&fhdr)) { + while (fread(&fhdr, sizeof(fhdr), 1, fp)) { + if ((*filecheck) (&fhdr)) { ans++; setdirpath(genbuf, dirname, fhdr.filename); - if (record){ + if (record) { deleted[14] = '\0'; stampfile(deleted, &delfh); strcpy(delfh.owner, fhdr.owner); @@ -319,39 +334,41 @@ int delete_files(char* dirname, int (*filecheck)(), int record) { } else fwrite(&fhdr, sizeof(fhdr), 1, fptmp); } - + fclose(fp); fclose(fptmp); unlink(dirname); Rename(tmpfname, dirname); - + return ans; } -int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { - char abuf[BUFSIZE]; - int fd; - struct stat st; - long numents; - - if(ent < 1 || (fd = open(dirname, O_RDWR)) == -1) +int +delete_file(char *dirname, int size, int ent, int (*filecheck) ()) +{ + char abuf[BUFSIZE]; + int fd; + struct stat st; + long numents; + + if (ent < 1 || (fd = open(dirname, O_RDWR)) == -1) return -1; flock(fd, LOCK_EX); fstat(fd, &st); - numents = ((long) st.st_size) / size; - if(((long) st.st_size) % size) + numents = ((long)st.st_size) / size; + if (((long)st.st_size) % size) fprintf(stderr, "align err\n"); - if(lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) { - if(read(fd, abuf, size) == size){ - if((*filecheck) (abuf)) { - int i; - - for(i = ent; i < numents; i++) { - if(lseek(fd, (off_t)((i) * size), SEEK_SET) == -1 || - read(fd, abuf, size) != size || - lseek(fd, (off_t)(i - 1) * size, SEEK_SET) == -1) + if (lseek(fd, (off_t) size * (ent - 1), SEEK_SET) != -1) { + if (read(fd, abuf, size) == size) { + if ((*filecheck) (abuf)) { + int i; + + for (i = ent; i < numents; i++) { + if (lseek(fd, (off_t) ((i) * size), SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t) (i - 1) * size, SEEK_SET) == -1) break; - if(safewrite(fd, abuf, size) != size) + if (safewrite(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); @@ -363,15 +380,15 @@ int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { } lseek(fd, 0, SEEK_SET); ent = 1; - while(read(fd, abuf, size) == size) { - if((*filecheck)(abuf)) { - int i; - - for(i = ent; i < numents; i++) { - if(lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 || - read(fd, abuf, size) != size || - lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 || - safewrite(fd, abuf, size) != size) + while (read(fd, abuf, size) == size) { + if ((*filecheck) (abuf)) { + int i; + + for (i = ent; i < numents; i++) { + if (lseek(fd, (off_t) (i + 1) * size, SEEK_SET) == -1 || + read(fd, abuf, size) != size || + lseek(fd, (off_t) (i) * size, SEEK_SET) == -1 || + safewrite(fd, abuf, size) != size) break; } ftruncate(fd, (off_t) size * (numents - 1)); @@ -386,17 +403,17 @@ int delete_file(char *dirname, int size, int ent, int (*filecheck)()) { return -1; } -#endif /* !defined(_BBS_UTIL_C_) */ +#endif /* !defined(_BBS_UTIL_C_) */ + +int apply_record(char *fpath, int (*fptr) (), int size){ + char abuf[BUFSIZE]; + FILE *fp; -int apply_record(char *fpath, int (*fptr)(), int size) { - char abuf[BUFSIZE]; - FILE* fp; - - if(!(fp = fopen(fpath, "r"))) + if (!(fp = fopen(fpath, "r"))) return -1; - - while(fread(abuf, 1, size, fp) == size) - if((*fptr) (abuf) == QUIT) { + + while (fread(abuf, 1, size, fp) == size) + if ((*fptr) (abuf) == QUIT) { fclose(fp); return QUIT; } @@ -405,22 +422,24 @@ int apply_record(char *fpath, int (*fptr)(), int size) { } /* mail / post ®É¡A¨Ì¾Ú®É¶¡«Ø¥ßÀɮסA¥[¤W¶lÂW */ -int stampfile(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; - int fp = 0; +int +stampfile(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; + int fp = 0; - if(access(fpath, X_OK | R_OK | W_OK)) + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand()&0xFFF ); - if(fp == -1 && errno != EEXIST) + sprintf(ip, "M.%ld.A.%3.3X", ++dtime, rand() & 0xFFF); + if (fp == -1 && errno != EEXIST) return -1; - } while((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); + } while ((fp = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) == -1); close(fp); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); @@ -429,82 +448,90 @@ int stampfile(char *fpath, fileheader_t *fh) { return 0; } -void stampdir(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; - - if(access(fpath, X_OK | R_OK | W_OK)) +void +stampdir(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; + + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - - while(*(++ip)); + + while (*(++ip)); *ip++ = '/'; do { sprintf(ip, "D%lX", ++dtime & 07777); - } while(mkdir(fpath, 0755) == -1); + } while (mkdir(fpath, 0755) == -1); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -void stamplink(char *fpath, fileheader_t *fh) { - register char *ip = fpath; - time_t dtime=now; - struct tm *ptime; +void +stamplink(char *fpath, fileheader_t * fh) +{ + register char *ip = fpath; + time_t dtime = now; + struct tm *ptime; - if(access(fpath, X_OK | R_OK | W_OK)) + if (access(fpath, X_OK | R_OK | W_OK)) mkdir(fpath, 0755); - while(*(++ip)); + while (*(++ip)); *ip++ = '/'; do { - sprintf(ip, "S%lX", ++dtime ); - } while(symlink("temp", fpath) == -1); + sprintf(ip, "S%lX", ++dtime); + } while (symlink("temp", fpath) == -1); memset(fh, 0, sizeof(fileheader_t)); strcpy(fh->filename, ip); ptime = localtime(&dtime); sprintf(fh->date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } -int do_append(char *fpath, fileheader_t *record, int size) { - int fd; - - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { +int +do_append(char *fpath, fileheader_t * record, int size) +{ + int fd; + + if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) == -1) { perror("open"); return -1; } flock(fd, LOCK_EX); lseek(fd, 0, SEEK_END); - + safewrite(fd, record, size); - + flock(fd, LOCK_UN); close(fd); return 0; } -int append_record(char *fpath, fileheader_t *record, int size) { +int +append_record(char *fpath, fileheader_t * record, int size) +{ #if !defined(_BBS_UTIL_C_) - int m,n; - if(get_num_records(fpath, sizeof(fileheader_t)) <= MAX_KEEPMAIL * 2) { - FILE *fp; - char buf[512],address[200]; + int m, n; + if (get_num_records(fpath, sizeof(fileheader_t)) <= MAX_KEEPMAIL * 2) { + FILE *fp; + char buf[512], address[200]; - for(n = strlen(fpath) - 1 ; fpath[n] != '/' && n > 0; n--); + for (n = strlen(fpath) - 1; fpath[n] != '/' && n > 0; n--); strncpy(buf, fpath, n + 1); buf[n + 1] = 0; - for(m = strlen(buf) - 2 ; buf[m] != '/' && m > 0 ; m--); + for (m = strlen(buf) - 2; buf[m] != '/' && m > 0; m--); strcat(buf, ".forward"); - if((fp = fopen(buf,"r"))) { - fscanf(fp,"%s",address); + if ((fp = fopen(buf, "r"))) { + fscanf(fp, "%s", address); fclose(fp); - if(buf[0] != 0 && buf[0] != ' ') { + if (buf[0] != 0 && buf[0] != ' ') { buf[n + 1] = 0; strcat(buf, record->filename); - do_append(fpath,record,size); + do_append(fpath, record, size); #ifndef USE_BSMTP - bbs_sendmail(buf,record->title,address); + bbs_sendmail(buf, record->title, address); #else bsmtp(buf, record->title, address, 0); #endif @@ -512,9 +539,9 @@ int append_record(char *fpath, fileheader_t *record, int size) { } } } -#endif - - do_append(fpath,record,size); - +#endif + + do_append(fpath, record, size); + return 0; } diff --git a/mbbsd/register.c b/mbbsd/register.c index a3fa13ef..f2b50a9b 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -1,24 +1,26 @@ -/* $Id: register.c,v 1.5 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: register.c,v 1.6 2002/07/05 17:10:28 in2 Exp $ */ #define _XOPEN_SOURCE #include "bbs.h" /* password encryption */ -static char pwbuf[14]; +static char pwbuf[14]; + +char * +genpasswd(char *pw) +{ + if (pw[0]) { + char saltc[2], c; + int i; -char *genpasswd(char *pw) { - if(pw[0]) { - char saltc[2], c; - int i; - i = 9 * getpid(); saltc[0] = i & 077; saltc[1] = (i >> 6) & 077; - - for(i = 0; i < 2; i++) { + + for (i = 0; i < 2; i++) { c = saltc[i] + '.'; - if(c > '9') + if (c > '9') c += 7; - if(c > 'Z') + if (c > 'Z') c += 6; saltc[i] = c; } @@ -28,34 +30,39 @@ char *genpasswd(char *pw) { return ""; } -int checkpasswd(char *passwd, char *test) { - char *pw; - +int +checkpasswd(char *passwd, char *test) +{ + char *pw; + strncpy(pwbuf, test, 14); pw = crypt(pwbuf, passwd); return (!strncmp(pw, passwd, 14)); } /* Àˬd user µù¥U±¡ªp */ -int bad_user_id(char *userid) { - int len, i; +int +bad_user_id(char *userid) +{ + int len, i; len = strlen(userid); - if(len < 2) + if (len < 2) return 1; if (not_alpha(userid[0])) return 1; - for (i=1; i<len; i++) //DickG:×¥¿¤F¥u¤ñ¸û userid ²Ä¤@Ó¦r¤¸ªº bug - if(not_alnum(userid[i])) - return 1; - - if(strcasecmp(userid, str_new) == 0) + for (i = 1; i < len; i++) +//DickG:×¥¿¤F ¥ u ¤ ñ¸ûuserid ² Ĥ@Ó¦r ¤ ¸ªºbug + if (not_alnum(userid[i])) + return 1; + + if (strcasecmp(userid, str_new) == 0) return 1; - - /* while((ch = *(++userid))) - if(not_alnum(ch)) - return 1;*/ + + /* + * while((ch = *(++userid))) if(not_alnum(ch)) return 1; + */ return 0; } @@ -64,23 +71,25 @@ int bad_user_id(char *userid) { /* (a) is the worst user currently */ /* (b) is the object to be compared */ /* -------------------------------- */ -static int compute_user_value(userec_t *urec, time_t clock) { - int value; - +static int +compute_user_value(userec_t * urec, time_t clock) +{ + int value; + /* if (urec) has XEMPT permission, don't kick it */ - if((urec->userid[0] == '\0') || (urec->userlevel & PERM_XEMPT) - /*|| (urec->userlevel & PERM_LOGINOK)*/ - || !strcmp(STR_GUEST,urec->userid)) + if ((urec->userid[0] == '\0') || (urec->userlevel & PERM_XEMPT) + /* || (urec->userlevel & PERM_LOGINOK) */ + || !strcmp(STR_GUEST, urec->userid)) return 999999; - value = (clock - urec->lastlogin) / 60; /* minutes */ - + value = (clock - urec->lastlogin) / 60; /* minutes */ + /* new user should register in 30 mins */ - if(strcmp(urec->userid, str_new) == 0) + if (strcmp(urec->userid, str_new) == 0) return 30 - value; -#if 0 - if (!urec->numlogins) /* ¥¼ login ¦¨¥\ªÌ¡A¤£«O¯d */ +#if 0 + if (!urec->numlogins) /* ¥¼ login ¦¨¥\ªÌ¡A¤£«O¯d */ return -1; - if (urec->numlogins <= 3) /* #login ¤Ö©ó¤TªÌ¡A«O¯d 20 ¤Ñ */ + if (urec->numlogins <= 3) /* #login ¤Ö©ó¤TªÌ¡A«O¯d 20 ¤Ñ */ return 20 * 24 * 60 - value; #endif /* ¥¼§¹¦¨µù¥UªÌ¡A«O¯d 15 ¤Ñ */ @@ -88,87 +97,86 @@ static int compute_user_value(userec_t *urec, time_t clock) { return (urec->userlevel & PERM_LOGINOK ? 120 : 15) * 24 * 60 - value; } -int check_and_expire_account(int uid,userec_t *urec) +int +check_and_expire_account(int uid, userec_t * urec) { - userec_t zerorec; - char genbuf[200],genbuf2[200]; - int val; - if((val = compute_user_value(urec, now)) < 0) { - sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", - uid, urec->userid, ctime(&(urec->lastlogin)) + 4, - urec->numlogins, urec->numposts, val); - if(val > -1 * 60 * 24 * 365) { + userec_t zerorec; + char genbuf[200], genbuf2[200]; + int val; + if ((val = compute_user_value(urec, now)) < 0) { + sprintf(genbuf, "#%d %-12s %15.15s %d %d %d", + uid, urec->userid, ctime(&(urec->lastlogin)) + 4, + urec->numlogins, urec->numposts, val); + if (val > -1 * 60 * 24 * 365) { memset(&zerorec, 0, sizeof(zerorec)); - log_usies("CLEAN", genbuf); - sprintf(genbuf, "home/%c/%s", urec->userid[0], - urec->userid); - sprintf(genbuf2, "tmp/%s", urec->userid); - if(dashd(genbuf) && Rename(genbuf, genbuf2)) { - sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", - urec->userid[0],urec->userid); - system(genbuf); - } + log_usies("CLEAN", genbuf); + sprintf(genbuf, "home/%c/%s", urec->userid[0], + urec->userid); + sprintf(genbuf2, "tmp/%s", urec->userid); + if (dashd(genbuf) && Rename(genbuf, genbuf2)) { + sprintf(genbuf, "/bin/rm -fr home/%c/%s >/dev/null 2>&1", + urec->userid[0], urec->userid); + system(genbuf); + } passwd_update(uid, &zerorec); remove_from_uhash(uid - 1); add_to_uhash(uid - 1, ""); - } - else - { - val=0; - log_usies("DATED", genbuf); - } + } else { + val = 0; + log_usies("DATED", genbuf); } + } return val; } -int getnewuserid() { - char genbuf[50]; - static char *fn_fresh = ".fresh"; - userec_t utmp,zerorec; - time_t clock; - struct stat st; - int fd, i; - +int +getnewuserid() +{ + char genbuf[50]; + static char *fn_fresh = ".fresh"; + userec_t utmp, zerorec; + time_t clock; + struct stat st; + int fd, i; + memset(&zerorec, 0, sizeof(zerorec)); clock = now; - + /* Lazy method : ¥ý§ä´M¤w¸g²M°£ªº¹L´Á±b¸¹ */ - if((i = searchnewuser(0)) == 0) { + if ((i = searchnewuser(0)) == 0) { /* ¨C 1 Ó¤p®É¡A²M²z user ±b¸¹¤@¦¸ */ - if((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { - if((fd = open(fn_fresh, O_RDWR | O_CREAT, 0600)) == -1) + if ((stat(fn_fresh, &st) == -1) || (st.st_mtime < clock - 3600)) { + if ((fd = open(fn_fresh, O_RDWR | O_CREAT, 0600)) == -1) return -1; write(fd, ctime(&clock), 25); close(fd); log_usies("CLEAN", "dated users"); - + fprintf(stdout, "´M§ä·s±b¸¹¤¤, ½Ðµy«Ý¤ù¨è...\n\r"); - - if((fd = open(fn_passwd, O_RDWR | O_CREAT, 0600)) == -1) + + if ((fd = open(fn_passwd, O_RDWR | O_CREAT, 0600)) == -1) return -1; - + /* ¤£¾å±o¬°¤°»òn±q 2 ¶}©l... Ptt:¦]¬°SYSOP¦b1 */ - for(i = 2; i <= MAX_USERS; i++) { + for (i = 2; i <= MAX_USERS; i++) { passwd_query(i, &utmp); - check_and_expire_account(i,&utmp); + check_and_expire_account(i, &utmp); } } } - passwd_lock(); i = searchnewuser(1); - if((i <= 0) || (i > MAX_USERS)) { + if ((i <= 0) || (i > MAX_USERS)) { passwd_unlock(); - if(more("etc/user_full", NA) == -1) + if (more("etc/user_full", NA) == -1) fprintf(stdout, "©êºp¡A¨Ï¥ÎªÌ±b¸¹¤w¸gº¡¤F¡AµLªkµù¥U·sªº±b¸¹\n\r"); safe_sleep(2); exit(1); } - sprintf(genbuf, "uid %d", i); log_usies("APPLY", genbuf); - + strcpy(zerorec.userid, str_new); zerorec.lastlogin = clock; passwd_update(i, &zerorec); @@ -177,19 +185,21 @@ int getnewuserid() { return i; } -void new_register() { - userec_t newuser; - char passbuf[STRLEN]; - int allocid, try, id; +void +new_register() +{ + userec_t newuser; + char passbuf[STRLEN]; + int allocid, try, id; memset(&newuser, 0, sizeof(newuser)); more("etc/register", NA); try = 0; - while(1) { - if(++try >= 6) { + while (1) { + if (++try >= 6) { outs("\n±z¹Á¸Õ¿ù»~ªº¿é¤J¤Ó¦h¡A½Ð¤U¦¸¦A¨Ó§a\n"); refresh(); - + pressanykey(); oflush(); exit(1); @@ -197,42 +207,39 @@ void new_register() { getdata(17, 0, msg_uid, newuser.userid, sizeof(newuser.userid), DOECHO); - if(bad_user_id(newuser.userid)) + if (bad_user_id(newuser.userid)) outs("µLªk±µ¨ü³oÓ¥N¸¹¡A½Ð¨Ï¥Î^¤å¦r¥À¡A¨Ã¥B¤£n¥]§tªÅ®æ\n"); - else if ((id=getuser(newuser.userid)) && - (id=check_and_expire_account(id,&xuser))>=0) - { - if(id==999999) + else if ((id = getuser(newuser.userid)) && + (id = check_and_expire_account(id, &xuser)) >= 0) { + if (id == 999999) outs("¦¹¥N¸¹¤w¸g¦³¤H¨Ï¥Î ¬O¤£¦º¤§¨"); - else - { - sprintf(passbuf,"¦¹¥N¸¹¤w¸g¦³¤H¨Ï¥Î ÁÙ¦³%d¤Ñ¤~¹L´Á \n",id/(60*24)); - outs(passbuf); - } - } - else + else { + sprintf(passbuf, "¦¹¥N¸¹¤w¸g¦³¤H¨Ï¥Î ÁÙ¦³%d¤Ñ¤~¹L´Á \n", id / (60 * 24)); + outs(passbuf); + } + } else break; } try = 0; - while(1) { - if(++try >= 6) { + while (1) { + if (++try >= 6) { outs("\n±z¹Á¸Õ¿ù»~ªº¿é¤J¤Ó¦h¡A½Ð¤U¦¸¦A¨Ó§a\n"); refresh(); - + pressanykey(); oflush(); exit(1); } - if((getdata(19, 0, "½Ð³]©w±K½X¡G", passbuf, - sizeof(passbuf), NOECHO) < 3) || - !strcmp(passbuf, newuser.userid)) { + if ((getdata(19, 0, "½Ð³]©w±K½X¡G", passbuf, + sizeof(passbuf), NOECHO) < 3) || + !strcmp(passbuf, newuser.userid)) { outs("±K½X¤Ó²³æ¡A©ö¾D¤J«I¡A¦Ü¤Ön 4 Ó¦r¡A½Ð«·s¿é¤J\n"); continue; } strncpy(newuser.passwd, passbuf, PASSLEN); getdata(20, 0, "½ÐÀˬd±K½X¡G", passbuf, sizeof(passbuf), NOECHO); - if(strncmp(passbuf, newuser.passwd, PASSLEN)) { + if (strncmp(passbuf, newuser.passwd, PASSLEN)) { outs("±K½X¿é¤J¿ù»~, ½Ð«·s¿é¤J±K½X.\n"); continue; } @@ -246,76 +253,69 @@ void new_register() { newuser.money = 0; newuser.pager = 1; allocid = getnewuserid(); - if(allocid > MAX_USERS || allocid <= 0) { + if (allocid > MAX_USERS || allocid <= 0) { fprintf(stderr, "¥»¯¸¤H¤f¤w¹F¹¡©M¡I\n"); exit(1); } - - if(passwd_update(allocid, &newuser) == -1) { + if (passwd_update(allocid, &newuser) == -1) { fprintf(stderr, "«Èº¡¤F¡A¦A¨£¡I\n"); exit(1); } setuserid(allocid, newuser.userid); - if(!dosearchuser(newuser.userid)) { + if (!dosearchuser(newuser.userid)) { fprintf(stderr, "µLªk«Ø¥ß±b¸¹\n"); exit(1); } } -void check_register() { - char *ptr = NULL; - +void +check_register() +{ + char *ptr = NULL; + stand_title("½Ð¸Ô²Ó¶ñ¼gÓ¤H¸ê®Æ"); - - while(strlen(cuser.username) < 2) + + while (strlen(cuser.username) < 2) getdata(2, 0, "ºï¸¹¼ÊºÙ¡G", cuser.username, sizeof(cuser.username), DOECHO); - for(ptr = cuser.username; *ptr; ptr++) { - if (*ptr == 9) /* TAB convert */ + for (ptr = cuser.username; *ptr; ptr++) { + if (*ptr == 9) /* TAB convert */ *ptr = ' '; } - while(strlen(cuser.realname) < 4) + while (strlen(cuser.realname) < 4) getdata(4, 0, "¯u¹ê©m¦W¡G", cuser.realname, sizeof(cuser.realname), DOECHO); - - while(strlen(cuser.address) < 8) + + while (strlen(cuser.address) < 8) getdata(6, 0, "Ápµ¸¦a§}¡G", cuser.address, sizeof(cuser.address), DOECHO); /* - if(!strchr(cuser.email, '@')) { - bell(); - move(t_lines - 4, 0); - prints("¡° ¬°¤F±zªºÅv¯q¡A½Ð¶ñ¼g¯u¹êªº E-mail address¡A" - "¥H¸ê½T»{»Õ¤U¨¥÷¡A\n" - "®æ¦¡¬° \033[44muser@domain_name\033[0m ©Î \033[44muser" - "@\\[ip_number\\]\033[0m¡C\n\n" - "¡° ¦pªG±z¯uªº¨S¦³ E-mail¡A½Ðª½±µ«ö [return] §Y¥i¡C"); - - do { - getdata(8, 0, "¹q¤l«H½c¡G", - cuser.email, sizeof(cuser.email), DOECHO); - if(!cuser.email[0]) - sprintf(cuser.email, "%s%s", cuser.userid, str_mail_address); - } while(!strchr(cuser.email, '@')); - - } - */ - if(!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { + * if(!strchr(cuser.email, '@')) { bell(); move(t_lines - 4, 0); prints(" + * ±zªºÅv¯q¡A½Ð¶ñ¼g¯u¹êªº E-mail address¡A" "¥H¸ê½T»{»Õ¤U¨¥÷¡A\n" " + * 033[44muser@domain_name\033[0m ©Î \033[44muser" + * "@\\[ip_number\\]\033[0m¡C\n\n" "¡° ¦pªG±z¯uªº¨S¦³ E-mail¡A + * turn] §Y¥i¡C"); + * + * do { getdata(8, 0, "¹q¤l«H½c¡G", cuser.email, sizeof(cuser.email), + * DOECHO); if(!cuser.email[0]) sprintf(cuser.email, "%s%s", + * cuser.userid, str_mail_address); } while(!strchr(cuser.email, '@')); + * + * } */ + if (!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_LOGINOK)) { /* ¦^ÂйL¨¥÷»{ÃÒ«H¨ç¡A©Î´¿¸g E-mail post ¹L */ clear(); - move(9,3); + move(9, 3); prints("½Ð¸Ô¶ñ¼g\033[32mµù¥U¥Ó½Ð³æ\033[m¡A" "³q§i¯¸ªø¥HÀò±o¶i¶¥¨Ï¥ÎÅv¤O¡C\n\n\n\n"); u_register(); } - #ifdef NEWUSER_LIMIT - if(!(cuser.userlevel & PERM_LOGINOK) && !HAS_PERM(PERM_SYSOP)) { - if(cuser.lastlogin - cuser.firstlogin < 3 * 86400) + if (!(cuser.userlevel & PERM_LOGINOK) && !HAS_PERM(PERM_SYSOP)) { + if (cuser.lastlogin - cuser.firstlogin < 3 * 86400) cuser.userlevel &= ~PERM_POST; more("etc/newuser", YEA); } diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 5bd9dbdb..12901158 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -1,11 +1,11 @@ -/* $Id: screen.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: screen.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -#ifdef SUPPORT_GB -static int current_font_type=TYPE_BIG5; -static int gbinited=0; +#ifdef SUPPORT_GB +static int current_font_type = TYPE_BIG5; +static int gbinited = 0; #endif -#define SCR_WIDTH 80 +#define SCR_WIDTH 80 #define o_clear() output(clearbuf,clearbuflen) #define o_cleol() output(cleolbuf,cleolbuflen) #define o_scrollrev() output(scrollrev,scrollrevlen) @@ -15,16 +15,18 @@ static int gbinited=0; static unsigned char cur_ln = 0, cur_col = 0; static unsigned char docls, downfrom = 0; static unsigned char standing = NA; -static char roll = 0; -static int scrollcnt, tc_col, tc_line; +static char roll = 0; +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 */ +#define MODIFIED (1) /* if line has been modifed, screen output */ +#define STANDOUT (2) /* if this line has a standout region */ -int tputs(const char *str, int affcnt, int (*putc)(int)); +int tputs(const char *str, int affcnt, int (*putc) (int)); -void initscr() { - if(!big_picture) { +void +initscr() +{ + if (!big_picture) { scr_lns = t_lines; scr_cols = t_columns = ANSILINELEN; /* scr_cols = MIN(t_columns, ANSILINELEN); */ @@ -33,40 +35,45 @@ void initscr() { } } -void move(int y, int x) { +void +move(int y, int x) +{ cur_col = x; cur_ln = y; } -void getyx(int *y, int *x) { +void +getyx(int *y, int *x) +{ *y = cur_ln; *x = cur_col; } -static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { - if(new_ln >= t_lines || new_col >= t_columns) +static void +rel_move(int was_col, int was_ln, int new_col, int new_ln) +{ + if (new_ln >= t_lines || new_col >= t_columns) return; tc_col = new_col; tc_line = new_ln; - if(new_col == 0) { - if(new_ln == was_ln) { - if(was_col) + if (new_col == 0) { + if (new_ln == was_ln) { + if (was_col) ochar('\r'); return; - } else if(new_ln == was_ln + 1) { + } else if (new_ln == was_ln + 1) { ochar('\n'); - if(was_col) + if (was_col) ochar('\r'); return; } } - - if(new_ln == was_ln) { - if(was_col == new_col) + if (new_ln == was_ln) { + if (was_col == new_col) return; - if(new_col == was_col - 1) { + if (new_col == was_col - 1) { ochar(Ctrl('H')); return; } @@ -74,47 +81,51 @@ static void rel_move(int was_col, int was_ln, int new_col, int new_ln) { do_move(new_col, new_ln); } -static void standoutput(char *buf, int ds, int de, int sso, int eso) { - int st_start, st_end; - - if(eso <= ds || sso >= de) { +static void +standoutput(char *buf, int ds, int de, int sso, int eso) +{ + int st_start, st_end; + + if (eso <= ds || sso >= de) { output(buf + ds, de - ds); } else { st_start = MAX(sso, ds); st_end = MIN(eso, de); - if(sso > ds) + if (sso > ds) output(buf + ds, sso - ds); o_standup(); output(buf + st_start, st_end - st_start); o_standdown(); - if(de > eso) + if (de > eso) output(buf + eso, de - eso); } } -void redoscr() { +void +redoscr() +{ register screenline_t *bp; - register int i, j, len; + register int i, j, len; o_clear(); - for(tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { - if(j >= scr_lns) + for (tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { + if (j >= scr_lns) j = 0; bp = &big_picture[j]; - if((len = bp->len)) { + if ((len = bp->len)) { rel_move(tc_col, tc_line, 0, i); - if(bp->mode & STANDOUT) + if (bp->mode & STANDOUT) standoutput((char *)bp->data, 0, len, bp->sso, bp->eso); else output((char *)bp->data, len); tc_col += len; - if(tc_col >= t_columns) { + if (tc_col >= t_columns) { if (automargins) tc_col = t_columns - 1; else { tc_col -= t_columns; tc_line++; - if(tc_line >= t_lines) + if (tc_line >= t_lines) tc_line = b_lines; } } @@ -127,61 +138,60 @@ void redoscr() { oflush(); } -void refresh() { +void +refresh() +{ register screenline_t *bp = big_picture; - register int i, j, len; - if(num_in_buf()) + register int i, j, len; + if (num_in_buf()) return; - if((docls) || (abs(scrollcnt) >= (scr_lns - 3))) { + if ((docls) || (abs(scrollcnt) >= (scr_lns - 3))) { redoscr(); return; } - - if(scrollcnt < 0) { - if(!scrollrevlen) { + if (scrollcnt < 0) { + if (!scrollrevlen) { redoscr(); return; } rel_move(tc_col, tc_line, 0, 0); do { o_scrollrev(); - } while(++scrollcnt); + } while (++scrollcnt); } else if (scrollcnt > 0) { rel_move(tc_col, tc_line, 0, b_lines); do { ochar('\n'); - } while(--scrollcnt); + } while (--scrollcnt); } - - for(i = 0, j = roll; i < scr_lns; i++, j++) { - if(j >= scr_lns) + for (i = 0, j = roll; i < scr_lns; i++, j++) { + if (j >= scr_lns) j = 0; bp = &big_picture[j]; len = bp->len; - if(bp->mode & MODIFIED && bp->smod < len) { + if (bp->mode & MODIFIED && bp->smod < len) { bp->mode &= ~(MODIFIED); - if(bp->emod >= len) + if (bp->emod >= len) bp->emod = len - 1; rel_move(tc_col, tc_line, bp->smod, i); - if(bp->mode & STANDOUT) + if (bp->mode & STANDOUT) standoutput((char *)bp->data, bp->smod, bp->emod + 1, bp->sso, bp->eso); else output((char *)&bp->data[bp->smod], bp->emod - bp->smod + 1); tc_col = bp->emod + 1; - if(tc_col >= t_columns) { - if(automargins) { + if (tc_col >= t_columns) { + if (automargins) { tc_col -= t_columns; - if(++tc_line >= t_lines) + if (++tc_line >= t_lines) tc_line = b_lines; } else tc_col = t_columns - 1; } } - - if(bp->oldlen > len) { + if (bp->oldlen > len) { rel_move(tc_col, tc_line, len, i); o_cleol(); } @@ -194,134 +204,137 @@ void refresh() { oflush(); } -void clear() { +void +clear() +{ register screenline_t *slp; - register int i; + register int i; docls = YEA; cur_col = cur_ln = roll = downfrom = i = 0; do { slp = &big_picture[i]; slp->mode = slp->len = slp->oldlen = 0; - } while(++i < scr_lns); + } while (++i < scr_lns); } -void clrtoeol() { +void +clrtoeol() +{ register screenline_t *slp; - register int ln; + register int ln; standing = NA; - if((ln = cur_ln + roll) >= scr_lns) + if ((ln = cur_ln + roll) >= scr_lns) ln -= scr_lns; slp = &big_picture[ln]; - if(cur_col <= slp->sso) + if (cur_col <= slp->sso) slp->mode &= ~STANDOUT; - if(cur_col > slp->oldlen) { - for(ln = slp->len; ln <= cur_col; ln++) + if (cur_col > slp->oldlen) { + for (ln = slp->len; ln <= cur_col; ln++) slp->data[ln] = ' '; } - - if(cur_col < slp->oldlen) { - for(ln = slp->len; ln >= cur_col; ln--) + if (cur_col < slp->oldlen) { + for (ln = slp->len; ln >= cur_col; ln--) slp->data[ln] = ' '; } - slp->len = cur_col; } -void clrtoline(int line) { +void +clrtoline(int line) +{ register screenline_t *slp; - register int i, j; + register int i, j; - for(i = cur_ln, j = i + roll; i < line; i++, j++) { - if(j >= scr_lns) + for (i = cur_ln, j = i + roll; i < line; i++, j++) { + if (j >= scr_lns) j -= scr_lns; slp = &big_picture[j]; slp->mode = slp->len = 0; - if(slp->oldlen) + if (slp->oldlen) slp->oldlen = 255; } -} +} -void clrtobot() { +void +clrtobot() +{ clrtoline(scr_lns); } -void outch(unsigned char c) { +void +outch(unsigned char c) +{ register screenline_t *slp; - register int i; + register int i; - if((i = cur_ln + roll) >= scr_lns) + if ((i = cur_ln + roll) >= scr_lns) i -= scr_lns; slp = &big_picture[i]; - - if(c == '\n' || c == '\r') { - if(standing) { + + if (c == '\n' || c == '\r') { + if (standing) { slp->eso = MAX(slp->eso, cur_col); standing = NA; } - if((i = cur_col - slp->len) > 0) + if ((i = cur_col - slp->len) > 0) memset(&slp->data[slp->len], ' ', i + 1); slp->len = cur_col; cur_col = 0; - if(cur_ln < scr_lns) + if (cur_ln < scr_lns) cur_ln++; return; } -/* - else if(c != '\033' && !isprint2(c)) - { - c = '*'; //substitute a '*' for non-printable - } -*/ - if(cur_col >= slp->len) { - for(i = slp->len; i < cur_col; i++) + /* + * else if(c != '\033' && !isprint2(c)) { c = '*'; //substitute a '*' for + * non-printable } + */ + if (cur_col >= slp->len) { + for (i = slp->len; i < cur_col; i++) slp->data[i] = ' '; slp->data[cur_col] = '\0'; slp->len = cur_col + 1; } - - if(slp->data[cur_col] != c) { + if (slp->data[cur_col] != c) { slp->data[cur_col] = c; - if((slp->mode & MODIFIED) != MODIFIED) + if ((slp->mode & MODIFIED) != MODIFIED) slp->smod = slp->emod = cur_col; slp->mode |= MODIFIED; - if(cur_col > slp->emod) + if (cur_col > slp->emod) slp->emod = cur_col; - if(cur_col < slp->smod) + if (cur_col < slp->smod) slp->smod = cur_col; } - - if (++cur_col >= scr_cols) - { - if (standing && (slp->mode & STANDOUT)) - { + if (++cur_col >= scr_cols) { + if (standing && (slp->mode & STANDOUT)) { standing = 0; slp->eso = MAX(slp->eso, cur_col); } cur_col = 0; if (cur_ln < scr_lns) cur_ln++; - } - + } } -static void parsecolor(char *buf) { - char *val; - char data[24]; - +static void +parsecolor(char *buf) +{ + char *val; + char data[24]; + data[0] = '\0'; val = (char *)strtok(buf, ";"); - while(val) { - if(atoi(val) < 30) { - if(data[0]) + while (val) { + if (atoi(val) < 30) { + if (data[0]) strcat(data, ";"); strcat(data, val); } - val = (char *) strtok(NULL, ";"); + val = (char *)strtok(NULL, ";"); } strcpy(buf, data); } @@ -330,24 +343,26 @@ static void parsecolor(char *buf) { #define ESCAPE (01) #define VTKEYS (02) -void outc(unsigned char ch) { - if(showansi) +void +outc(unsigned char ch) +{ + if (showansi) outch(ch); else { - static char buf[24]; - static int p = 0; - static int mode = NORMAL; - int i; + static char buf[24]; + static int p = 0; + static int mode = NORMAL; + int i; - switch(mode) { + switch (mode) { case NORMAL: - if(ch == '\033') + if (ch == '\033') mode = ESCAPE; else outch(ch); return; case ESCAPE: - if(ch == '[') + if (ch == '[') mode = VTKEYS; else { mode = NORMAL; @@ -356,18 +371,18 @@ void outc(unsigned char ch) { } return; case VTKEYS: - if(ch == 'm') { + if (ch == 'm') { buf[p++] = '\0'; parsecolor(buf); - } else if((p < 24) && (not_alpha(ch))) { + } else if ((p < 24) && (not_alpha(ch))) { buf[p++] = ch; return; } - if(buf[0]) { + if (buf[0]) { outch(''); outch('['); - for(i = 0; (p = buf[i]); i++) + for (i = 0; (p = buf[i]); i++) outch(p); outch(ch); } @@ -377,49 +392,55 @@ void outc(unsigned char ch) { } } -static void do_outs(char *str) { - while(*str) - { - outc(*str++); +static void +do_outs(char *str) +{ + while (*str) { + outc(*str++); } -} -#ifdef SUPPORT_GB -static void gb_init() +} +#ifdef SUPPORT_GB +static void +gb_init() { - if(current_font_type == TYPE_GB) - { - hc_readtab(BBSHOME"/etc/hc.tab"); + if (current_font_type == TYPE_GB) { + hc_readtab(BBSHOME "/etc/hc.tab"); } gbinited = 1; } -static void gb_outs(char *str) +static void +gb_outs(char *str) { do_outs(hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE)); -} +} #endif -int edit_outs(char *text) { - register int column = 0; - register char ch; -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) +int +edit_outs(char *text) +{ + register int column = 0; + register char ch; +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) text = hc_convert_str(text, HC_BIGtoGB, HC_DO_SINGLE); #endif - while((ch = *text++) && (++column < SCR_WIDTH)) - outch(ch == 27 ? '*' : ch); + while ((ch = *text++) && (++column < SCR_WIDTH)) + outch(ch == 27 ? '*' : ch); return 0; -} +} -void outs(char *str) { -#ifdef SUPPORT_GB - if(current_font_type == TYPE_BIG5) +void +outs(char *str) +{ +#ifdef SUPPORT_GB + if (current_font_type == TYPE_BIG5) #endif do_outs(str); -#ifdef SUPPORT_GB - else - { - if(!gbinited) gb_init(); +#ifdef SUPPORT_GB + else { + if (!gbinited) + gb_init(); gb_outs(str); } #endif @@ -427,33 +448,39 @@ void outs(char *str) { /* Jaky */ -void Jaky_outs(char *str, int line) { -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - str = hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE); +void +Jaky_outs(char *str, int line) +{ +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) + str = hc_convert_str(str, HC_BIGtoGB, HC_DO_SINGLE); #endif - while(*str && line) { + while (*str && line) { outc(*str); - if(*str=='\n') + if (*str == '\n') line--; str++; } } -void outmsg(char *msg) { +void +outmsg(char *msg) +{ move(b_lines, 0); clrtoeol(); -#ifdef SUPPORT_GB - if(current_font_type == TYPE_GB) - msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); +#ifdef SUPPORT_GB + if (current_font_type == TYPE_GB) + msg = hc_convert_str(msg, HC_BIGtoGB, HC_DO_SINGLE); #endif - while(*msg) + while (*msg) outc(*msg++); } -void prints(char *fmt, ...) { - va_list args; - char buff[1024]; +void +prints(char *fmt,...) +{ + va_list args; + char buff[1024]; va_start(args, fmt); vsprintf(buff, fmt, args); @@ -461,41 +488,48 @@ void prints(char *fmt, ...) { outs(buff); } -void mprints(int y, int x, char *str) { +void +mprints(int y, int x, char *str) +{ move(y, x); clrtoeol(); prints(str); -} +} -void scroll() { +void +scroll() +{ scrollcnt++; - if(++roll >= scr_lns) + if (++roll >= scr_lns) roll = 0; move(b_lines, 0); clrtoeol(); } -void rscroll() { +void +rscroll() +{ scrollcnt--; - if(--roll < 0) + if (--roll < 0) roll = b_lines; move(0, 0); clrtoeol(); } -void region_scroll_up(int top, int bottom) { - int i; +void +region_scroll_up(int top, int bottom) +{ + int i; - if(top > bottom) { - i = top; + if (top > bottom) { + i = top; top = bottom; bottom = i; } - - if(top < 0 || bottom >= scr_lns) + if (top < 0 || bottom >= scr_lns) return; - for(i = top; i < bottom; i++) + for (i = top; i < bottom; i++) big_picture[i] = big_picture[i + 1]; memset(big_picture + i, 0, sizeof(*big_picture)); memset(big_picture[i].data, ' ', scr_cols); @@ -508,8 +542,10 @@ void region_scroll_up(int top, int bottom) { refresh(); } -void standout() { - if(!standing && strtstandoutlen) { +void +standout() +{ + if (!standing && strtstandoutlen) { register screenline_t *slp; slp = &big_picture[((cur_ln + roll) % scr_lns)]; @@ -519,8 +555,10 @@ void standout() { } } -void standend() { - if(standing && strtstandoutlen) { +void +standend() +{ + if (standing && strtstandoutlen) { register screenline_t *slp; slp = &big_picture[((cur_ln + roll) % scr_lns)]; diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index c563fc29..98c38e19 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -1,71 +1,97 @@ -/* $Id: stuff.c,v 1.6 2002/06/29 15:10:01 ptt Exp $ */ +/* $Id: stuff.c,v 1.7 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" /* ----------------------------------------------------- */ /* set file path for boards/user home */ /* ----------------------------------------------------- */ -static char *str_home_file = "home/%c/%s/%s"; -static char *str_board_file = "boards/%c/%s/%s"; +static char *str_home_file = "home/%c/%s/%s"; +static char *str_board_file = "boards/%c/%s/%s"; #define STR_DOTDIR ".DIR" -static char *str_dotdir = STR_DOTDIR; +static char *str_dotdir = STR_DOTDIR; -void setcalfile(char *buf, char *userid) { +void +setcalfile(char *buf, char *userid) +{ sprintf(buf, "home/%c/%s/calendar", userid[0], userid); } -void sethomepath(char *buf, char *userid) { +void +sethomepath(char *buf, char *userid) +{ sprintf(buf, "home/%c/%s", userid[0], userid); } -void sethomedir(char *buf, char *userid) { +void +sethomedir(char *buf, char *userid) +{ sprintf(buf, str_home_file, userid[0], userid, str_dotdir); } -void sethomeman(char *buf, char *userid) { +void +sethomeman(char *buf, char *userid) +{ sprintf(buf, str_home_file, userid[0], userid, "man"); } -void sethomefile(char *buf, char *userid, char *fname) { +void +sethomefile(char *buf, char *userid, char *fname) +{ sprintf(buf, str_home_file, userid[0], userid, fname); } -void setuserfile(char *buf, char *fname) { +void +setuserfile(char *buf, char *fname) +{ sprintf(buf, str_home_file, cuser.userid[0], cuser.userid, fname); } -void setapath(char *buf, char *boardname) { +void +setapath(char *buf, char *boardname) +{ sprintf(buf, "man/boards/%c/%s", boardname[0], boardname); } -void setadir(char *buf, char *path) { +void +setadir(char *buf, char *path) +{ sprintf(buf, "%s/%s", path, str_dotdir); } -void setbpath(char *buf, char *boardname) { +void +setbpath(char *buf, char *boardname) +{ sprintf(buf, "boards/%c/%s", boardname[0], boardname); } -void setbdir(char *buf, char *boardname) { +void +setbdir(char *buf, char *boardname) +{ sprintf(buf, str_board_file, boardname[0], boardname, currmode & MODE_ETC ? ".ETC" : (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } -void setbfile(char *buf, char *boardname, char *fname) { +void +setbfile(char *buf, char *boardname, char *fname) +{ sprintf(buf, str_board_file, boardname[0], boardname, fname); } -void setdirpath(char *buf, char *direct, char *fname) { +void +setdirpath(char *buf, char *direct, char *fname) +{ strcpy(buf, direct); direct = strrchr(buf, '/'); strcpy(direct + 1, fname); } -char *subject(char *title) { - if(!strncasecmp(title, str_reply, 3)) { +char * +subject(char *title) +{ + if (!strncasecmp(title, str_reply, 3)) { title += 3; - if(*title == ' ') + if (*title == ' ') title++; } return title; @@ -74,38 +100,46 @@ char *subject(char *title) { /* ----------------------------------------------------- */ /* ¦r¦êÂà´«Àˬd¨ç¼Æ */ /* ----------------------------------------------------- */ -int str_checksum(char *str) { - int n = 1; - if(strlen(str) < 6) +int +str_checksum(char *str) +{ + int n = 1; + if (strlen(str) < 6) return 0; - while(*str) - n += *(str++) * (n); + while (*str) + n += *(str++) * (n); return n; } -void str_lower(char *t, char *s) { +void +str_lower(char *t, char *s) +{ register unsigned char ch; do { ch = *s++; *t++ = char_lower(ch); - } while(ch); + } while (ch); } -int strstr_lower(char *str, char *tag) { - char buf[STRLEN]; - +int +strstr_lower(char *str, char *tag) +{ + char buf[STRLEN]; + str_lower(buf, str); return (int)strstr(buf, tag); } -void trim(char *buf) { /* remove trailing space */ - char *p = buf; +void +trim(char *buf) +{ /* remove trailing space */ + char *p = buf; - while(*p) + while (*p) p++; - while(--p >= buf) { - if(*p == ' ') + while (--p >= buf) { + if (*p == ' ') *p = '\0'; else break; @@ -115,98 +149,114 @@ void trim(char *buf) { /* remove trailing space */ /* ----------------------------------------------------- */ /* ¦r¦êÀˬd¨ç¼Æ¡G^¤å¡B¼Æ¦r¡BÀɦW¡BE-mail address */ /* ----------------------------------------------------- */ -int isprint2(char ch) { +int +isprint2(char ch) +{ return ((ch & 0x80) ? 1 : isprint(ch)); //return 1; } -int not_alpha(char ch) { +int +not_alpha(char ch) +{ return (ch < 'A' || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int not_alnum(char ch) { +int +not_alnum(char ch) +{ return (ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') || ch > 'z'); } -int invalid_pname(char *str) { - char *p1, *p2, *p3; - +int +invalid_pname(char *str) +{ + char *p1, *p2, *p3; + p1 = str; - while(*p1) { - if(!(p2 = strchr(p1, '/'))) + while (*p1) { + if (!(p2 = strchr(p1, '/'))) p2 = str + strlen(str); - if(p1 + 1 > p2 || p1 + strspn(p1, ".") == p2) + if (p1 + 1 > p2 || p1 + strspn(p1, ".") == p2) return 1; - for(p3 = p1; p3 < p2; p3++) - if(not_alnum(*p3) && !strchr("@[]-._", *p3)) + for (p3 = p1; p3 < p2; p3++) + if (not_alnum(*p3) && !strchr("@[]-._", *p3)) return 1; p1 = p2 + (*p2 ? 1 : 0); } return 0; } -int valid_ident(char *ident) { - static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", - "@bbs", "guest@", "@ppp", "@slip", NULL}; - char buf[128]; - int i; - +int +valid_ident(char *ident) +{ + static char *invalid[] = {"unknown@", "root@", "gopher@", "bbs@", + "@bbs", "guest@", "@ppp", "@slip", NULL}; + char buf[128]; + int i; + str_lower(buf, ident); - for(i = 0; invalid[i]; i++) - if(strstr(buf, invalid[i])) + for (i = 0; invalid[i]; i++) + if (strstr(buf, invalid[i])) return 0; return 1; } -int is_uBM(char *list, char *id) { - register int len; +int +is_uBM(char *list, char *id) +{ + register int len; - if(list[0] == '[') + if (list[0] == '[') list++; - if(list[0] > ' ') { + if (list[0] > ' ') { len = strlen(id); do { - if(!strncasecmp(list, id, len)) { + if (!strncasecmp(list, id, len)) { list += len; - if((*list == 0) || (*list == '/') || - (*list == ']') || (*list == ' ')) + if ((*list == 0) || (*list == '/') || + (*list == ']') || (*list == ' ')) return 1; } - if((list = strchr(list,'/')) != NULL) + if ((list = strchr(list, '/')) != NULL) list++; else break; - } while(1); + } while (1); } return 0; } -int is_BM(char *list) { - if(is_uBM(list,cuser.userid)) { - cuser.userlevel |= PERM_BM; /* Ptt ¦Û°Ê¥[¤WBMªºÅv§Q */ +int +is_BM(char *list) +{ + if (is_uBM(list, cuser.userid)) { + cuser.userlevel |= PERM_BM; /* Ptt ¦Û°Ê¥[¤WBMªºÅv§Q */ return 1; } return 0; } -int userid_is_BM(char *userid, char *list) { - register int ch, len; - +int +userid_is_BM(char *userid, char *list) +{ + register int ch, len; + ch = list[0]; - if((ch > ' ') && (ch < 128)) { + if ((ch > ' ') && (ch < 128)) { len = strlen(userid); do { - if(!strncasecmp(list, userid, len)) { + if (!strncasecmp(list, userid, len)) { ch = list[len]; - if((ch == 0) || (ch == '/') || (ch == ']')) + if ((ch == 0) || (ch == '/') || (ch == ']')) return 1; } - while((ch = *list++)) { - if(ch == '/') + while ((ch = *list++)) { + if (ch == '/') break; } - } while(ch); + } while (ch); } return 0; } @@ -214,51 +264,63 @@ int userid_is_BM(char *userid, char *list) { /* ----------------------------------------------------- */ /* ÀÉ®×Àˬd¨ç¼Æ¡GÀɮסB¥Ø¿ý¡BÄÝ©ó */ /* ----------------------------------------------------- */ -off_t dashs(char *fname) { - struct stat st; - - if(!stat(fname, &st)) - return st.st_size; +off_t +dashs(char *fname) +{ + struct stat st; + + if (!stat(fname, &st)) + return st.st_size; else - return -1; + return -1; } -long dasht(char *fname) { - struct stat st; - - if(!stat(fname, &st)) - return st.st_mtime; +long +dasht(char *fname) +{ + struct stat st; + + if (!stat(fname, &st)) + return st.st_mtime; else - return -1; + return -1; } -int dashl(char *fname) { - struct stat st; - +int +dashl(char *fname) +{ + struct stat st; + return (lstat(fname, &st) == 0 && S_ISLNK(st.st_mode)); } -int dashf(char *fname) { - struct stat st; - +int +dashf(char *fname) +{ + struct stat st; + return (stat(fname, &st) == 0 && S_ISREG(st.st_mode)); } -int dashd(char *fname) { - struct stat st; +int +dashd(char *fname) +{ + struct stat st; return (stat(fname, &st) == 0 && S_ISDIR(st.st_mode)); } -int belong(char *filelist, char *key) { - FILE *fp; - int rc = 0; - - if((fp = fopen(filelist, "r"))) { - char buf[STRLEN], *ptr; - - while(fgets(buf, STRLEN, fp)) { - if((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, key)) { +int +belong(char *filelist, char *key) +{ + FILE *fp; + int rc = 0; + + if ((fp = fopen(filelist, "r"))) { + char buf[STRLEN], *ptr; + + while (fgets(buf, STRLEN, fp)) { + if ((ptr = strtok(buf, str_space)) && !strcasecmp(ptr, key)) { rc = 1; break; } @@ -268,150 +330,167 @@ int belong(char *filelist, char *key) { return rc; } -time_t gettime(int line, time_t dt) -{ - char yn[7]; - struct tm *ptime = localtime(&dt), endtime; - - memcpy(&endtime, ptime, sizeof(struct tm )); - sprintf(yn, "%4d", ptime->tm_year+1900); - do{ - getdata_buf(line, 0, "¦è¤¸¦~:", yn, 5, LCECHO); - }while( (endtime.tm_year = atoi(yn)-1900)<0 || endtime.tm_year>200); - sprintf(yn, "%d", ptime->tm_mon+1); - do{ - getdata_buf(line, 13, "¤ë:", yn, 3, LCECHO); - }while((endtime.tm_mon = atoi(yn)-1)<0 || endtime.tm_mon>11); - sprintf(yn, "%d", ptime->tm_mday); - do{ - getdata_buf(line, 22, "¤é:", yn, 3, LCECHO); - }while((endtime.tm_mday = atoi(yn))<1 || endtime.tm_mday>31); - sprintf(yn, "%d", ptime->tm_hour); - do{ - getdata_buf(line, 31, "®É(0-23):", yn, 3, LCECHO); - }while(( endtime.tm_hour = atoi(yn))<0 || endtime.tm_hour>23); - return mktime(&endtime); -} -char *Cdate(time_t *clock) { - static char foo[32]; - struct tm *mytm = localtime(clock); - +time_t +gettime(int line, time_t dt) +{ + char yn[7]; + struct tm *ptime = localtime(&dt), endtime; + + memcpy(&endtime, ptime, sizeof(struct tm)); + sprintf(yn, "%4d", ptime->tm_year + 1900); + do { + getdata_buf(line, 0, "¦è¤¸¦~:", yn, 5, LCECHO); + } while ((endtime.tm_year = atoi(yn) - 1900) < 0 || endtime.tm_year > 200); + sprintf(yn, "%d", ptime->tm_mon + 1); + do { + getdata_buf(line, 13, "¤ë:", yn, 3, LCECHO); + } while ((endtime.tm_mon = atoi(yn) - 1) < 0 || endtime.tm_mon > 11); + sprintf(yn, "%d", ptime->tm_mday); + do { + getdata_buf(line, 22, "¤é:", yn, 3, LCECHO); + } while ((endtime.tm_mday = atoi(yn)) < 1 || endtime.tm_mday > 31); + sprintf(yn, "%d", ptime->tm_hour); + do { + getdata_buf(line, 31, "®É(0-23):", yn, 3, LCECHO); + } while ((endtime.tm_hour = atoi(yn)) < 0 || endtime.tm_hour > 23); + return mktime(&endtime); +} +char * +Cdate(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y %T %a", mytm); return foo; } -char *Cdatelite(time_t *clock) { - static char foo[32]; - struct tm *mytm = localtime(clock); - +char * +Cdatelite(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y %T", mytm); return foo; } -char *Cdatedate(time_t *clock){ - static char foo[32]; - struct tm *mytm = localtime(clock); - +char * +Cdatedate(time_t * clock) +{ + static char foo[32]; + struct tm *mytm = localtime(clock); + strftime(foo, 32, "%m/%d/%Y", mytm); return foo; } -static void capture_screen() { - char fname[200]; - FILE* fp; - int i; +static void +capture_screen() +{ + char fname[200]; + FILE *fp; + int i; getdata(b_lines - 2, 0, "§â³oÓµe±¦¬¤J¨ì¼È¦sÀÉ¡H[y/N] ", fname, 4, LCECHO); - if(fname[0] != 'y' ) return; - + if (fname[0] != 'y') + return; + setuserfile(fname, ask_tmpbuf(b_lines - 1)); - if((fp = fopen(fname, "w"))) { - for(i = 0; i < scr_lns; i++) + if ((fp = fopen(fname, "w"))) { + for (i = 0; i < scr_lns; i++) fprintf(fp, "%.*s\n", big_picture[i].len, big_picture[i].data); fclose(fp); } } -void pressanykey() { - int ch; - +void +pressanykey() +{ + int ch; + outmsg("\033[37;45;1m " "¡´ ½Ð«ö \033[33m(Space/Return)\033[37m Ä~Äò ¡´" " \033[33m(^T)\033[37m ¦s¼È¦sÀÉ \033[m"); do { ch = igetkey(); - - if(ch == Ctrl('T')) { + + if (ch == Ctrl('T')) { capture_screen(); break; } - } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); move(b_lines, 0); clrtoeol(); refresh(); } -int vmsg (const char *fmt, ...) +int +vmsg(const char *fmt,...) { - va_list ap; - char msg[80] = {0}; - int ch; + va_list ap; + char msg[80] = {0}; + int ch; - va_start (ap, fmt); - vsprintf (msg, fmt, ap); - va_end (ap); + va_start(ap, fmt); + vsprintf(msg, fmt, ap); + va_end(ap); - move (b_lines, 0); - clrtoeol (); + move(b_lines, 0); + clrtoeol(); - if (*msg) - prints ("\033[1;36;44m ¡» %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[½Ð«ö¥ô·NÁäÄ~Äò]\033[201m \033[m", msg); - else - outs ("\033[46;1m \033[37m" - "\033[200m\033[1431m\033[506m¡¼ ½Ð«ö \033[33m(Space/Return)\033[37m Ä~Äò ¡¼\033[201m" - " \033[m"); + if (*msg) + prints("\033[1;36;44m ¡» %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[½Ð«ö¥ô·NÁäÄ~Äò]\033[201m \033[m", msg); + else + outs("\033[46;1m \033[37m" + "\033[200m\033[1431m\033[506m¡¼ ½Ð«ö \033[33m(Space/Return)\033[37m Ä~Äò ¡¼\033[201m" + " \033[m"); - do { + do { ch = igetkey(); - - if(ch == Ctrl('T')) { + + if (ch == Ctrl('T')) { capture_screen(); break; } - } while((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + - - move (b_lines, 0); - clrtoeol (); - refresh (); - return ch; + move(b_lines, 0); + clrtoeol(); + refresh(); + return ch; } -void bell() { - char c; - +void +bell() +{ + char c; + c = Ctrl('G'); write(1, &c, 1); } -int search_num(int ch, int max) { - int clen = 1; - int x, y; - char genbuf[10]; - +int +search_num(int ch, int max) +{ + int clen = 1; + int x, y; + char genbuf[10]; + outmsg("\033[7m ¸õ¦Ü²Ä´X¶µ¡G\033[m"); outc(ch); genbuf[0] = ch; getyx(&y, &x); x--; - while((ch = igetch()) != '\r') { - if(ch == 'q' || ch == 'e') + while ((ch = igetch()) != '\r') { + if (ch == 'q' || ch == 'e') return -1; - if(ch == '\n') + if (ch == '\n') break; - if(ch == '\177' || ch == Ctrl('H')) { - if(clen == 0) { + if (ch == '\177' || ch == Ctrl('H')) { + if (clen == 0) { bell(); continue; } @@ -421,11 +500,11 @@ int search_num(int ch, int max) { move(y, x + clen); continue; } - if(!isdigit(ch)) { + if (!isdigit(ch)) { bell(); continue; } - if(x + clen >= scr_cols || clen >= 6) { + if (x + clen >= scr_cols || clen >= 6) { bell(); continue; } @@ -435,35 +514,43 @@ int search_num(int ch, int max) { genbuf[clen] = '\0'; move(b_lines, 0); clrtoeol(); - if(genbuf[0] == '\0') + if (genbuf[0] == '\0') return -1; clen = atoi(genbuf); - if(clen == 0) + if (clen == 0) return 0; - if(clen > max) + if (clen > max) return max; return clen - 1; } -void stand_title(char *title) { +void +stand_title(char *title) +{ clear(); prints("\033[1;37;46m¡i %s ¡j\033[m\n", title); } -void cursor_show(int row, int column) { +void +cursor_show(int row, int column) +{ move(row, column); outs(STR_CURSOR); move(row, column + 1); } -void cursor_clear(int row, int column) { +void +cursor_clear(int row, int column) +{ move(row, column); outs(STR_UNCUR); } -int cursor_key(int row, int column) { - int ch; - +int +cursor_key(int row, int column) +{ + int ch; + cursor_show(row, column); ch = egetch(); move(row, column); @@ -471,51 +558,55 @@ int cursor_key(int row, int column) { return ch; } -void printdash(char *mesg) { - int head = 0, tail; - - if(mesg) +void +printdash(char *mesg) +{ + int head = 0, tail; + + if (mesg) head = (strlen(mesg) + 1) >> 1; - + tail = head; - - while(head++ < 38) + + while (head++ < 38) outch('-'); - - if(tail) { + + if (tail) { outch(' '); outs(mesg); outch(' '); } - - while(tail++ < 38) + while (tail++ < 38) outch('-'); outch('\n'); } -int log_file(char *filename,char *buf) { - FILE *fp; +int +log_file(char *filename, char *buf) +{ + FILE *fp; - if((fp = fopen(filename, "a" )) != NULL ) { - fputs( buf, fp ); - if(!strchr(buf,'\n')) - fputc('\n',fp); - fclose( fp ); - return 0; - } - else + if ((fp = fopen(filename, "a")) != NULL) { + fputs(buf, fp); + if (!strchr(buf, '\n')) + fputc('\n', fp); + fclose(fp); + return 0; + } else return -1; } -void show_help(char *helptext[]) { - char *str; - int i; - +void +show_help(char *helptext[]) +{ + char *str; + int i; + clear(); - for(i = 0; (str = helptext[i]); i++) { - if(*str == '\0') + for (i = 0; (str = helptext[i]); i++) { + if (*str == '\0') prints("\033[1m¡i %s ¡j\033[0m\n", str + 1); - else if(*str == '\01') + else if (*str == '\01') prints("\n\033[36m¡i %s ¡j\033[m\n", str + 1); else prints(" %s\n", str); diff --git a/mbbsd/syspost.c b/mbbsd/syspost.c index 3039cd6b..15caf482 100644 --- a/mbbsd/syspost.c +++ b/mbbsd/syspost.c @@ -1,39 +1,41 @@ -/* $Id: syspost.c,v 1.11 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: syspost.c,v 1.12 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { - FILE *fp; - fileheader_t fhdr; - char genbuf[200], reason[30]; - int i, flag=0; - +void +post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) +{ + FILE *fp; + fileheader_t fhdr; + char genbuf[200], reason[30]; + int i, flag = 0; + strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) + if (!(fp = fopen(genbuf, "w"))) return; - + fprintf(fp, "§@ªÌ: [¨t²Î¦w¥þ§½] ¬ÝªO: Security\n" "¼ÐÃD: [¤½¦w³ø§i] ¯¸ªøקïÅv³ø§i\n" "®É¶¡: %s\n", ctime(&now)); - for(i = 5; i < NUMPERMS; i++) { - if(((oldperm >> i) & 1) != ((newperm >> i) & 1)) { - fprintf (fp, " ¯¸ªø\033[1;32m%s%s%s%s\033[mªºÅv\n", - sysopid, - (((oldperm >> i) & 1) ? "\033[1;33mÃö³¬":"\033[1;33m¶}±Ò"), - userid, str_permid[i]); - flag++; - } + for (i = 5; i < NUMPERMS; i++) { + if (((oldperm >> i) & 1) != ((newperm >> i) & 1)) { + fprintf(fp, " ¯¸ªø\033[1;32m%s%s%s%s\033[mªºÅv\n", + sysopid, + (((oldperm >> i) & 1) ? "\033[1;33mÃö³¬" : "\033[1;33m¶}±Ò"), + userid, str_permid[i]); + flag++; + } } - - if(flag) { + + if (flag) { clrtobot(); clear(); - while(!getdata_str(5, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", - reason, sizeof(reason), DOECHO, "¬ÝªOªO¥D:")); + while (!getdata_str(5, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", + reason, sizeof(reason), DOECHO, "¬ÝªOªO¥D:")); fprintf(fp, "\n \033[1;37m¯¸ªø%sקïÅv²z¥Ñ¬O¡G%s\033[m", cuser.userid, reason); fclose(fp); - + sprintf(fhdr.title, "[¤½¦w³ø§i] ¯¸ªø%sקï%sÅv³ø§i", cuser.userid, userid); strcpy(fhdr.owner, "[¨t²Î¦w¥þ§½]"); @@ -41,14 +43,16 @@ void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { } } -void post_violatelaw(char* crime, char* police, char* reason, char* result){ - char genbuf[200]; - fileheader_t fhdr; - FILE *fp; +void +post_violatelaw(char *crime, char *police, char *reason, char *result) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "§@ªÌ: [Pttªk°|] ¬ÝªO: Security\n" "¼ÐÃD: [³ø§i] %-20s ¹Hªk§P¨M³ø§i\n" "®É¶¡: %s\n" @@ -59,11 +63,11 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ sprintf(fhdr.title, "[³ø§i] %-20s ¹Hªk§P¨M³ø§i", crime); strcpy(fhdr.owner, "[Pttªk°|]"); append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); - + strcpy(genbuf, "boards/V/ViolateLaw"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "§@ªÌ: [Pttªk°|] ¬ÝªO: ViolateLaw\n" "¼ÐÃD: [³ø§i] %-20s ¹Hªk§P¨M³ø§i\n" "®É¶¡: %s\n" @@ -73,40 +77,44 @@ void post_violatelaw(char* crime, char* police, char* reason, char* result){ fclose(fp); sprintf(fhdr.title, "[³ø§i] %-20s ¹Hªk§P¨M³ø§i", crime); strcpy(fhdr.owner, "[Pttªk°|]"); - + append_record("boards/V/ViolateLaw/.DIR", &fhdr, sizeof(fhdr)); - + } -void post_newboard(char* bgroup, char* bname, char* bms){ - char genbuf[256], title[128]; +void +post_newboard(char *bgroup, char *bname, char *bms) +{ + char genbuf[256], title[128]; sprintf(title, "[·sªO¦¨¥ß] %s", bname); sprintf(genbuf, "%s ¶}¤F¤@Ó·sªO %s : %s\n\n·s¥ôªO¥D¬° %s\n\n®¥³ß*^_^*\n", - cuser.userid, bname, bgroup, bms); - post_msg("Record", title, genbuf, "[¨t²Î]"); + cuser.userid, bname, bgroup, bms); + post_msg("Record", title, genbuf, "[¨t²Î]"); } -void give_money_post(char *userid, int money) { - FILE *fp; - fileheader_t fhdr; - time_t now = time(0); - char genbuf[200]; +void +give_money_post(char *userid, int money) +{ + FILE *fp; + fileheader_t fhdr; + time_t now = time(0); + char genbuf[200]; strcpy(genbuf, "boards/S/Security"); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "§@ªÌ: [¨t²Î¦w¥þ§½] ¬ÝªO: Security\n" - "¼ÐÃD: [¤½¦w³ø§i] ¯¸ªø%s¨Ï¥Î¬õ¥]¾÷³ø§i\n" - "®É¶¡: %s\n", cuser.userid, ctime(&now)); - clrtobot(); - clear(); - fprintf(fp, "\n ¯¸ªø\033[1;32m%s\033[mµ¹\033[1;33m%s %d ¤¸\033[m", - cuser.userid, userid, money); + "¼ÐÃD: [¤½¦w³ø§i] ¯¸ªø%s¨Ï¥Î¬õ¥]¾÷³ø§i\n" + "®É¶¡: %s\n", cuser.userid, ctime(&now)); + clrtobot(); + clear(); + fprintf(fp, "\n ¯¸ªø\033[1;32m%s\033[mµ¹\033[1;33m%s %d ¤¸\033[m", + cuser.userid, userid, money); - fclose(fp); - sprintf(fhdr.title, "[¤½¦w³ø§i] ¯¸ªø%s¨Ï¥Î¬õ¥]¾÷³ø§i", - cuser.userid); - strcpy(fhdr.owner, "[¨t²Î¦w¥þ§½]"); - append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); + fclose(fp); + sprintf(fhdr.title, "[¤½¦w³ø§i] ¯¸ªø%s¨Ï¥Î¬õ¥]¾÷³ø§i", + cuser.userid); + strcpy(fhdr.owner, "[¨t²Î¦w¥þ§½]"); + append_record("boards/S/Security/.DIR", &fhdr, sizeof(fhdr)); } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 9c8dba8d..5f62d642 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -1,12 +1,12 @@ -/* $Id: talk.c,v 1.77 2002/07/04 20:08:11 in2 Exp $ */ +/* $Id: talk.c,v 1.78 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define QCAST int (*)(const void *, const void *) -static char *IdleTypeTable[] = { +static char *IdleTypeTable[] = { "°¸¦bªá§b°Õ", "±¡¤H¨Ó¹q", "³V¹¤¤", "«ô¨£©P¤½", "°²¦ºª¬ºA", "§Ú¦b«ä¦Ò" }; -static char *sig_des[] = { +static char *sig_des[] = { "°«Âû", "²á¤Ñ", "", "¤U´Ñ", "¶H´Ñ", "·t´Ñ" }; @@ -17,103 +17,104 @@ static char *sig_des[] = { #define BOARDFRI 1 typedef struct talkwin_t { - int curcol, curln; - int sline, eline; -} talkwin_t; + int curcol, curln; + int sline, eline; +} talkwin_t; typedef struct pickup_t { - userinfo_t *ui; - int friend, uoffset; -} pickup_t; + userinfo_t *ui; + int friend, uoffset; +} pickup_t; -//extern int bind( /* int,struct sockaddr *, int */ ); -//extern char *getuserid(); +//extern int bind( /* int,struct sockaddr *, int */ ); +//extern char *getuserid(); /* °O¿ý friend ªº user number */ -//#define PICKUP_WAYS 7 //Ãö±¼¤k¤hÀu¥ý +// +#define PICKUP_WAYS 7 //Ãö±¼¤k¤hÀu¥ý #define PICKUP_WAYS 6 -static char *fcolor[11] = { +static char *fcolor[11] = { "", "\033[36m", "\033[32m", "\033[1;32m", "\033[33m", "\033[1;33m", "\033[1;37m", "\033[1;37m", "\033[31m", "\033[1;35m", "\033[1;36m" }; -static char save_page_requestor[40]; -static char page_requestor[40]; -static char description[30]; -static FILE *flog; +static char save_page_requestor[40]; +static char page_requestor[40]; +static char description[30]; +static FILE *flog; -int iswritable_stat(userinfo_t *uentp, int fri_stat) +int +iswritable_stat(userinfo_t * uentp, int fri_stat) { - if( uentp == currutmp ) + if (uentp == currutmp) return 0; - if( HAS_PERM(PERM_SYSOP) ) + if (HAS_PERM(PERM_SYSOP)) return 1; - if( !HAS_PERM(PERM_LOGINOK) ) + if (!HAS_PERM(PERM_LOGINOK)) return 0; return (uentp->pager != 3 && (fri_stat & HFM || uentp->pager != 4)); } -int isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) +int +isvisible_stat(userinfo_t * me, userinfo_t * uentp, int fri_stat) { if (uentp->userid[0] == 0) return 0; - - if (PERM_HIDE(uentp) && !(PERM_HIDE(me)))/* ¹ï¤èµµ¦âÁô§Î¦Ó§A¨S¦³ */ + + if (PERM_HIDE(uentp) && !(PERM_HIDE(me))) /* ¹ï¤èµµ¦âÁô§Î¦Ó§A¨S¦³ */ return 0; else if ((me->userlevel & PERM_SYSOP) || - ((fri_stat & HRM) && (fri_stat & HFM))) - /* ¯¸ªø¬Ýªº¨£¥ô¦ó¤H */ + ((fri_stat & HRM) && (fri_stat & HFM))) + /* ¯¸ªø¬Ýªº¨£¥ô¦ó¤H */ return 1; - - if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) return 0; + + if (uentp->invisible && !(me->userlevel & PERM_SEECLOAK)) + return 0; return !(fri_stat & HRM); } -char *modestring(userinfo_t * uentp, int simple) +char * +modestring(userinfo_t * uentp, int simple) { - static char modestr[40]; - static char *notonline = "¤£¦b¯¸¤W"; - register int mode = uentp->mode; - register char *word; - int fri_stat; - -/* for debugging */ - if (mode >= MAX_MODES){ + static char modestr[40]; + static char *notonline = "¤£¦b¯¸¤W"; + register int mode = uentp->mode; + register char *word; + int fri_stat; + + /* for debugging */ + if (mode >= MAX_MODES) { syslog(LOG_WARNING, "what!? mode = %d", mode); word = ModeTypeTable[mode % MAX_MODES]; - } - else + } else word = ModeTypeTable[mode]; fri_stat = friend_stat(currutmp, uentp); - if( !(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && + if (!(HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK)) && ((uentp->invisible || (fri_stat & HRM)) && - !((fri_stat & HFM) && (fri_stat & HRM))) ) + !((fri_stat & HFM) && (fri_stat & HRM)))) return notonline; - else if (mode == EDITING){ + else if (mode == EDITING) { sprintf(modestr, "E:%s", ModeTypeTable[uentp->destuid < EDITING ? uentp->destuid : EDITING]); word = modestr; - } - else if (!mode && *uentp->chatid == 1){ + } else if (!mode && *uentp->chatid == 1) { if (!simple) sprintf(modestr, "¦^À³ %s", getuserid(uentp->destuid)); else sprintf(modestr, "¦^À³©I¥s"); - } - else if (!mode && *uentp->chatid == 2) - if (uentp->msgcount < 10){ - char *cnum[10] = - {"", "¤@", "¨â", "¤T", "¥|", "¤", "¤»", "¤C", - "¤K", "¤E"}; + } else if (!mode && *uentp->chatid == 2) + if (uentp->msgcount < 10) { + char *cnum[10] = + {"", "¤@", "¨â", "¤T", "¥|", "¤", "¤»", "¤C", + "¤K", "¤E"}; sprintf(modestr, "¤¤%sÁû¤ô²y", cnum[uentp->msgcount]); - } - else + } else sprintf(modestr, "¤£¦æ¤F @_@"); else if (!mode && *uentp->chatid == 3) sprintf(modestr, "¤ô²y·Ç³Æ¤¤"); @@ -125,25 +126,23 @@ char *modestring(userinfo_t * uentp, int simple) return word; else if (uentp->in_chat && mode == CHATING) sprintf(modestr, "%s (%s)", word, uentp->chatid); - else if (mode == TALK){ - if (!isvisible_uid(uentp->destuid))/* Leeym ¹ï¤è(µµ¦â)Áô§Î */ - sprintf(modestr, "%s", "¥æ½Í ªÅ®ð");/* Leeym ¤j®a¦Û¤vµo´§§a¡I */ + else if (mode == TALK) { + if (!isvisible_uid(uentp->destuid)) /* Leeym ¹ï¤è(µµ¦â)Áô§Î */ + sprintf(modestr, "%s", "¥æ½Í ªÅ®ð"); /* Leeym + * ¤j®a¦Û¤vµo´§§a¡I */ else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); - } - else if (mode == M_FIVE){ + } else if (mode == M_FIVE) { if (!isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "¤¤l´Ñ ªÅ®ð"); else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); - } - else if (mode == CHC){ + } else if (mode == CHC) { if (isvisible_uid(uentp->destuid)) sprintf(modestr, "%s", "¤U¶H´Ñ"); else sprintf(modestr, "¤U¶H´Ñ %s", getuserid(uentp->destuid)); - } - else if (mode != PAGE && mode != TQUERY) + } else if (mode != PAGE && mode != TQUERY) return word; else sprintf(modestr, "%s %s", word, getuserid(uentp->destuid)); @@ -151,43 +150,45 @@ char *modestring(userinfo_t * uentp, int simple) return (modestr); } -int set_friend_bit(userinfo_t * me, userinfo_t * ui) { - int unum, *myfriends, hit=0, n; +int +set_friend_bit(userinfo_t * me, userinfo_t * ui) +{ + int unum, *myfriends, hit = 0, n; /* §PÂ_¹ï¤è¬O§_¬°§ÚªºªB¤Í ? */ unum = ui->uid; myfriends = me->friend; - while ((n = *myfriends++)){ - if (unum == n){ + while ((n = *myfriends++)) { + if (unum == n) { hit = IFH; break; } } - + /* §PÂ_§Ú¬O§_¬°¹ï¤èªºªB¤Í ? */ myfriends = ui->friend; - while ((unum = *myfriends++)){ - if (unum == me->uid){ + while ((unum = *myfriends++)) { + if (unum == me->uid) { hit |= HFM; break; } } - -/* §PÂ_¹ï¤è¬O§_¬°§Úªº¤³¤H ? */ + + /* §PÂ_¹ï¤è¬O§_¬°§Úªº¤³¤H ? */ unum = ui->uid; myfriends = me->reject; - while ((n = *myfriends++)){ - if (unum == n){ + while ((n = *myfriends++)) { + if (unum == n) { hit |= IRH; break; } } -/* §PÂ_§Ú¬O§_¬°¹ï¤èªº¤³¤H ? */ + /* §PÂ_§Ú¬O§_¬°¹ï¤èªº¤³¤H ? */ myfriends = ui->reject; - while ((unum = *myfriends++)){ - if (unum == me->uid){ + while ((unum = *myfriends++)) { + if (unum == me->uid) { hit |= HRM; break; } @@ -195,131 +196,136 @@ int set_friend_bit(userinfo_t * me, userinfo_t * ui) { return hit; } -int reverse_friend_stat(int stat) +int +reverse_friend_stat(int stat) { - int stat1=0; - if(stat & IFH) - stat1 |=HFM; - if(stat & IRH) - stat1 |=HRM; - if(stat & HFM) - stat1 |=IFH; - if(stat & HRM) - stat1 |=IRH; - if(stat & IBH) - stat1 |=IBH; - return stat1; + int stat1 = 0; + if (stat & IFH) + stat1 |= HFM; + if (stat & IRH) + stat1 |= HRM; + if (stat & HFM) + stat1 |= IFH; + if (stat & HRM) + stat1 |= IRH; + if (stat & IBH) + stat1 |= IBH; + return stat1; } -int login_friend_online(void) +int +login_friend_online(void) { - userinfo_t *uentp; - int i, stat, stat1; - int offset=(int) (currutmp - &SHM->uinfo[0]); - for (i=0;i<SHM->UTMPnumber && currutmp->friendtotal<MAX_FRIEND; i++){ + userinfo_t *uentp; + int i, stat, stat1; + int offset = (int)(currutmp - &SHM->uinfo[0]); + for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) { uentp = (SHM->sorted[SHM->currsorted][0][i]); - if(uentp && uentp->uid && (stat=set_friend_bit(currutmp,uentp))){ - stat1=reverse_friend_stat(stat); + if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) { + stat1 = reverse_friend_stat(stat); stat <<= 24; - stat |= (int) (uentp - &SHM->uinfo[0]); - currutmp->friend_online[currutmp->friendtotal++]=stat; - if(uentp!=currutmp && uentp->friendtotal<MAX_FRIEND){ + stat |= (int)(uentp - &SHM->uinfo[0]); + currutmp->friend_online[currutmp->friendtotal++] = stat; + if (uentp != currutmp && uentp->friendtotal < MAX_FRIEND) { stat1 <<= 24; stat1 |= offset; - uentp->friend_online[uentp->friendtotal++]=stat1; + uentp->friend_online[uentp->friendtotal++] = stat1; } } - } + } return 0; } -int logout_friend_online(userinfo_t *utmp) +int +logout_friend_online(userinfo_t * utmp) { - int i, j, k; - int offset=(int) (utmp - &SHM->uinfo[0]); - userinfo_t *ui; - while( utmp->friendtotal > 0 ){ - i = utmp->friendtotal-1; + int i, j, k; + int offset = (int)(utmp - &SHM->uinfo[0]); + userinfo_t *ui; + while (utmp->friendtotal > 0) { + i = utmp->friendtotal - 1; j = (utmp->friend_online[i] & 0xFFFFFF); - utmp->friend_online[i]=0; - ui = &SHM->uinfo[j]; - if(ui->pid && ui!=utmp){ - for(k=0; k<ui->friendtotal > 0 && k < MAX_FRIEND && - (int)(ui->friend_online[k] & 0xFFFFFF) !=offset; k++); - if(k<ui->friendtotal){ + utmp->friend_online[i] = 0; + ui = &SHM->uinfo[j]; + if (ui->pid && ui != utmp) { + for (k = 0; k < ui->friendtotal > 0 && k < MAX_FRIEND && + (int)(ui->friend_online[k] & 0xFFFFFF) != offset; k++); + if (k < ui->friendtotal) { ui->friendtotal--; - ui->friend_online[k]=ui->friend_online[ui->friendtotal]; - ui->friend_online[ui->friendtotal]=0; + ui->friend_online[k] = ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal] = 0; } } utmp->friendtotal--; - utmp->friend_online[utmp->friendtotal]=0; + utmp->friend_online[utmp->friendtotal] = 0; } return 0; } -int friend_stat(userinfo_t *me, userinfo_t * ui) +int +friend_stat(userinfo_t * me, userinfo_t * ui) { - int i, j, hit=0; - /* ¬ÝªO¦n¤Í */ - if (me->brc_id && ui->brc_id == me->brc_id){ - hit = IBH; - } - for(i=0;me->friend_online[i] && i < MAX_FRIEND;i++){ - j = (me->friend_online[i] & 0xFFFFFF); - if( 0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j] ){ - hit |= me->friend_online[i] >>24; - break; - } - } - if (PERM_HIDE(ui)) - return hit & ST_FRIEND; - return hit; + int i, j, hit = 0; + /* ¬ÝªO¦n¤Í */ + if (me->brc_id && ui->brc_id == me->brc_id) { + hit = IBH; + } + for (i = 0; me->friend_online[i] && i < MAX_FRIEND; i++) { + j = (me->friend_online[i] & 0xFFFFFF); + if (0 <= j && j < MAX_ACTIVE && ui == &SHM->uinfo[j]) { + hit |= me->friend_online[i] >> 24; + break; + } + } + if (PERM_HIDE(ui)) + return hit & ST_FRIEND; + return hit; } -int isvisible_uid(int tuid) +int +isvisible_uid(int tuid) { - userinfo_t *uentp; + userinfo_t *uentp; - if(!tuid || !(uentp = search_ulist(tuid))) - return 1; + if (!tuid || !(uentp = search_ulist(tuid))) + return 1; return isvisible(currutmp, uentp); } /* ¯u¹ê°Ê§@ */ -static void my_kick(userinfo_t * uentp) +static void +my_kick(userinfo_t * uentp) { - char genbuf[200]; + char genbuf[200]; getdata(1, 0, msg_sure_ny, genbuf, 4, LCECHO); clrtoeol(); - if (genbuf[0] == 'y'){ + if (genbuf[0] == 'y') { sprintf(genbuf, "%s (%s)", uentp->userid, uentp->username); log_usies("KICK ", genbuf); - if((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) + if ((uentp->pid <= 0 || kill(uentp->pid, SIGHUP) == -1) && (errno == ESRCH)) purge_utmp(uentp); outs("½ð¥X¥hÅo"); - } - else + } else outs(msg_cancel); pressanykey(); } -static void chicken_query(char *userid) +static void +chicken_query(char *userid) { - char buf[100]; + char buf[100]; - if (getuser(userid)){ - if (xuser.mychicken.name[0]){ + if (getuser(userid)) { + if (xuser.mychicken.name[0]) { time_diff(&(xuser.mychicken)); - if (!isdeadth(&(xuser.mychicken))){ + if (!isdeadth(&(xuser.mychicken))) { show_chicken_data(&(xuser.mychicken), NULL); sprintf(buf, "\n\n¥H¤W¬O %s ªºÃdª«¸ê®Æ..", userid); outs(buf); } - } - else{ + } else { move(1, 0); clrtobot(); sprintf(buf, "\n\n%s ¨Ã¨S¦³¾iÃdª«..", userid); @@ -329,28 +335,29 @@ static void chicken_query(char *userid) } } -int my_query(char *uident) +int +my_query(char *uident) { - userec_t muser; - int tuid, i, fri_stat=0; + userec_t muser; + int tuid, i, fri_stat = 0; unsigned long int j; - userinfo_t *uentp; - static const char *money[10] = - {"¶Å¥x°ª¿v", "¨ª³h", "²M´H", "´¶³q", "¤p±d", - "¤p´I", "¤¤´I", "¤j´I¯Î", "´I¥i¼Ä°ê", "¤ñº¸»\\¤Ñ"}; - static const char *sex[8] = - {MSG_BIG_BOY, MSG_BIG_GIRL, - MSG_LITTLE_BOY, MSG_LITTLE_GIRL, - MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; - - if ((tuid = getuser(uident))){ + userinfo_t *uentp; + static const char *money[10] = + {"¶Å¥x°ª¿v", "¨ª³h", "²M´H", "´¶³q", "¤p±d", + "¤p´I", "¤¤´I", "¤j´I¯Î", "´I¥i¼Ä°ê", "¤ñº¸»\\¤Ñ"}; + static const char *sex[8] = + {MSG_BIG_BOY, MSG_BIG_GIRL, + MSG_LITTLE_BOY, MSG_LITTLE_GIRL, + MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME}; + + if ((tuid = getuser(uident))) { memcpy(&muser, &xuser, sizeof(muser)); move(1, 0); clrtobot(); move(1, 0); setutmpmode(TQUERY); currutmp->destuid = tuid; - + j = muser.money; for (i = 0; i < 10 && j > 10; i++) j /= 10; @@ -362,20 +369,20 @@ int my_query(char *uident) prints("¡m¤W¯¸¦¸¼Æ¡n%d¦¸", muser.numlogins); move(2, 40); prints("¡m¤å³¹½g¼Æ¡n%d½g\n", muser.numposts); - - if((uentp = (userinfo_t *) search_ulist(tuid))) - fri_stat=friend_stat(currutmp, uentp); + + if ((uentp = (userinfo_t *) search_ulist(tuid))) + fri_stat = friend_stat(currutmp, uentp); prints("\033[1;33m¡m¥Ø«e°ÊºA¡n%-28.28s\033[m", (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? modestring(uentp, 0) : "¤£¦b¯¸¤W"); - + outs(((uentp && uentp->mailalert) || load_mailalert(muser.userid)) ? "¡m¨p¤H«H½c¡n¦³·s¶i«H¥óÁÙ¨S¬Ý\n" : "¡m¨p¤H«H½c¡n©Ò¦³«H¥ó³£¬Ý¹L¤F\n"); prints("¡m¤W¦¸¤W¯¸¡n%-28.28s¡m¤W¦¸¬G¶m¡n%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(¤£¸Ô)")); - if ((uentp && fri_stat&HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) + if ((uentp && fri_stat & HFM && !uentp->invisible) || HAS_PERM(PERM_SYSOP)) prints("¡m ©Ê §O ¡n%-28.28s¡m¨p¦³°]²£¡n%ld »È¨â\n", sex[muser.sex % 8], muser.money); @@ -390,41 +397,45 @@ int my_query(char *uident) return DONOTHING; } -static char t_last_write[200] = ""; +static char t_last_write[200] = ""; -void water_scr(water_t *tw, int which, char type) +void +water_scr(water_t * tw, int which, char type) { - if( type == 1 ){ - int i; - int colors[] = {33, 37, 33, 37, 33}; - move(8 + which, 28);prints(" "); + if (type == 1) { + int i; + int colors[] = {33, 37, 33, 37, 33}; + move(8 + which, 28); + prints(" "); move(8 + which, 28); prints("\033[1;37;45m %c %-14s \033[0m", tw->uin ? ' ' : 'x', tw->userid); - for( i = 0 ; i < 5 ; ++i ){ + for (i = 0; i < 5; ++i) { move(16 + i, 4); prints(" "); move(16 + i, 4); - if( tw->msg[ (tw->top - i + 4) % 5 ].last_call_in[0] != 0 ) + if (tw->msg[(tw->top - i + 4) % 5].last_call_in[0] != 0) prints("\033[0m \033[1;%d;44m¡¹%-64s\033[0m \n", colors[i], - tw->msg[ (tw->top - i + 4) % 5 ].last_call_in); + tw->msg[(tw->top - i + 4) % 5].last_call_in); else prints("\033[0m¡@\n"); } - move(21, 4);prints(" "); + move(21, 4); + prints(" "); move(21, 4); prints("\033[0m \033[1;37;46m%-66s\033[0m \n", tw->msg[5].last_call_in); - move(0, 0);prints(" "); - move(0, 0);prints("\033[0m¤ÏÀ» %s:", tw->userid); + move(0, 0); + prints(" "); + move(0, 0); + prints("\033[0m¤ÏÀ» %s:", tw->userid); clrtoeol(); move(0, strlen(tw->userid) + 6); - } - else{ + } else { move(8 + which, 28); prints("123456789012345678901234567890"); move(8 + which, 28); @@ -434,15 +445,16 @@ void water_scr(water_t *tw, int which, char type) } } -void my_write2(void) +void +my_write2(void) { - int i, ch, currstat0; - char genbuf[256], msg[80], done = 0, c0, which; - water_t *tw; - unsigned char mode0; + int i, ch, currstat0; + char genbuf[256], msg[80], done = 0, c0, which; + water_t *tw; + unsigned char mode0; - if( swater[0] == NULL ) - return; + if (swater[0] == NULL) + return; wmofo = 0; currstat0 = currstat; c0 = currutmp->chatid[0]; @@ -451,17 +463,17 @@ void my_write2(void) currutmp->chatid[0] = 3; currstat = XMODE; - // init screen - move(7, 28); + //init screen + move(7, 28); prints("\033[1;33;46m ¡ô ¤ô²y¤ÏÀ»¹ï¶H ¡õ\033[0m"); - for( i = 0 ; i < 5 ; ++i ) - if( swater[i] == NULL || swater[i]->pid == 0 ) + for (i = 0; i < 5; ++i) + if (swater[i] == NULL || swater[i]->pid == 0) break; - else{ - if( swater[i]->uin && + else { + if (swater[i]->uin && (swater[i]->pid != swater[i]->uin->pid || - swater[i]->userid[0]!=swater[i]->uin->userid[0]) ) - swater[i]->uin = (userinfo_t*)search_ulist_pid(swater[i]->pid); + swater[i]->userid[0] != swater[i]->uin->userid[0])) + swater[i]->uin = (userinfo_t *) search_ulist_pid(swater[i]->pid); water_scr(swater[i], i, 0); } move(15, 4); @@ -474,11 +486,11 @@ void my_write2(void) refresh(); which = 0; - do{ - switch( (ch = igetkey()) ){ + do { + switch ((ch = igetkey())) { case Ctrl('T'): case KEY_UP: - if( water_usies != 1 ){ + if (water_usies != 1) { water_scr(swater[(int)which], which, 0); which = (which - 1 + water_usies) % water_usies; water_scr(swater[(int)which], which, 1); @@ -488,7 +500,7 @@ void my_write2(void) case KEY_DOWN: case Ctrl('R'): - if( water_usies != 1 ){ + if (water_usies != 1) { water_scr(swater[(int)which], which, 0); which = (which + 1 + water_usies) % water_usies; water_scr(swater[(int)which], which, 1); @@ -504,57 +516,56 @@ void my_write2(void) done = 1; tw = swater[(int)which]; - if( !tw->uin ) + if (!tw->uin) break; - if( ch != '\r' && ch != '\n' ){ + if (ch != '\r' && ch != '\n') { msg[0] = ch, msg[1] = 0; - } - else + } else msg[0] = 0; - move(0, 0);prints("\033[m"); clrtoeol(); + move(0, 0); + prints("\033[m"); + clrtoeol(); sprintf(genbuf, "§ðÀ» %s:", tw->userid); - if( !oldgetdata(0, 0, genbuf, msg, - 80-strlen(tw->userid)-6, DOECHO) ) + if (!oldgetdata(0, 0, genbuf, msg, + 80 - strlen(tw->userid) - 6, DOECHO)) break; - if( my_write(tw->pid, msg, tw->userid, 4, tw->uin) ) + if (my_write(tw->pid, msg, tw->userid, 4, tw->uin)) strncpy(tw->msg[5].last_call_in, t_last_write, sizeof(tw->msg[5].last_call_in)); break; } - } while( !done ); + } while (!done); currstat = currstat0; currutmp->chatid[0] = c0; currutmp->mode = mode0; - if( wmofo == 1 ) + if (wmofo == 1) write_request(0); wmofo = -1; } -/* - ³Q©I¥sªº®É¾÷: - 1. ¥á¸s²Õ¤ô²y flag = 1 (pre-edit) - 2. ¦^¤ô²y flag = 0 - 3. ¤W¯¸aloha flag = 2 (pre-edit) - 4. ¼s¼½ flag = 3 if SYSOP, otherwise flag = 1 (pre-edit) - 5. ¥á¤ô²y flag = 0 - 6. my_write2 flag = 4 (pre-edit) but confirm -*/ -int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) +/* + * ³Q©I¥sªº®É¾÷: 1. ¥á¸s²Õ¤ô²y flag = 1 (pre-edit) 2. ¦^¤ô²y flag = 0 3. + * ¤W¯¸aloha flag = 2 (pre-edit) 4. ¼s¼½ flag = 3 if SYSOP, otherwise + * flag = 1 (pre-edit) 5. ¥á¤ô²y flag = 0 6. my_write2 flag = 4 + * (pre-edit) but confirm + */ +int +my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) { - int len, currstat0 = currstat, fri_stat; - char msg[80], destid[IDLEN + 1]; - char genbuf[200], buf[200], c0 = currutmp->chatid[0]; - unsigned char mode0 = currutmp->mode; - struct tm *ptime; - userinfo_t *uin; - uin = (puin != NULL) ? puin : (userinfo_t *)search_ulist_pid(pid); + int len, currstat0 = currstat, fri_stat; + char msg[80], destid[IDLEN + 1]; + char genbuf[200], buf[200], c0 = currutmp->chatid[0]; + unsigned char mode0 = currutmp->mode; + struct tm *ptime; + userinfo_t *uin; + uin = (puin != NULL) ? puin : (userinfo_t *) search_ulist_pid(pid); strcpy(destid, id); - - if(!uin && !(flag == 0 && water_which->count> 0)) { - outmsg("\033[1;33;41mÁV¿|! ¹ï¤è¤w¸¨¶]¤F(¤£¦b¯¸¤W)! \033[37m~>_<~\033[m"); + + if (!uin && !(flag == 0 && water_which->count > 0)) { + outmsg("\033[1;33;41mÁV¿|! ¹ï¤è¤w¸¨¶]¤F(¤£¦b¯¸¤W)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); watermode = -1; @@ -563,13 +574,13 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currutmp->mode = 0; currutmp->chatid[0] = 3; currstat = XMODE; - + ptime = localtime(&now); - - if(flag == 0) { + + if (flag == 0) { /* ¤@¯ë¤ô²y */ watermode = 0; - if(!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { + if (!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { outmsg("\033[1;33;42mºâ¤F! ©ñ§A¤@°¨...\033[m"); clrtoeol(); refresh(); @@ -579,12 +590,11 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) watermode = -1; return 0; } - - if(watermode > 0) { - int i; - - i = (water_which->top- watermode + MAX_REVIEW) % MAX_REVIEW; - uin = (userinfo_t *)search_ulist_pid(water_which->msg[i].pid); + if (watermode > 0) { + int i; + + i = (water_which->top - watermode + MAX_REVIEW) % MAX_REVIEW; + uin = (userinfo_t *) search_ulist_pid(water_which->msg[i].pid); strcpy(destid, water_which->msg[i].userid); } } else { @@ -592,12 +602,12 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) strcpy(msg, prompt); len = strlen(msg); } - + strip_ansi(msg, msg, 0); - if(uin && *uin->userid && (flag == 0 || flag == 4)) { + if (uin && *uin->userid && (flag == 0 || flag == 4)) { sprintf(buf, "¥áµ¹ %s : %s [Y/n]?", uin->userid, msg); getdata(0, 0, buf, genbuf, 3, LCECHO); - if(genbuf[0] == 'n') { + if (genbuf[0] == 'n') { outmsg("\033[1;33;42mºâ¤F! ©ñ§A¤@°¨...\033[m"); clrtoeol(); refresh(); @@ -608,9 +618,8 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) return 0; } } - watermode = -1; - if(!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { + if (!uin || !*uin->userid || strcasecmp(destid, uin->userid)) { outmsg("\033[1;33;41mÁV¿|! ¹ï¤è¤w¸¨¶]¤F(¤£¦b¯¸¤W)! \033[37m~>_<~\033[m"); clrtoeol(); refresh(); @@ -619,37 +628,36 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) currstat = currstat0; return 0; } - - fri_stat=friend_stat(currutmp, uin); - if(flag != 2) { /* aloha ªº¤ô²y¤£¥Î¦s¤U¨Ó */ + fri_stat = friend_stat(currutmp, uin); + if (flag != 2) { /* aloha ªº¤ô²y¤£¥Î¦s¤U¨Ó */ /* ¦s¨ì¦Û¤vªº¤ô²yÀÉ */ - if(!fp_writelog){ + if (!fp_writelog) { sethomefile(genbuf, cuser.userid, fn_writelog); fp_writelog = fopen(genbuf, "a"); } - if(fp_writelog) { - fprintf(fp_writelog, "To %s: %s [%s]\n", + if (fp_writelog) { + fprintf(fp_writelog, "To %s: %s [%s]\n", uin->userid, msg, Cdatelite(&now)); snprintf(t_last_write, 66, "To %s: %s", uin->userid, msg); } } - - if(flag == 3 && uin->msgcount) { + if (flag == 3 && uin->msgcount) { /* ¤£À´ */ uin->destuip = currutmp - &SHM->uinfo[0]; uin->sig = 2; - if(uin->pid > 0) kill(uin->pid, SIGUSR1); - } else if(flag != 2 && - !HAS_PERM(PERM_SYSOP) && - (uin->pager == 3 || - uin->pager == 2 || - (uin->pager == 4 && - !(fri_stat & HFM)))) + if (uin->pid > 0) + kill(uin->pid, SIGUSR1); + } else if (flag != 2 && + !HAS_PERM(PERM_SYSOP) && + (uin->pager == 3 || + uin->pager == 2 || + (uin->pager == 4 && + !(fri_stat & HFM)))) outmsg("\033[1;33;41mÁV¿|! ¹ï¤è¨¾¤ô¤F! \033[37m~>_<~\033[m"); else { - if(uin->msgcount < MAX_MSGS) { - unsigned char pager0 = uin->pager; - + if (uin->msgcount < MAX_MSGS) { + unsigned char pager0 = uin->pager; + uin->pager = 2; uin->msgs[uin->msgcount].pid = currpid; strcpy(uin->msgs[uin->msgcount].userid, cuser.userid); @@ -657,80 +665,78 @@ int my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t *puin) uin->pager = pager0; } else if (flag != 2) outmsg("\033[1;33;41mÁV¿|! ¹ï¤è¤£¦æ¤F! (¦¬¨ì¤Ó¦h¤ô²y) \033[37m@_@\033[m"); - - if(uin->msgcount >= 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) + + if (uin->msgcount >= 1 && (uin->pid <= 0 || kill(uin->pid, SIGUSR2) == -1) && flag != 2) outmsg("\033[1;33;41mÁV¿|! ¨S¥´¤¤! \033[37m~>_<~\033[m"); - else if(uin->msgcount == 1 && flag != 2) + else if (uin->msgcount == 1 && flag != 2) outmsg("\033[1;33;44m¤ô²y¯{¹L¥h¤F! \033[37m*^o^*\033[m"); - else if(uin->msgcount > 1 && uin->msgcount < MAX_MSGS && flag != 2) + else if (uin->msgcount > 1 && uin->msgcount < MAX_MSGS && flag != 2) outmsg("\033[1;33;44m¦A¸É¤W¤@²É! \033[37m*^o^*\033[m"); } - + clrtoeol(); refresh(); - + currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; return 1; } -void t_display_new(void) +void +t_display_new(void) { - static int t_display_new_flag=0; - int i, off=2; + static int t_display_new_flag = 0; + int i, off = 2; if (t_display_new_flag) return; else t_display_new_flag = 1; - if( WATERMODE(WATER_ORIG) ) + if (WATERMODE(WATER_ORIG)) water_which = &water[0]; else - off =3; + off = 3; - if (water[0].count && watermode > 0){ + if (water[0].count && watermode > 0) { move(1, 0); outs("¢w¢w¢w¢w¢w¢w¢w¤ô¢w²y¢w¦^¢wÅU¢w¢w¢w"); - outs(WATERMODE(WATER_ORIG) ? + outs(WATERMODE(WATER_ORIG) ? "¢w¢w¢w¢w¢w¢w¥Î[Ctrl-R Ctrl-T]Áä¤Á´«¢w¢w¢w¢w¢w" : "¥Î[Ctrl-R Ctrl-T Ctrl-F Ctrl-G ]Áä¤Á´«¢w¢w¢w¢w"); - if( WATERMODE(WATER_NEW) ){ + if (WATERMODE(WATER_NEW)) { move(2, 0); clrtoeol(); - for (i = 0; i<6 ; i++){ - if(i>0) - if(swater[i-1]) - { - - if( swater[i-1]->uin && - (swater[i-1]->pid != swater[i-1]->uin->pid || - swater[i-1]->userid[0]!=swater[i-1]->uin->userid[0]) ) - swater[i-1]->uin = (userinfo_t*)search_ulist_pid(swater[i-1]->pid); - prints("%s%c%-13.13s\033[m", - swater[i-1]!=water_which? "" : - swater[i-1]->uin?"\033[1;33;47m": - "\033[1;33;45m", - !swater[i-1]->uin?'#':' ', - swater[i-1]->userid); - } - else - prints(" "); + for (i = 0; i < 6; i++) { + if (i > 0) + if (swater[i - 1]) { + + if (swater[i - 1]->uin && + (swater[i - 1]->pid != swater[i - 1]->uin->pid || + swater[i - 1]->userid[0] != swater[i - 1]->uin->userid[0])) + swater[i - 1]->uin = (userinfo_t *) search_ulist_pid(swater[i - 1]->pid); + prints("%s%c%-13.13s\033[m", + swater[i - 1] != water_which ? "" : + swater[i - 1]->uin ? "\033[1;33;47m" : + "\033[1;33;45m", + !swater[i - 1]->uin ? '#' : ' ', + swater[i - 1]->userid); + } else + prints(" "); else prints("%s ¥þ³¡ \033[m", - water_which==&water[0]?"\033[1;33;47m ": + water_which == &water[0] ? "\033[1;33;47m " : " " - ); + ); } } - - for (i = 0; i < water_which->count; i++){ - int a = (water_which->top - i - 1 + MAX_REVIEW) % MAX_REVIEW, - len = 75-strlen(water_which->msg[a].last_call_in) - -strlen(water_which->msg[a].userid); - if(len<0) len=0; - - move(i + (WATERMODE(WATER_ORIG)?2:3), 0); + for (i = 0; i < water_which->count; i++) { + int a = (water_which->top - i - 1 + MAX_REVIEW) % MAX_REVIEW, len = 75 - strlen(water_which->msg[a].last_call_in) + - strlen(water_which->msg[a].userid); + if (len < 0) + len = 0; + + move(i + (WATERMODE(WATER_ORIG) ? 2 : 3), 0); clrtoeol(); if (watermode - 1 != i) prints("\033[1;33;46m %s \033[37;45m %s \033[m%*s", @@ -740,12 +746,12 @@ void t_display_new(void) else prints("\033[1;44m>\033[1;33;47m%s " "\033[37;45m %s \033[m%*s", - water_which->msg[a].userid, + water_which->msg[a].userid, water_which->msg[a].last_call_in, - len,""); + len, ""); } - - if (t_last_write[0]){ + + if (t_last_write[0]) { move(i + off, 0); clrtoeol(); prints(t_last_write); @@ -754,34 +760,34 @@ void t_display_new(void) move(i + off, 0); outs("¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w"); - if( WATERMODE(WATER_NEW) ) - while( i++ <= water[0].count ) { - move(i + off, 0); - clrtoeol(); - } + if (WATERMODE(WATER_NEW)) + while (i++ <= water[0].count) { + move(i + off, 0); + clrtoeol(); + } } - t_display_new_flag = 0; } -int t_display(void) +int +t_display(void) { - char genbuf[200], ans[4]; - if(fp_writelog){ + char genbuf[200], ans[4]; + if (fp_writelog) { fclose(fp_writelog); - fp_writelog=NULL; + fp_writelog = NULL; } setuserfile(genbuf, fn_writelog); - if (more(genbuf, YEA) != -1){ + if (more(genbuf, YEA) != -1) { move(b_lines - 4, 0); outs("\033[1;33;45m¡¹²{¦b Ptt´£¨Ñ³Ð·sªº¤ô²y¾ã²zµ{¦¡¡¹\033[m\n" "±z±N¤ô²y¦s¦Ü«H½c«á, ¦b¡i¶l¥ó¿ï³æ¡j¸Ó«H¥ó«e«ö u,\n" "¨t²Î§Y·|±N±zªº¤ô²y¬ö¿ý«·s¾ã²z«á±H°eµ¹±zò! \n"); getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M) «O¯d(R) (C/M/R)?[R]", ans, sizeof(ans), LCECHO); - if (*ans == 'm'){ - fileheader_t mymail; - char title[128], buf[80]; + if (*ans == 'm') { + fileheader_t mymail; + char title[128], buf[80]; sethomepath(buf, cuser.userid); stampfile(buf, &mymail); @@ -792,15 +798,15 @@ int t_display(void) sethomedir(title, cuser.userid); Rename(genbuf, buf); append_record(title, &mymail, sizeof(mymail)); - } - else if (*ans == 'c') + } else if (*ans == 'c') unlink(genbuf); return FULLUPDATE; } return DONOTHING; } -static void do_talk_nextline(talkwin_t * twin) +static void +do_talk_nextline(talkwin_t * twin) { twin->curcol = 0; if (twin->curln < twin->eline) @@ -810,13 +816,14 @@ static void do_talk_nextline(talkwin_t * twin) move(twin->curln, twin->curcol); } -static void do_talk_char(talkwin_t * twin, int ch) +static void +do_talk_char(talkwin_t * twin, int ch) { - screenline_t *line; - int i; - char ch0, buf[81]; + screenline_t *line; + int i; + char ch0, buf[81]; - if (isprint2(ch)){ + if (isprint2(ch)) { ch0 = big_picture[twin->curln].data[twin->curcol]; if (big_picture[twin->curln].len < 79) move(twin->curln, twin->curcol); @@ -825,7 +832,7 @@ static void do_talk_char(talkwin_t * twin, int ch) outc(ch); ++(twin->curcol); line = big_picture + twin->curln; - if (twin->curcol < line->len){ /* insert */ + if (twin->curcol < line->len) { /* insert */ ++(line->len); memcpy(buf, line->data + twin->curcol, 80); save_cursor(); @@ -838,15 +845,14 @@ static void do_talk_char(talkwin_t * twin, int ch) line->data[line->len] = 0; return; } - - switch (ch){ + switch (ch) { case Ctrl('H'): case '\177': if (twin->curcol == 0) return; line = big_picture + twin->curln; --(twin->curcol); - if (twin->curcol < line->len){ + if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -860,7 +866,7 @@ static void do_talk_char(talkwin_t * twin, int ch) return; case Ctrl('D'): line = big_picture + twin->curln; - if (twin->curcol < line->len){ + if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); @@ -875,13 +881,13 @@ static void do_talk_char(talkwin_t * twin, int ch) bell(); return; case Ctrl('B'): - if (twin->curcol > 0){ + if (twin->curcol > 0) { --(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('F'): - if (twin->curcol < 79){ + if (twin->curcol < 79) { ++(twin->curcol); move(twin->curln, twin->curcol); } @@ -919,7 +925,7 @@ static void do_talk_char(talkwin_t * twin, int ch) line = big_picture + twin->curln; strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; - if (twin->curln > twin->sline){ + if (twin->curln > twin->sline) { --(twin->curln); move(twin->curln, twin->curcol); } @@ -928,7 +934,7 @@ static void do_talk_char(talkwin_t * twin, int ch) line = big_picture + twin->curln; strncpy(buf, (char *)line->data, line->len); buf[line->len] = 0; - if (twin->curln < twin->eline){ + if (twin->curln < twin->eline) { ++(twin->curln); move(twin->curln, twin->curcol); } @@ -943,15 +949,16 @@ static void do_talk_char(talkwin_t * twin, int ch) (ch == Ctrl('P')) ? "\033[37;45m(Up)\033[m" : "\033[m"); } -static void do_talk(int fd) +static void +do_talk(int fd) { struct talkwin_t mywin, itswin; - char mid_line[128], data[200]; - int i, datac, ch; - int im_leaving = 0; - FILE *log; - struct tm *ptime; - char genbuf[200], fpath[100]; + char mid_line[128], data[200]; + int i, datac, ch; + int im_leaving = 0; + FILE *log; + struct tm *ptime; + char genbuf[200], fpath[100]; ptime = localtime(&now); @@ -972,7 +979,7 @@ static void do_talk(int fd) i = ch - strlen(genbuf); if (i >= 0) i = (i >> 1) + 1; - else{ + else { genbuf[ch] = '\0'; i = 1; } @@ -997,17 +1004,16 @@ static void do_talk(int fd) add_io(fd, 0); - while (1){ + while (1) { ch = igetkey(); - if (ch == I_OTHERDATA){ + if (ch == I_OTHERDATA) { datac = recv(fd, data, sizeof(data), 0); if (datac <= 0) break; for (i = 0; i < datac; i++) do_talk_char(&itswin, data[i]); - } - else{ - if (ch == Ctrl('C')){ + } else { + if (ch == Ctrl('C')) { if (im_leaving) break; move(b_lines, 0); @@ -1016,12 +1022,12 @@ static void do_talk(int fd) im_leaving = 1; continue; } - if (im_leaving){ + if (im_leaving) { move(b_lines, 0); clrtoeol(); im_leaving = 0; } - switch (ch){ + switch (ch) { case KEY_LEFT: /* §â2byteªºÁä§ï¬°¤@byte */ ch = Ctrl('B'); break; @@ -1035,11 +1041,11 @@ static void do_talk(int fd) ch = Ctrl('N'); break; } - data[0] = (char) ch; + data[0] = (char)ch; if (send(fd, data, 1, 0) != 1) break; if (log) - fprintf(log, "%c", (ch == Ctrl('M')) ? '\n' : (char) *data); + fprintf(log, "%c", (ch == Ctrl('M')) ? '\n' : (char)*data); do_talk_char(&mywin, *data); } } @@ -1049,9 +1055,9 @@ static void do_talk(int fd) add_io(0, 0); close(fd); - if (flog){ - char ans[4]; - int i; + if (flog) { + char ans[4]; + int i; fprintf(flog, "\n\033[33;44mÂ÷§Oµe± [%s] ... \033[m\n", Cdatelite(&now)); @@ -1061,37 +1067,38 @@ static void do_talk(int fd) more(fpath, NA); getdata(b_lines - 1, 0, "²M°£(C) ²¾¦Ü³Æ§Ñ¿ý(M). (C/M)?[C]", ans, sizeof(ans), LCECHO); - if (*ans == 'm'){ - fileheader_t mymail; - char title[128]; + if (*ans == 'm') { + fileheader_t mymail; + char title[128]; sethomepath(genbuf, cuser.userid); stampfile(genbuf, &mymail); - mymail.filemode = FILE_READ|FILE_HOLD; + mymail.filemode = FILE_READ | FILE_HOLD; strcpy(mymail.owner, "[³Æ.§Ñ.¿ý]"); sprintf(mymail.title, "¹ï¸Ü°O¿ý \033[1;36m(%s)\033[m", getuserid(currutmp->destuid)); sethomedir(title, cuser.userid); Rename(fpath, genbuf); append_record(title, &mymail, sizeof(mymail)); - } - else + } else unlink(fpath); flog = 0; } setutmpmode(XINFO); } -#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return +#define lockreturn(unmode, state) if(lockutmpmode(unmode, state)) return -static void my_talk(userinfo_t * uin, int fri_stat) { - int sock, msgsock, length, ch, error = 0; +static void +my_talk(userinfo_t * uin, int fri_stat) +{ + int sock, msgsock, length, ch, error = 0; struct sockaddr_in server; - pid_t pid; - char c; - char genbuf[4]; + pid_t pid; + char c; + char genbuf[4]; - unsigned char mode0 = currutmp->mode; + unsigned char mode0 = currutmp->mode; ch = uin->mode; strcpy(currauthor, uin->userid); @@ -1099,31 +1106,26 @@ static void my_talk(userinfo_t * uin, int fri_stat) { if (ch == EDITING || ch == TALK || ch == CHATING || ch == PAGE || ch == MAILALL || ch == MONITOR || ch == M_FIVE || ch == CHC || (!ch && (uin->chatid[0] == 1 || uin->chatid[0] == 3)) || - uin->lockmode == M_FIVE || uin->lockmode == CHC){ + uin->lockmode == M_FIVE || uin->lockmode == CHC) { outs("¤H®a¦b¦£°Õ"); - } - else if (!HAS_PERM(PERM_SYSOP) && - (((fri_stat& HRM) && !(fri_stat& HFM)) || - ((!uin->pager) && !(fri_stat & HFM)) ) ){ + } else if (!HAS_PERM(PERM_SYSOP) && + (((fri_stat & HRM) && !(fri_stat & HFM)) || + ((!uin->pager) && !(fri_stat & HFM)))) { outs("¹ï¤èÃö±¼©I¥s¾¹¤F"); - } - else if (!HAS_PERM(PERM_SYSOP) && - (((fri_stat & HRM) && !(fri_stat& HFM)) || uin->pager == 2 )) { + } else if (!HAS_PERM(PERM_SYSOP) && + (((fri_stat & HRM) && !(fri_stat & HFM)) || uin->pager == 2)) { outs("¹ï¤è©Þ±¼©I¥s¾¹¤F"); - } - else if (!HAS_PERM(PERM_SYSOP) && - !(fri_stat & HFM) && uin->pager == 4){ + } else if (!HAS_PERM(PERM_SYSOP) && + !(fri_stat & HFM) && uin->pager == 4) { outs("¹ï¤è¥u±µ¨ü¦n¤Íªº©I¥s"); - } - else if (!(pid = uin->pid) /*|| (kill(pid, 0) == -1) */ ){ + } else if (!(pid = uin->pid) /* || (kill(pid, 0) == -1) */ ) { //resetutmpent(); outs(msg_usr_left); - } - else{ + } else { showplans(uin->userid); getdata(2, 0, "n©M¥L(¦o) (T)½Í¤Ñ(F)¤U¤¤l´Ñ(P)°«Ãdª«" "(C)¤U¶H´Ñ(D)¤U·t´Ñ(N)¨S¨Æ§ä¿ù¤H¤F?[N] ", genbuf, 4, LCECHO); - switch (*genbuf){ + switch (*genbuf) { case 'y': case 't': uin->sig = SIG_TALK; @@ -1146,7 +1148,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { error = 1; if (!cuser.mychicken.name[0] || !xuser.mychicken.name[0]) error = 2; - if (error){ + if (error) { outmsg(error == 2 ? "¨Ã«D¨â¤H³£¾iÃdª«" : "¦³¤@¤èªºÃdª«¥¿¦b¨Ï¥Î¤¤"); bell(); @@ -1166,7 +1168,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { strcpy(currutmp->mateid, uin->userid); sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0){ + if (sock < 0) { perror("sock err"); unlockutmpmode(); return; @@ -1174,14 +1176,14 @@ static void my_talk(userinfo_t * uin, int fri_stat) { server.sin_family = PF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = 0; - if (bind(sock, (struct sockaddr *) &server, sizeof(server)) < 0){ + if (bind(sock, (struct sockaddr *) & server, sizeof(server)) < 0) { close(sock); perror("bind err"); unlockutmpmode(); return; } length = sizeof(server); - if (getsockname(sock, (struct sockaddr *) &server, (socklen_t*)&length) < 0){ + if (getsockname(sock, (struct sockaddr *) & server, (socklen_t *) & length) < 0) { close(sock); perror("sock name err"); unlockutmpmode(); @@ -1192,27 +1194,27 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->destuid = uin->uid; setutmpmode(PAGE); uin->destuip = currutmp - &SHM->uinfo[0]; - if(pid > 0) kill(pid, SIGUSR1); + if (pid > 0) + kill(pid, SIGUSR1); clear(); prints("¥¿©I¥s %s.....\nÁä¤J Ctrl-D ¤¤¤î....", uin->userid); listen(sock, 1); add_io(sock, 5); - while (1){ + while (1) { ch = igetch(); - if (ch == I_TIMEOUT){ + if (ch == I_TIMEOUT) { ch = uin->mode; if (!ch && uin->chatid[0] == 1 && - uin->destuip == currutmp - &SHM->uinfo[0]){ + uin->destuip == currutmp - &SHM->uinfo[0]) { bell(); outmsg("¹ï¤è¦^À³¤¤..."); refresh(); - } - else if (ch == EDITING || ch == TALK || ch == CHATING || - ch == PAGE || ch == MAILALL || ch == MONITOR || - ch == M_FIVE || ch == CHC || - (!ch && (uin->chatid[0] == 1 || - uin->chatid[0] == 3))){ + } else if (ch == EDITING || ch == TALK || ch == CHATING || + ch == PAGE || ch == MAILALL || ch == MONITOR || + ch == M_FIVE || ch == CHC || + (!ch && (uin->chatid[0] == 1 || + uin->chatid[0] == 3))) { add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1220,8 +1222,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { pressanykey(); unlockutmpmode(); return; - } - else{ + } else { #ifdef linux add_io(sock, 20); /* added for linux... achen */ #endif @@ -1230,7 +1231,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { bell(); uin->destuip = currutmp - &SHM->uinfo[0]; - if(pid <= 0 || kill(pid, SIGUSR1) == -1){ + if (pid <= 0 || kill(pid, SIGUSR1) == -1) { #ifdef linux add_io(sock, 20); /* added 4 linux... achen */ #endif @@ -1243,11 +1244,10 @@ static void my_talk(userinfo_t * uin, int fri_stat) { continue; } } - if (ch == I_OTHERDATA) break; - if (ch == '\004'){ + if (ch == '\004') { add_io(0, 0); close(sock); currutmp->sockactive = currutmp->destuid = 0; @@ -1257,7 +1257,7 @@ static void my_talk(userinfo_t * uin, int fri_stat) { } msgsock = accept(sock, (struct sockaddr *) 0, (socklen_t *) 0); - if (msgsock == -1){ + if (msgsock == -1) { perror("accept"); unlockutmpmode(); return; @@ -1267,11 +1267,11 @@ static void my_talk(userinfo_t * uin, int fri_stat) { currutmp->sockactive = NA; read(msgsock, &c, sizeof c); - if (c == 'y'){ + if (c == 'y') { sprintf(save_page_requestor, "%s (%s)", uin->userid, uin->username); /* gomo */ - switch (uin->sig){ + switch (uin->sig) { case SIG_DARK: main_dark(msgsock, uin); break; @@ -1288,11 +1288,10 @@ static void my_talk(userinfo_t * uin, int fri_stat) { default: do_talk(msgsock); } - } - else{ + } else { move(9, 9); outs("¡i¦^µ¡j "); - switch (c){ + switch (c) { case 'a': outs("§Ú²{¦b«Ü¦£¡A½Ðµ¥¤@·|¨à¦A call §Ú¡A¦n¶Ü¡H"); break; @@ -1310,8 +1309,8 @@ static void my_talk(userinfo_t * uin, int fri_stat) { break; case 'f': { - char msgbuf[60]; - + char msgbuf[60]; + read(msgsock, msgbuf, 60); prints("¹ï¤£°_¡A§Ú²{¦b¤£¯à¸ò§A %s¡A¦]¬°\n", sig_des[uin->sig]); move(10, 18); @@ -1342,23 +1341,25 @@ static void my_talk(userinfo_t * uin, int fri_stat) { #define US_ACTION 1232 #define US_REDRAW 1231 -static void t_showhelp() { +static void +t_showhelp() +{ clear(); outs("\033[36m¡i ¥ð¶¢²á¤Ñ¨Ï¥Î»¡©ú ¡j\033[m\n\n" "(¡ö)(e) µ²§ôÂ÷¶} (h) ¬Ý¨Ï¥Î»¡©ú\n" - "(¡ô)/(¡õ)(n) ¤W¤U²¾°Ê (TAB) ¤Á´«±Æ§Ç¤è¦¡\n" + "(¡ô)/(¡õ)(n) ¤W¤U²¾°Ê (TAB) ¤Á´«±Æ§Ç¤è¦¡\n" "(PgUp)(^B) ¤W¶¿ï³æ ( )(PgDn)(^F) ¤U¶¿ï³æ\n" "(Hm)/($)(Ed) º/§À (S) " "¨Ó·½/¦n¤Í´yz/¾ÔÁZ ¤Á´«\n" "(m) ±H«H (q/c) " "¬d¸ßºô¤Í/Ãdª«\n" "(r) ¾\\Ū«H¥ó (l/C) ¬Ý¤W¦¸¼ö°T/¤Á´«Áô¨\n" - "(f) ¥þ³¡/¦n¤Í¦Cªí (¼Æ¦r) ¸õ¦Ü¸Ó¨Ï¥ÎªÌ\n" - "(p) ¤Á´«©I¥s¾¹ (g/i) µ¹¿ú/¤Á´«¤ß±¡\n" - "(a/d/o) ¦n¤Í ¼W¥[/§R°£/קï (/)(s) ºô¤ÍID/¼ÊºÙ·j´M"); + "(f) ¥þ³¡/¦n¤Í¦Cªí (¼Æ¦r) ¸õ¦Ü¸Ó¨Ï¥ÎªÌ\n" + "(p) ¤Á´«©I¥s¾¹ (g/i) µ¹¿ú/¤Á´«¤ß±¡\n" + "(a/d/o) ¦n¤Í ¼W¥[/§R°£/קï (/)(s) ºô¤ÍID/¼ÊºÙ·j´M"); - if (HAS_PERM(PERM_PAGE)){ + if (HAS_PERM(PERM_PAGE)) { outs("\n\n\033[36m¡i ¥æ½Í±M¥ÎÁä ¡j\033[m\n\n" "(¡÷)(t)(Enter) ¸ò¥L¡þ¦o²á¤Ñ\n" "(w) ¼ö½u Call in\n" @@ -1366,8 +1367,7 @@ static void t_showhelp() { "(b) ¹ï¦n¤Í¼s¼½ (¤@©wn¦b¦n¤Í¦Cªí¤¤)\n" "(^R) §Y®É¦^À³ (¦³¤H Call in §A®É)"); } - - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { outs("\n\n\033[36m¡i ¯¸ªø±M¥ÎÁä ¡j\033[m\n\n"); if (HAS_PERM(PERM_SYSOP)) outs("(u)/(H) ³]©w¨Ï¥ÎªÌ¸ê®Æ/¤Á´«Áô§Î¼Ò¦¡\n"); @@ -1377,38 +1377,33 @@ static void t_showhelp() { } /* -static int listcuent(userinfo_t * uentp) -{ - if((!uentp->invisible || HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) - AddNameList(uentp->userid); - return 0; -} - -static void creat_list() -{ - CreateNameList(); - apply_ulist(listcuent); -} -*/ + * static int listcuent(userinfo_t * uentp) { if((!uentp->invisible || + * HAS_PERM(PERM_SYSOP) || HAS_PERM(PERM_SEECLOAK))) + * AddNameList(uentp->userid); return 0; } + * + * static void creat_list() { CreateNameList(); apply_ulist(listcuent); } + */ /* Kaede show friend description */ -static char *friend_descript(char *uident) { - static char *space_buf = " "; - static char desc_buf[80]; - char fpath[80], name[IDLEN + 2], *desc, *ptr; - int len, flag; - FILE *fp; - char genbuf[200]; +static char * +friend_descript(char *uident) +{ + static char *space_buf = " "; + static char desc_buf[80]; + char fpath[80], name[IDLEN + 2], *desc, *ptr; + int len, flag; + FILE *fp; + char genbuf[200]; setuserfile(fpath, friend_file[0]); - if ((fp = fopen(fpath, "r"))){ + if ((fp = fopen(fpath, "r"))) { sprintf(name, "%s ", uident); len = strlen(name); desc = genbuf + 13; - while ((flag = (int) fgets(genbuf, STRLEN, fp))){ - if (!memcmp(genbuf, name, len)){ + while ((flag = (int)fgets(genbuf, STRLEN, fp))) { + if (!memcmp(genbuf, name, len)) { if ((ptr = strchr(desc, '\n'))) ptr[0] = '\0'; if (desc) @@ -1422,15 +1417,15 @@ static char *friend_descript(char *uident) { return space_buf; return desc_buf; - } - else + } else return space_buf; } -static char *descript(int show_mode, userinfo_t * uentp, time_t diff) +static char * +descript(int show_mode, userinfo_t * uentp, time_t diff) { - switch (show_mode){ - case 1: + switch (show_mode) { + case 1: return friend_descript(uentp->userid); case 0: return (((uentp->pager != 2 && uentp->pager != 3 && diff) || @@ -1455,52 +1450,55 @@ static char *descript(int show_mode, userinfo_t * uentp, time_t diff) } #define MAXPICKUP 20 -static int sort_cmpfriend(const void *a, const void *b) +static int +sort_cmpfriend(const void *a, const void *b) { - if( ((((pickup_t *)a)->friend)&ST_FRIEND) == - ((((pickup_t *)b)->friend)&ST_FRIEND) ) - return strcasecmp( ((pickup_t *)a)->ui->userid, - ((pickup_t *)b)->ui->userid ); + if (((((pickup_t *) a)->friend) & ST_FRIEND) == + ((((pickup_t *) b)->friend) & ST_FRIEND)) + return strcasecmp(((pickup_t *) a)->ui->userid, + ((pickup_t *) b)->ui->userid); else - return (((pickup_t *)b)->friend & ST_FRIEND) - - (((pickup_t *)a)->friend & ST_FRIEND); + return (((pickup_t *) b)->friend & ST_FRIEND) - + (((pickup_t *) a)->friend & ST_FRIEND); } -int pickup_maxpages(int pickupway, int nfriends) +int +pickup_maxpages(int pickupway, int nfriends) { - int number; - if( cuser.uflag & FRIEND_FLAG ) + int number; + if (cuser.uflag & FRIEND_FLAG) number = nfriends; else - number = SHM->UTMPnumber+ - (pickupway == 0 ? nfriends : 0); - return (number-1) / MAXPICKUP +1; + number = SHM->UTMPnumber + + (pickupway == 0 ? nfriends : 0); + return (number - 1) / MAXPICKUP + 1; } -static int pickup_myfriend(pickup_t *friends, - int *myfriend, int *friendme) +static int +pickup_myfriend(pickup_t * friends, + int *myfriend, int *friendme) { - userinfo_t *uentp; - int i, where, frstate, ngets=0; - + userinfo_t *uentp; + int i, where, frstate, ngets = 0; + *myfriend = *friendme = 1; - for( i = 0 ; currutmp->friend_online[i] && i < MAX_FRIEND ; ++i ){ + for (i = 0; currutmp->friend_online[i] && i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if( 0 <= where && where < MAX_ACTIVE && - (uentp = &SHM->uinfo[where]) && uentp->pid && - uentp != currutmp && + if (0 <= where && where < MAX_ACTIVE && + (uentp = &SHM->uinfo[where]) && uentp->pid && + uentp != currutmp && isvisible_stat(currutmp, uentp, frstate = currutmp->friend_online[i] >> 24) && - ( !(frstate & IRH) || ((frstate & IRH) && (frstate & IFH)) ) - ){ + (!(frstate & IRH) || ((frstate & IRH) && (frstate & IFH))) + ) { friends[ngets].ui = uentp; friends[ngets].uoffset = where; friends[ngets++].friend = frstate; - if( frstate & IFH ) - ++*myfriend; - if( frstate & HFM ) - ++*friendme; + if (frstate & IFH) + ++* myfriend; + if (frstate & HFM) + ++* friendme; } } friends[ngets].ui = currutmp; @@ -1508,18 +1506,18 @@ static int pickup_myfriend(pickup_t *friends, return ngets; } -static int pickup_bfriend(pickup_t *friends, int base) +static int +pickup_bfriend(pickup_t * friends, int base) { - userinfo_t *uentp; - int i, ngets = 0; - int currsorted = SHM->currsorted, - number = SHM->UTMPnumber; + userinfo_t *uentp; + int i, ngets = 0; + int currsorted = SHM->currsorted, number = SHM->UTMPnumber; friends = friends + base; - for( i = 0 ; i < number && ngets < MAX_FRIEND - base ; ++i ){ + for (i = 0; i < number && ngets < MAX_FRIEND - base; ++i) { uentp = SHM->sorted[currsorted][0][i]; - if( uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && + if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && currutmp != uentp && isvisible(currutmp, uentp) && - (base || !(friend_stat(currutmp, uentp) & (IFH | HFM))) ){ + (base || !(friend_stat(currutmp, uentp) & (IFH | HFM)))) { friends[ngets].ui = uentp; friends[ngets++].friend = IBH; } @@ -1527,120 +1525,116 @@ static int pickup_bfriend(pickup_t *friends, int base) return ngets; } -static void pickup(pickup_t *currpickup, int pickup_way, int *page, - int *nfriend, int *myfriend, int *friendme, int *bfriend) +static void +pickup(pickup_t * currpickup, int pickup_way, int *page, + int *nfriend, int *myfriend, int *friendme, int *bfriend) { /* avoid race condition */ - int currsorted = SHM->currsorted; - int utmpnumber = SHM->UTMPnumber; - int friendtotal= currutmp->friendtotal; + int currsorted = SHM->currsorted; + int utmpnumber = SHM->UTMPnumber; + int friendtotal = currutmp->friendtotal; - userinfo_t **utmp; - int which, sorted_way, size=0, friend; + userinfo_t **utmp; + int which, sorted_way, size = 0, friend; - if( friendtotal == 0 ) + if (friendtotal == 0) *myfriend = *friendme = 1; - if( cuser.uflag & FRIEND_FLAG || - (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND ) ){ - /* [¶Ù! ªB¤Í] mode. - we need to pickup ALL friends (from currutmp friend_online), - sort, and get pickup from right starting position */ + if (cuser.uflag & FRIEND_FLAG || + (pickup_way == 0 && *page * MAXPICKUP < MAX_FRIEND)) { + /* + * [¶Ù! ªB¤Í] mode. we need to pickup ALL friends (from currutmp + * friend_online), sort, and get pickup from right starting position + */ pickup_t friends[MAX_FRIEND]; - + *nfriend = pickup_myfriend(friends, myfriend, friendme); - if( pickup_way == 0 && currutmp->brc_id != 0 ) - *bfriend = pickup_bfriend(friends,*nfriend); - else - *bfriend=0; - *nfriend += *bfriend; - which = *page * MAXPICKUP; - if( *nfriend > which ){ // Ptt: ¥u¦³¦bn¨q¥X¤~¦³¥²n sort - qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); + if (pickup_way == 0 && currutmp->brc_id != 0) + *bfriend = pickup_bfriend(friends, *nfriend); + else + *bfriend = 0; + *nfriend += *bfriend; + which = *page * MAXPICKUP; + if (*nfriend > which) { + //Ptt: ¥u ¦ ³¦b n ¨ q ¥ X ¤ ~¦³¥²n sort + qsort(friends, *nfriend, sizeof(pickup_t), sort_cmpfriend); size = *nfriend - which; - if( size > MAXPICKUP ) + if (size > MAXPICKUP) size = MAXPICKUP; - memcpy(currpickup, friends + which, sizeof(pickup_t) * size); + memcpy(currpickup, friends + which, sizeof(pickup_t) * size); } - } - else - *nfriend=0; + } else + *nfriend = 0; - if( !(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP ){ + if (!(cuser.uflag & FRIEND_FLAG) && size < MAXPICKUP) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); utmp = SHM->sorted[currsorted][sorted_way]; - which = *page * MAXPICKUP-*nfriend; - if( which < 0 ) + which = *page * MAXPICKUP - *nfriend; + if (which < 0) which = 0; - for( ; which < utmpnumber && size < MAXPICKUP ; which++ ){ + for (; which < utmpnumber && size < MAXPICKUP; which++) { friend = friend_stat(currutmp, utmp[which]); - if( ( pickup_way || - (currutmp != utmp[which] && !(friend & ST_FRIEND))) && - isvisible_stat(currutmp, utmp[which], 0)){ + if ((pickup_way || + (currutmp != utmp[which] && !(friend & ST_FRIEND))) && + isvisible_stat(currutmp, utmp[which], 0)) { currpickup[size].ui = utmp[which]; currpickup[size++].friend = friend; } } } /* - for( which = (which >= 0 ? which : 0) ; - got < MAXPICKUP && which < utmpnumber ; - ++got, ++which ){ - - for( ; which < utmpnumber ; ++which ) - if( currutmp != utmp[which] && - isvisible_stat(currutmp, utmp[which], 0) ) - break; - if( which == utmpnumber ) - break; - currpickup[got].ui = utmp[which]; - currpickup[got].friend = 0; - } - */ - - for( ; size < MAXPICKUP ; ++size ) + * for( which = (which >= 0 ? which : 0) ; got < MAXPICKUP && which + * < utmpnumber ; ++got, ++which ){ + * + * for( ; which < utmpnumber ; ++which ) if( currutmp != utmp[which] && + * isvisible_stat(currutmp, utmp[which], 0) ) break; if( which == + * utmpnumber ) break; currpickup[got].ui = utmp[which]; + * currpickup[got].friend = 0; } + */ + + for (; size < MAXPICKUP; ++size) currpickup[size].ui = 0; } -static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, - int page, int show_mode, int show_uid, int show_board, - int show_pid, int real_name, - int myfriend, int friendme, int bfriend) +static void +draw_pickup(int drawall, pickup_t * pickup, int pickup_way, + int page, int show_mode, int show_uid, int show_board, + int show_pid, int real_name, + int myfriend, int friendme, int bfriend) { - char *msg_pickup_way[PICKUP_WAYS] = { + char *msg_pickup_way[PICKUP_WAYS] = { "¶Ù! ªB¤Í", "ºô¤Í¥N¸¹", "ºô¤Í°ÊºA", "µo§b®É¶¡", "¨Ó¦Û¦ó¤è", "¤¤l´Ñ " }; - char *MODE_STRING[MAX_SHOW_MODE] = {"¬G¶m", "¦n¤Í´yz", "¤¤l´Ñ¾ÔÁZ"}; - char pagerchar[5] = "* -Wf"; + char *MODE_STRING[MAX_SHOW_MODE] = {"¬G¶m", "¦n¤Í´yz", "¤¤l´Ñ¾ÔÁZ"}; + char pagerchar[5] = "* -Wf"; - userinfo_t *uentp; - int i, ch, state, friend; - char mind[5]; + userinfo_t *uentp; + int i, ch, state, friend; + char mind[5]; #ifdef SHOW_IDLE_TIME - char idlestr[32]; - int idletime; + char idlestr[32]; + int idletime; #endif - if( drawall ){ + if (drawall) { showtitle((cuser.uflag & FRIEND_FLAG) ? "¦n¤Í¦Cªí" : "¥ð¶¢²á¤Ñ", BBSName); prints("\n" "\033[7m %s P%c¥N¸¹ %-17s%-17s%-13s%-10s\033[m\n", - show_uid ? "UID" : "No.", + show_uid ? "UID" : "No.", (HAS_PERM(PERM_SEECLOAK) || HAS_PERM(PERM_SYSOP)) ? 'C' : ' ', real_name ? "©m¦W" : "¼ÊºÙ", MODE_STRING[show_mode], show_board ? "Board" : "°ÊºA", show_pid ? " PID" : "³Æµù µo§b" - ); + ); move(b_lines, 0); outs("\033[31;47m(TAB/f)\033[30m±Æ§Ç/¦n¤Í \033[31m(t)\033[30m²á¤Ñ " "\033[31m(a/d/o)\033[30m¥æ¤Í \033[31m(q)\033[30m¬d¸ß " "\033[31m(w)\033[30m¤ô²y \033[31m(m)\033[30m±H«H \033[31m(h)" "\033[30m½u¤W»²§U \033[m"); } - move(1, 0); prints(" ±Æ§Ç¡G[%s] ¤W¯¸¤H¼Æ¡G%-4d\033[1;32m§ÚªºªB¤Í¡G%-3d" "\033[33m»P§Ú¬°¤Í¡G%-3d\033[36mªO¤Í¡G%-4d\033[31mÃa¤H¡G" @@ -1648,47 +1642,46 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, msg_pickup_way[pickup_way], SHM->UTMPnumber, myfriend, friendme, currutmp->brc_id ? (bfriend + 1) : 0, 0); - for( i = 0, ch = page * 20 + 1 ; i < MAXPICKUP ; ++i, ++ch ){ - move(i + 3, 0); prints("a"); + for (i = 0, ch = page * 20 + 1; i < MAXPICKUP; ++i, ++ch) { + move(i + 3, 0); + prints("a"); move(i + 3, 0); uentp = pickup[i].ui; friend = pickup[i].friend; - if( uentp == NULL ){ + if (uentp == NULL) { prints("\n"); continue; } - - if( !uentp->pid ){ + if (!uentp->pid) { prints("%5d < Â÷¯¸¤¤..>\n", ch); continue; } - - if( PERM_HIDE(uentp) ) + if (PERM_HIDE(uentp)) state = 9; - else if( currutmp == uentp ) + else if (currutmp == uentp) state = 10; - else if( friend & IRH && !(friend & IFH) ) + else if (friend & IRH && !(friend & IFH)) state = 8; else state = (friend & ST_FRIEND) >> 2; #ifdef SHOW_IDLE_TIME idletime = (now - uentp->lastact); - if( idletime > 86400 ) - strcpy(idlestr, " -----"); - else if( idletime >= 3600 ) + if (idletime > 86400) + strcpy(idlestr, " -----"); + else if (idletime >= 3600) sprintf(idlestr, "%3dh%02d", idletime / 3600, (idletime / 60) % 60); - else if( idletime > 0 ) + else if (idletime > 0) sprintf(idlestr, "%3d'%02d", idletime / 60, idletime % 60); else - strcpy(idlestr, " "); + strcpy(idlestr, " "); #endif - if( (uentp->userlevel & PERM_VIOLATELAW) ) + if ((uentp->userlevel & PERM_VIOLATELAW)) memcpy(mind, "³q½r", 4); - else if( uentp->birth ) + else if (uentp->birth) memcpy(mind, "¹Ø¬P", 4); else memcpy(mind, uentp->mind, 4); @@ -1696,58 +1689,59 @@ static void draw_pickup(int drawall, pickup_t *pickup, int pickup_way, prints("%5d %c%c%s%-13s%-17.16s\033[m%-17.16s%-13.13s" "\33[33m%-4.4s\33[m%s\n", - /* list number or uid */ + /* list number or uid */ #ifdef SHOWUID show_uid ? uentp->uid : #endif ch, - /* super friend or pager */ - (friend & HRM) ? 'X' : pagerchar[uentp->pager % 5], + /* super friend or pager */ + (friend & HRM) ? 'X' : pagerchar[uentp->pager % 5], - /* visibility */ + /* visibility */ (uentp->invisible ? ')' : ' '), - /* color of userid, userid */ + /* color of userid, userid */ fcolor[state], uentp->userid, - /* nickname or realname */ + /* nickname or realname */ #ifdef REALINFO real_name ? uentp->realname : #endif uentp->username, - /* from */ + /* from */ descript(show_mode, uentp, - uentp->pager & !(friend&HRM)), + uentp->pager & !(friend & HRM)), - /* board or mode */ + /* board or mode */ #ifdef SHOWBOARD show_board ? (uentp->brc_id == 0 ? "" : bcache[uentp->brc_id - 1].brdname) : #endif - /* %-13.13s */ + /* %-13.13s */ modestring(uentp, 0), - - /* memo */ + + /* memo */ mind, - /* idle */ + /* idle */ #ifdef SHOW_IDLE_TIME idlestr #else "" #endif - ); + ); refresh(); } } -int call_in(userinfo_t *uentp, int fri_stat) +int +call_in(userinfo_t * uentp, int fri_stat) { - if( iswritable_stat(uentp, fri_stat) ){ - char genbuf[60]; + if (iswritable_stat(uentp, fri_stat)) { + char genbuf[60]; sprintf(genbuf, "Call-In %s ¡G", uentp->userid); my_write(uentp->pid, genbuf, uentp->userid, 0, NULL); return 1; @@ -1755,62 +1749,64 @@ int call_in(userinfo_t *uentp, int fri_stat) return 0; } -static void userlist(void) +static void +userlist(void) { - /* ¨Ï¥ÎªÌ¦W³æ: - userlist() : main loop - draw_pickup() : show out screen - pickup() : generate THIS PAGE pickup list - pickup_maxpages : return max pages number of all list - pickup_myfriend : pickup friend (from friend_online) and sort - */ + /* + * ¨Ï¥ÎªÌ¦W³æ: userlist() : main loop draw_pickup() : show out + * screen pickup() : generate THIS PAGE pickup list + * pickup_maxpages : return max pages number of all list pickup_myfriend + * : pickup friend (from friend_online) and sort + */ pickup_t currpickup[MAXPICKUP]; - userinfo_t *uentp; - static int show_mode = 0; - static int show_uid = 0; - static int show_board = 0; - static int show_pid = 0; - static int real_name = 0; - char genbuf[256]; - int page, offset, pickup_way, ch, leave, redraw, redrawall, fri_stat; - int nfriend, myfriend, friendme, bfriend, i; - time_t lastupdate; + userinfo_t *uentp; + static int show_mode = 0; + static int show_uid = 0; + static int show_board = 0; + static int show_pid = 0; + static int real_name = 0; + char genbuf[256]; + int page, offset, pickup_way, ch, leave, redraw, redrawall, + fri_stat; + int nfriend, myfriend, friendme, bfriend, i; + time_t lastupdate; page = offset = 0; pickup_way = 0; leave = 0; redrawall = 1; - /* redraw : ·|Â÷¶}Áä½L³B²z loop , «·s pickup, draw_pickup - (¥u«µe¤¤¶¡¨Ï¥ÎªÌ³¡¥÷) - redrawall : ·|«µe©Ò¦³ªº³¡¥÷ (¤W±ªº¼ÐÃD¦C, ¤U±ªº»¡©ú¦Cµ¥µ¥) - leave : ªð¦^¤W¤@¿ï³æ - */ - while( !leave ){ + /* + * redraw : ·|Â÷¶}Áä½L³B²z loop , «·s pickup, draw_pickup + * (¥u«µe¤¤¶¡¨Ï¥ÎªÌ³¡¥÷) redrawall : ·|«µe©Ò¦³ªº³¡¥÷ (¤W±ªº¼ÐÃD¦C, + * ¤U±ªº»¡©ú¦Cµ¥µ¥) leave : ªð¦^¤W¤@¿ï³æ + */ + while (!leave) { pickup(currpickup, pickup_way, &page, &nfriend, &myfriend, &friendme, &bfriend); draw_pickup(redrawall, currpickup, pickup_way, page, show_mode, show_uid, show_board, show_pid, real_name, myfriend, friendme, bfriend); - /* ¦pªG¦]¬°´«¶ªº®ÉÔ, ³o¤@¶¦³ªº¤H¼Æ¤ñ¸û¤Ö, - (³q±`³£¬O³Ì«á¤@¶¤H¼Æ¤£º¡ªº®ÉÔ) - ¨ºn«·spºâ offset ¥H§K«ü¨ì¨S¦³¤Hªº¦a¤è */ - if( offset == -1 || currpickup[offset].ui == NULL ){ - for( offset = (offset == -1 ? MAXPICKUP - 1 : offset ) ; - offset >= 0 ; --offset ) - if( currpickup[offset].ui != NULL ) + /* + * ¦pªG¦]¬°´«¶ªº®ÉÔ, ³o¤@¶¦³ªº¤H¼Æ¤ñ¸û¤Ö, + * (³q±`³£¬O³Ì«á¤@¶¤H¼Æ¤£º¡ªº®ÉÔ) ¨ºn«·spºâ offset + * ¥H§K«ü¨ì¨S¦³¤Hªº¦a¤è + */ + if (offset == -1 || currpickup[offset].ui == NULL) { + for (offset = (offset == -1 ? MAXPICKUP - 1 : offset); + offset >= 0; --offset) + if (currpickup[offset].ui != NULL) break; - if( offset == -1 ){ - if( --page < 0 ) + if (offset == -1) { + if (--page < 0) page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; continue; } } - redraw = redrawall = 0; lastupdate = now; - while( !redraw ){ + while (!redraw) { ch = cursor_key(offset + 3, 0); uentp = currpickup[offset].ui; fri_stat = currpickup[offset].friend; @@ -1818,7 +1814,7 @@ static void userlist(void) if (ch == KEY_RIGHT || ch == '\n' || ch == '\r') ch = 't'; - switch (ch){ + switch (ch) { case KEY_LEFT: case 'e': case 'E': @@ -1834,10 +1830,10 @@ static void userlist(void) case KEY_DOWN: case 'n': case 'j': - if( ++offset == MAXPICKUP || currpickup[offset].ui == NULL ){ + if (++offset == MAXPICKUP || currpickup[offset].ui == NULL) { redraw = 1; - if( ++page >= pickup_maxpages(pickup_way, - nfriend) ) + if (++page >= pickup_maxpages(pickup_way, + nfriend)) offset = page = 0; else offset = 0; @@ -1851,15 +1847,15 @@ static void userlist(void) break; case 'H': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { currutmp->userlevel ^= PERM_DENYPOST; redrawall = redraw = 1; } break; case 'D': - if (HAS_PERM(PERM_SYSOP)){ - char buf[100]; + if (HAS_PERM(PERM_SYSOP)) { + char buf[100]; sprintf(buf, "¥N¸¹ [%s]¡G", currutmp->userid); if (!getdata(1, 0, buf, currutmp->userid, sizeof(buf), DOECHO)) @@ -1869,8 +1865,8 @@ static void userlist(void) break; case 'F': - if (HAS_PERM(PERM_SYSOP)){ - char buf[100]; + if (HAS_PERM(PERM_SYSOP)) { + char buf[100]; sprintf(buf, "¬G¶m [%s]¡G", currutmp->from); if (!getdata(1, 0, buf, currutmp->from, @@ -1884,34 +1880,34 @@ static void userlist(void) #if !HAVE_FREECLOAK if (HAS_PERM(PERM_CLOAK)) #endif - { - currutmp->invisible ^= 1; - redrawall = redraw = 1; - } + { + currutmp->invisible ^= 1; + redrawall = redraw = 1; + } break; case ' ': case KEY_PGDN: case Ctrl('F'):{ - int newpage; - if( (newpage = page + 1) >= pickup_maxpages(pickup_way, - nfriend) ) - newpage = offset = 0; - if( newpage != page ){ - page = newpage; - redraw = 1; - } else if( now >= lastupdate + 2 ) - redrawall = redraw = 1; - } + int newpage; + if ((newpage = page + 1) >= pickup_maxpages(pickup_way, + nfriend)) + newpage = offset = 0; + if (newpage != page) { + page = newpage; + redraw = 1; + } else if (now >= lastupdate + 2) + redrawall = redraw = 1; + } break; case KEY_UP: case 'k': - if( --offset == -1 ){ + if (--offset == -1) { offset = MAXPICKUP - 1; - if( --page == -1 ) + if (--page == -1) page = pickup_maxpages(pickup_way, nfriend) - - 1; + - 1; redraw = 1; } break; @@ -1919,7 +1915,7 @@ static void userlist(void) case KEY_PGUP: case Ctrl('B'): case 'P': - if( --page == -1 ) + if (--page == -1) page = pickup_maxpages(pickup_way, nfriend) - 1; offset = 0; redraw = 1; @@ -1934,49 +1930,46 @@ static void userlist(void) case '/': /* - getdata_buf(b_lines-1,0,"½Ð¿é¤J¼ÊºÙÃöÁä¦r:", - keyword, sizeof(keyword), DOECHO); - state = US_PICKUP; - */ - break; + * getdata_buf(b_lines-1,0,"½Ð¿é¤J¼ÊºÙÃöÁä¦r:", keyword, + * sizeof(keyword), DOECHO); state = US_PICKUP; + */ + break; case 's': - if( !(cuser.uflag & FRIEND_FLAG) ){ - int si; /* utmpshm->sorted[X][0][si] */ - int fi; /* allpickuplist[fi] */ - char swid[IDLEN + 1]; + if (!(cuser.uflag & FRIEND_FLAG)) { + int si; /* utmpshm->sorted[X][0][si] */ + int fi; /* allpickuplist[fi] */ + char swid[IDLEN + 1]; move(1, 0); si = generalnamecomplete(msg_uid, swid, sizeof(swid), SHM->UTMPnumber, completeutmp_compar, completeutmp_permission, completeutmp_getname); - if( si >= 0 ){ + if (si >= 0) { pickup_t friends[MAX_FRIEND + 1]; - int nGots, i; + int nGots, i; fi = SHM->sorted[SHM->currsorted][0][si] - - &SHM->uinfo[0]; + &SHM->uinfo[0]; - nGots= pickup_myfriend(friends, &myfriend, &friendme); - for( i = 0 ; i < nGots ; ++i ) - if( friends[i].uoffset == fi ) + nGots = pickup_myfriend(friends, &myfriend, &friendme); + for (i = 0; i < nGots; ++i) + if (friends[i].uoffset == fi) break; - if( i != nGots ){ + if (i != nGots) { page = i / 20; offset = i % 20; - } - else{ + } else { page = (si + nGots) / 20; offset = (si + nGots) % 20; - } + } } redrawall = redraw = 1; } /* - if ((i = search_pickup(num, actor, pklist)) >= 0) - num = i; - state = US_ACTION; - */ + * if ((i = search_pickup(num, actor, pklist)) >= 0) num = i; + * state = US_ACTION; + */ break; case '1': @@ -1989,14 +1982,15 @@ static void userlist(void) case '8': case '9': { /* Thor: ¥i¥H¥´¼Æ¦r¸õ¨ì¸Ó¤H */ - int tmp; - if( (tmp = search_num(ch, SHM->UTMPnumber)) >= 0 ){ - if( tmp / 20 == page ){ - /* in2:¥Øªº¦b¥Ø«e³o¤@¶, ª½±µ - §ó·s offset , ¤£¥Î«µeµe± */ + int tmp; + if ((tmp = search_num(ch, SHM->UTMPnumber)) >= 0) { + if (tmp / 20 == page) { + /* + * in2:¥Øªº¦b¥Ø«e³o¤@¶, ª½±µ §ó·s offset , + * ¤£¥Î«µeµe± + */ offset = tmp % 20; - } - else{ + } else { page = tmp / 20; offset = tmp % 20; } @@ -2004,10 +1998,10 @@ static void userlist(void) } } break; - + #ifdef REALINFO case 'R': /* Åã¥Ü¯u¹ê©m¦W */ - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { real_name ^= 1; redrawall = redraw = 1; } @@ -2015,7 +2009,7 @@ static void userlist(void) #endif #ifdef SHOWUID case 'U': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_uid ^= 1; redrawall = redraw = 1; } @@ -2023,7 +2017,7 @@ static void userlist(void) #endif #ifdef SHOWBOARD case 'Y': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_board ^= 1; redrawall = redraw = 1; } @@ -2031,7 +2025,7 @@ static void userlist(void) #endif #ifdef SHOWPID case '#': - if (HAS_PERM(PERM_SYSOP)){ + if (HAS_PERM(PERM_SYSOP)) { show_pid ^= 1; redrawall = redraw = 1; } @@ -2039,41 +2033,40 @@ static void userlist(void) #endif case 'b': /* broadcast */ - if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)){ - char ans[4]; - + if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) { + char ans[4]; + if (!getdata(0, 0, "¼s¼½°T®§:", genbuf, 60, DOECHO)) break; if (getdata(0, 0, "½T©w¼s¼½? [Y]", ans, sizeof(ans), LCECHO) && *ans == 'n') break; - if( !(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP) ){ - for( i = 0 ; i < SHM->UTMPnumber ; ++i ){ + if (!(cuser.uflag & FRIEND_FLAG) && HAS_PERM(PERM_SYSOP)) { + for (i = 0; i < SHM->UTMPnumber; ++i) { uentp = SHM->sorted[SHM->currsorted][0][i]; - if( uentp->pid && kill(uentp->pid, 0) != -1 ) + if (uentp->pid && kill(uentp->pid, 0) != -1) my_write(uentp->pid, genbuf, - uentp->userid, 1, NULL); - if( i % 100 == 0 ) + uentp->userid, 1, NULL); + if (i % 100 == 0) sleep(1); } - } - else{ - userinfo_t *uentp; - int where, frstate; - for( i = 0 ; currutmp->friend_online[i] && - i < MAX_FRIEND ; ++i ){ + } else { + userinfo_t *uentp; + int where, frstate; + for (i = 0; currutmp->friend_online[i] && + i < MAX_FRIEND; ++i) { where = currutmp->friend_online[i] & 0xFFFFFF; - if( 0 <= where && where < MAX_ACTIVE && - (uentp = &SHM->uinfo[where]) && + if (0 <= where && where < MAX_ACTIVE && + (uentp = &SHM->uinfo[where]) && uentp->pid && isvisible_stat(currutmp, uentp, frstate = - currutmp->friend_online[i]>>24) + currutmp->friend_online[i] >> 24) && kill(uentp->pid, 0) != -1 && uentp->pager != 3 && (uentp->pager != 4 || frstate & HFM) && - !(frstate & IRH) ){ + !(frstate & IRH)) { my_write(uentp->pid, genbuf, uentp->userid, 1, NULL); } @@ -2088,16 +2081,16 @@ static void userlist(void) redrawall = redraw = 1; break; - case 'u': /* ½u¤Wקï¸ê®Æ */ - if( HAS_PERM(PERM_ACCOUNTS) ){ - int id; - userec_t muser; + case 'u': /* ½u¤Wקï¸ê®Æ */ + if (HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; strcpy(currauthor, uentp->userid); stand_title("¨Ï¥ÎªÌ³]©w"); move(1, 0); - if( (id = getuser(uentp->userid)) > 0 ){ + if ((id = getuser(uentp->userid)) > 0) { memcpy(&muser, &xuser, sizeof(muser)); - user_display(&muser, 1); + user_display(&muser, 1); uinfo_query(&muser, 1, id); } redrawall = redraw = 1; @@ -2105,26 +2098,26 @@ static void userlist(void) break; case 'i':{ - char mindbuf[5]; - getdata(b_lines - 1, 0, "²{¦bªº¤ß±¡? ", - mindbuf, sizeof(mindbuf), LCECHO); - if( strcmp(mindbuf, "³q½r") == 0 ) - vmsg("¤£¥i¥H§â¦Û¤v³]³q½r°Õ!"); - else if( strcmp(mindbuf, "¹Ø¬P") == 0 ) - vmsg("§A¤£¬O¤µ¤Ñ¥Í¤éÕÙ!"); - else - memcpy(currutmp->mind, mindbuf, 4); - } + char mindbuf[5]; + getdata(b_lines - 1, 0, "²{¦bªº¤ß±¡? ", + mindbuf, sizeof(mindbuf), LCECHO); + if (strcmp(mindbuf, "³q½r") == 0) + vmsg("¤£¥i¥H§â¦Û¤v³]³q½r°Õ!"); + else if (strcmp(mindbuf, "¹Ø¬P") == 0) + vmsg("§A¤£¬O¤µ¤Ñ¥Í¤éÕÙ!"); + else + memcpy(currutmp->mind, mindbuf, 4); + } redrawall = redraw = 1; break; - + case Ctrl('S'): break; case 't': - if( HAS_PERM(PERM_LOGINOK) ){ - if( uentp->pid != currpid && - strcmp(uentp->userid, cuser.userid) != 0 ){ + if (HAS_PERM(PERM_LOGINOK)) { + if (uentp->pid != currpid && + strcmp(uentp->userid, cuser.userid) != 0) { move(1, 0); clrtobot(); move(3, 0); @@ -2133,19 +2126,18 @@ static void userlist(void) } } break; - case 'K': - if(HAS_PERM(PERM_ACCOUNTS)) - { - my_kick(uentp); - redrawall = redraw = 1; - } - break; + case 'K': + if (HAS_PERM(PERM_ACCOUNTS)) { + my_kick(uentp); + redrawall = redraw = 1; + } + break; case 'w': - if(call_in(uentp,fri_stat)) - redrawall = redraw = 1; + if (call_in(uentp, fri_stat)) + redrawall = redraw = 1; break; case 'a': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { friend_add(uentp->userid, FRIEND_OVERRIDE); friend_load(); redrawall = redraw = 1; @@ -2153,7 +2145,7 @@ static void userlist(void) break; case 'd': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { friend_delete(uentp->userid, FRIEND_OVERRIDE); friend_load(); redrawall = redraw = 1; @@ -2161,51 +2153,50 @@ static void userlist(void) break; case 'o': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { t_override(); redrawall = redraw = 1; } break; case 'f': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { cuser.uflag ^= FRIEND_FLAG; redrawall = redraw = 1; } break; - + case 'g': - if( HAS_PERM(PERM_LOGINOK) && - strcmp(uentp->userid, cuser.userid) != 0 ){ + if (HAS_PERM(PERM_LOGINOK) && + strcmp(uentp->userid, cuser.userid) != 0) { move(b_lines - 2, 0); sprintf(genbuf, "nµ¹ %s ¦h¤Ö¿ú©O? ", uentp->userid); - outs(genbuf); - if( getdata(b_lines - 1, 0, "[»È¦æÂà±b]: ", - genbuf, 7, LCECHO) ){ - clrtoeol(); - if( (ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch) ) - break; + outs(genbuf); + if (getdata(b_lines - 1, 0, "[»È¦æÂà±b]: ", + genbuf, 7, LCECHO)) { + clrtoeol(); + if ((ch == atoi(genbuf)) <= 0 || ch <= give_tax(ch)) + break; reload_money(); - - if( ch > cuser.money ) - outs("\033[41m ²{ª÷¤£¨¬~~\033[m"); - else{ - deumoney(uentp->uid, ch - give_tax(ch)); - sprintf(genbuf, "\033[44m ¶â..ÁٳѤU %d ¿ú.." - "\033[m", demoney(-ch)); - outs(genbuf); - sprintf(genbuf, "%s\tµ¹%s\t%d\t%s", cuser.userid, - uentp->userid, ch, - ctime(&currutmp->lastact)); - log_file(FN_MONEY, genbuf); - mail_redenvelop(cuser.userid, uentp->userid, + + if (ch > cuser.money) + outs("\033[41m ²{ª÷¤£¨¬~~\033[m"); + else { + deumoney(uentp->uid, ch - give_tax(ch)); + sprintf(genbuf, "\033[44m ¶â..ÁٳѤU %d ¿ú.." + "\033[m", demoney(-ch)); + outs(genbuf); + sprintf(genbuf, "%s\tµ¹%s\t%d\t%s", cuser.userid, + uentp->userid, ch, + ctime(&currutmp->lastact)); + log_file(FN_MONEY, genbuf); + mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); - } - } - else{ - clrtoeol(); - outs("\033[41m ¥æ©ö¨ú®ø! \033[m"); - } + } + } else { + clrtoeol(); + outs("\033[41m ¥æ©ö¨ú®ø! \033[m"); + } redrawall = redraw = 1; } break; @@ -2218,21 +2209,21 @@ static void userlist(void) break; case 'q': - strcpy(currauthor, uentp->userid); - my_query(uentp->userid); + strcpy(currauthor, uentp->userid); + my_query(uentp->userid); setutmpmode(LUSERS); redrawall = redraw = 1; break; case 'c': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { chicken_query(uentp->userid); redrawall = redraw = 1; } break; case 'l': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { t_display(); redrawall = redraw = 1; } @@ -2244,50 +2235,51 @@ static void userlist(void) break; case 'p': - if( HAS_PERM(PERM_BASIC) ){ + if (HAS_PERM(PERM_BASIC)) { t_pager(); redrawall = redraw = 1; } break; case 'W': - if( HAS_PERM(PERM_LOGINOK) ){ - int tmp; - char *wm[3] = {"¤@¯ë", "¶i¶¥", "¥¼¨Ó"}; - tmp = cuser.uflag2 & WATER_MASK; - cuser.uflag2 -= tmp; - tmp = (tmp + 1) % 3; - cuser.uflag2 |= tmp; + if (HAS_PERM(PERM_LOGINOK)) { + int tmp; + char *wm[3] = {"¤@¯ë", "¶i¶¥", "¥¼¨Ó"}; + tmp = cuser.uflag2 & WATER_MASK; + cuser.uflag2 -= tmp; + tmp = (tmp + 1) % 3; + cuser.uflag2 |= tmp; move(4, 0); prints("¨t²Î´£¨Ñ ¤@¯ë ¶i¶¥ ¥¼¨Ó ¤TºØ¼Ò¦¡\n" "¦b¤Á´««á½Ð¥¿±`¤U½u¦A«·sµn¤J, ¥H½T«Oµ²ºc¥¿½T\n" "¥Ø«e¤Á´«¨ì %s ¤ô²y¼Ò¦¡\n", wm[tmp]); - refresh(); - sleep(2); + refresh(); + sleep(2); redrawall = redraw = 1; } break; case 'r': - if( HAS_PERM(PERM_LOGINOK) ){ + if (HAS_PERM(PERM_LOGINOK)) { m_read(); redrawall = redraw = 1; } break; default: - if( now >= lastupdate + 2 ) + if (now >= lastupdate + 2) redraw = 1; } } } } -int t_users(void) +int +t_users(void) { - int destuid0 = currutmp->destuid; - int mode0 = currutmp->mode; - int stat0 = currstat; + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; setutmpmode(LUSERS); userlist(); @@ -2297,29 +2289,30 @@ int t_users(void) return 0; } -int t_pager(void) +int +t_pager(void) { currutmp->pager = (currutmp->pager + 1) % 5; return 0; } -int t_idle(void) +int +t_idle(void) { - int destuid0 = currutmp->destuid; - int mode0 = currutmp->mode; - int stat0 = currstat; - char genbuf[20]; - char buf[80], passbuf[PASSLEN]; + int destuid0 = currutmp->destuid; + int mode0 = currutmp->mode; + int stat0 = currstat; + char genbuf[20]; + char buf[80], passbuf[PASSLEN]; setutmpmode(IDLE); getdata(b_lines - 1, 0, "²z¥Ñ¡G[0]µo§b (1)±µ¹q¸Ü (2)³V¹ (3)¥´½OºÎ " "(4)¸Ë¦º (5)ù¤¦ (6)¨ä¥L (Q)¨S¨Æ¡H", genbuf, 3, DOECHO); - if (genbuf[0] == 'q' || genbuf[0] == 'Q'){ + if (genbuf[0] == 'q' || genbuf[0] == 'Q') { currutmp->mode = mode0; currstat = stat0; return 0; - } - else if (genbuf[0] >= '1' && genbuf[0] <= '6') + } else if (genbuf[0] >= '1' && genbuf[0] <= '6') currutmp->destuid = genbuf[0] - '0'; else currutmp->destuid = 0; @@ -2329,7 +2322,7 @@ int t_idle(void) !getdata(b_lines - 1, 0, "µo§bªº²z¥Ñ¡G", currutmp->chatid, sizeof(currutmp->chatid), DOECHO)) currutmp->destuid = 0; - do{ + do { move(b_lines - 2, 0); clrtoeol(); sprintf(buf, "(Âê©w¿Ã¹õ)µo§bì¦]: %s", (currutmp->destuid != 6) ? @@ -2349,9 +2342,10 @@ int t_idle(void) return 0; } -int t_qchicken(void) +int +t_qchicken(void) { - char uident[STRLEN]; + char uident[STRLEN]; stand_title("¬d¸ßÃdª«"); usercomplete(msg_uid, uident); @@ -2360,9 +2354,10 @@ int t_qchicken(void) return 0; } -int t_query(void) +int +t_query(void) { - char uident[STRLEN]; + char uident[STRLEN]; stand_title("¬d¸ßºô¤Í"); usercomplete(msg_uid, uident); @@ -2371,17 +2366,17 @@ int t_query(void) return 0; } -int t_talk() { - char uident[16]; - int tuid, unum, ucount; - userinfo_t *uentp; - char genbuf[4]; -/* - if (count_ulist() <= 1){ - outs("¥Ø«e½u¤W¥u¦³±z¤@¤H¡A§ÖÁܽЪB¤Í¨Ó¥úÁ{¡i" BBSNAME "¡j§a¡I"); - return XEASY; - } -*/ +int +t_talk() +{ + char uident[16]; + int tuid, unum, ucount; + userinfo_t *uentp; + char genbuf[4]; + /* + * if (count_ulist() <= 1){ outs("¥Ø«e½u¤W¥u¦³±z¤@¤H¡A§ÖÁܽЪB¤Í¨Ó¥úÁ{¡i" + * BBSNAME "¡j§a¡I"); return XEASY; } + */ stand_title("¥´¶}¸Ü§X¤l"); generalnamecomplete(msg_uid, uident, sizeof(uident), SHM->UTMPnumber, @@ -2392,15 +2387,14 @@ int t_talk() { return 0; move(3, 0); - if (!(tuid = searchuser(uident)) || tuid == usernum){ + if (!(tuid = searchuser(uident)) || tuid == usernum) { outs(err_uid); pressanykey(); return 0; } - -/* multi-login check */ + /* multi-login check */ unum = 1; - while ((ucount = count_logins(tuid, 0)) > 1){ + while ((ucount = count_logins(tuid, 0)) > 1) { outs("(0) ¤£·Q talk ¤F...\n"); count_logins(tuid, 1); getdata(1, 33, "½Ð¿ï¾Ü¤@Ó²á¤Ñ¹ï¶H [0]¡G", genbuf, 4, DOECHO); @@ -2421,13 +2415,14 @@ int t_talk() { /* ¦³¤H¨Ó¦êªù¤l¤F¡A¦^À³©I¥s¾¹ */ static userinfo_t *uip; -void talkreply(void) +void +talkreply(void) { struct hostent *h; - char buf[4]; + char buf[4]; struct sockaddr_in sin; - char genbuf[200]; - int a, sig = currutmp->sig; + char genbuf[200]; + int a, sig = currutmp->sig; talkrequest = NA; uip = &SHM->uinfo[currutmp->destuip]; @@ -2463,7 +2458,7 @@ void talkreply(void) page_requestor, sig_des[sig]); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); - if (uip->mode != PAGE){ + if (uip->mode != PAGE) { sprintf(genbuf, "%s¤w°±¤î©I¥s¡A«öEnterÄ~Äò...", page_requestor); getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); return; @@ -2471,7 +2466,7 @@ void talkreply(void) currutmp->msgcount = 0; strcpy(save_page_requestor, page_requestor); memset(page_requestor, 0, sizeof(page_requestor)); - if (!(h = gethostbyname("localhost"))){ + if (!(h = gethostbyname("localhost"))) { perror("gethostbyname"); return; } @@ -2480,21 +2475,21 @@ void talkreply(void) memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = uip->sockaddr; a = socket(sin.sin_family, SOCK_STREAM, 0); - if ((connect(a, (struct sockaddr *) &sin, sizeof(sin)))){ + if ((connect(a, (struct sockaddr *) & sin, sizeof(sin)))) { perror("connect err"); return; } if (!buf[0] || !strchr("yabcdef12", buf[0])) buf[0] = 'n'; write(a, buf, 1); - if (buf[0] == 'f' || buf[0] == 'F'){ + if (buf[0] == 'f' || buf[0] == 'F') { if (!getdata(b_lines, 0, "¤£¯àªºì¦]¡G", genbuf, 60, DOECHO)) strcpy(genbuf, "¤£§i¶D§A«¨ !! ^o^"); write(a, genbuf, 60); } uip->destuip = currutmp - &SHM->uinfo[0]; if (buf[0] == 'y') - switch (sig){ + switch (sig) { case SIG_DARK: main_dark(a, uip); break; @@ -2517,75 +2512,33 @@ void talkreply(void) } /* ºô¤Í°ÊºA²ªí */ -/* not used -static int shortulist(userinfo_t * uentp) -{ - static int lineno, fullactive, linecnt; - static int moreactive, page, num; - char uentry[50]; - int state; - - if (!lineno){ - lineno = 3; - page = moreactive ? (page + p_lines * 3) : 0; - linecnt = num = moreactive = 0; - move(1, 70); - prints("Page: %d", page / (p_lines) / 3 + 1); - move(lineno, 0); - } - - if (uentp == NULL){ - int finaltally; - - clrtoeol(); - move(++lineno, 0); - clrtobot(); - finaltally = fullactive; - lineno = fullactive = 0; - return finaltally; - } - - if ((!HAS_PERM(PERM_SYSOP) && - !HAS_PERM(PERM_SEECLOAK) && - uentp->invisible) || - ((friend_stat(currutmp, uentp) & HRM) && - !HAS_PERM(PERM_SYSOP))){ - if (lineno >= b_lines) - return 0; - if (num++ < page) - return 0; - memset(uentry, ' ', 25); - uentry[25] = '\0'; - } - else{ - fullactive++; - if (lineno >= b_lines){ - moreactive = 1; - return 0; - } - if (num++ < page) - return 0; - - state = (currutmp == uentp) ? 10 : - (friend_stat(currutmp,uentp)&ST_FRIEND)>>2; - - if (PERM_HIDE(uentp)) - state = 9; - - sprintf(uentry, "%s%-13s%c%-10s%s ", fcolor[state], - uentp->userid, uentp->invisible ? '#' : ' ', - modestring(uentp, 1), state ? "\033[0m" : ""); - } - if (++linecnt < 3){ - strcat(uentry, "¢x"); - outs(uentry); - } - else{ - outs(uentry); - linecnt = 0; - clrtoeol(); - move(++lineno, 0); - } - return 0; -} -*/ +/* + * not used static int shortulist(userinfo_t * uentp) { static int lineno, + * fullactive, linecnt; static int moreactive, page, num; char uentry[50]; + * int state; + * + * if (!lineno){ lineno = 3; page = moreactive ? (page + p_lines * 3) : 0; + * linecnt = num = moreactive = 0; move(1, 70); prints("Page: %d", page / + * (p_lines) / 3 + 1); move(lineno, 0); } + * + * if (uentp == NULL){ int finaltally; + * + * clrtoeol(); move(++lineno, 0); clrtobot(); finaltally = fullactive; lineno = + * fullactive = 0; return finaltally; } + * + * if ((!HAS_PERM(PERM_SYSOP) && !HAS_PERM(PERM_SEECLOAK) && uentp->invisible) + * || ((friend_stat(currutmp, uentp) & HRM) && !HAS_PERM(PERM_SYSOP))){ if + * (lineno >= b_lines) return 0; if (num++ < page) return 0; memset(uentry, ' + * ', 25); uentry[25] = '\0'; } else{ fullactive++; if (lineno >= b_lines){ + * moreactive = 1; return 0; } if (num++ < page) return 0; + * + * state = (currutmp == uentp) ? 10 : + * (friend_stat(currutmp,uentp)&ST_FRIEND)>>2; + * + * if (PERM_HIDE(uentp)) state = 9; + * + * sprintf(uentry, "%s%-13s%c%-10s%s ", fcolor[state], uentp->userid, + * uentp->invisible ? '#' : ' ', modestring(uentp, 1), state ? "\033[0m" : + * ""); } if (++linecnt < 3){ strcat(uentry, "¢x"); outs(uentry); } else{ + * outs(uentry); linecnt = 0; clrtoeol(); move(++lineno, 0); } return 0; } + */ diff --git a/mbbsd/term.c b/mbbsd/term.c index 4cab3e2c..aa310212 100644 --- a/mbbsd/term.c +++ b/mbbsd/term.c @@ -1,28 +1,31 @@ -/* $Id: term.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: term.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -int tgetent(const char *bp, char *name); -char *tgetstr(const char *id, char **area); -int tgetflag(const char *id); -int tgetnum(const char *id); -int tputs(const char *str, int affcnt, int (*putc)(int)); -char *tparm(const char *str, ...); -char *tgoto(const char *cap, int col, int row); +int tgetent(const char *bp, char *name); +char *tgetstr(const char *id, char **area); +int tgetflag(const char *id); +int tgetnum(const char *id); +int tputs(const char *str, int affcnt, int (*putc) (int)); +char *tparm(const char *str,...); +char *tgoto(const char *cap, int col, int row); static struct termios tty_state, tty_new; /* ----------------------------------------------------- */ /* basic tty control */ /* ----------------------------------------------------- */ -void init_tty() { - if(tcgetattr(1, &tty_state) < 0) { +void +init_tty() +{ + if (tcgetattr(1, &tty_state) < 0) { syslog(LOG_ERR, "tcgetattr(): %m"); return; } memcpy(&tty_new, &tty_state, sizeof(tty_new)); tty_new.c_lflag &= ~(ICANON | ECHO | ISIG); -/* tty_new.c_cc[VTIME] = 0; - tty_new.c_cc[VMIN] = 1; */ + /* + * tty_new.c_cc[VTIME] = 0; tty_new.c_cc[VMIN] = 1; + */ tcsetattr(1, TCSANOW, &tty_new); system("stty raw -echo"); } @@ -35,11 +38,13 @@ void init_tty() { #define TERMCOMSIZE (40) #if 0 -static char *outp; -static int *outlp; +static char *outp; +static int *outlp; -static int outcf(int ch) { - if(*outlp < TERMCOMSIZE) { +static int +outcf(int ch) +{ + if (*outlp < TERMCOMSIZE) { (*outlp)++; *outp++ = ch; } @@ -47,64 +52,77 @@ static int outcf(int ch) { } #endif -static void term_resize(int sig) { - struct winsize newsize; - screenline_t *new_picture; +static void +term_resize(int sig) +{ + struct winsize newsize; + screenline_t *new_picture; signal(SIGWINCH, SIG_IGN); /* Don't bother me! */ ioctl(0, TIOCGWINSZ, &newsize); - if(newsize.ws_row > t_lines) { - new_picture = (screenline_t *)calloc(newsize.ws_row, - sizeof(screenline_t)); - if(new_picture == NULL) { + if (newsize.ws_row > t_lines) { + new_picture = (screenline_t *) calloc(newsize.ws_row, + sizeof(screenline_t)); + if (new_picture == NULL) { syslog(LOG_ERR, "calloc(): %m"); return; } free(big_picture); big_picture = new_picture; } - - t_lines=newsize.ws_row; - b_lines=t_lines-1; - p_lines=t_lines-4; + t_lines = newsize.ws_row; + b_lines = t_lines - 1; + p_lines = t_lines - 4; signal(SIGWINCH, term_resize); } -int term_init() { +int +term_init() +{ signal(SIGWINCH, term_resize); return YEA; } -char term_buf[32]; +char term_buf[32]; + +void +do_move(int destcol, int destline) +{ + char buf[16], *p; -void do_move(int destcol, int destline) { - char buf[16], *p; - sprintf(buf, "\33[%d;%dH", destline + 1, destcol + 1); - for(p = buf; *p; p++) + for (p = buf; *p; p++) ochar(*p); } -void save_cursor() { +void +save_cursor() +{ ochar('\33'); ochar('7'); } -void restore_cursor() { +void +restore_cursor() +{ ochar('\33'); ochar('8'); } -void change_scroll_range(int top, int bottom) { - char buf[16], *p; - +void +change_scroll_range(int top, int bottom) +{ + char buf[16], *p; + sprintf(buf, "\33[%d;%dr", top + 1, bottom + 1); - for(p = buf; *p; p++) + for (p = buf; *p; p++) ochar(*p); } -void scroll_forward() { +void +scroll_forward() +{ ochar('\33'); ochar('D'); } diff --git a/mbbsd/toolkit.c b/mbbsd/toolkit.c index 2955f040..9623c578 100644 --- a/mbbsd/toolkit.c +++ b/mbbsd/toolkit.c @@ -1,9 +1,11 @@ -/* $Id: toolkit.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: toolkit.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -unsigned StringHash(unsigned char *s) { - unsigned int v=0; - while(*s) { +unsigned +StringHash(unsigned char *s) +{ + unsigned int v = 0; + while (*s) { v = (v << 8) | (v >> 24); v ^= toupper(*s++); /* note this is case insensitive */ } diff --git a/mbbsd/topsong.c b/mbbsd/topsong.c index 169feb8d..9d5fd475 100644 --- a/mbbsd/topsong.c +++ b/mbbsd/topsong.c @@ -1,71 +1,79 @@ -/* $Id: topsong.c,v 1.2 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: topsong.c,v 1.3 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define MAX_SONGS 300 #define QCAST int (*)(const void *, const void *) typedef struct songcmp_t { - char name[100]; - char cname[100]; - long int count; -} songcmp_t; + char name[100]; + char cname[100]; + long int count; +} songcmp_t; -static long int totalcount=0; +static long int totalcount = 0; -static int count_cmp(songcmp_t *b, songcmp_t *a) { +static int +count_cmp(songcmp_t * b, songcmp_t * a) +{ return (a->count - b->count); } -int topsong() { - more(FN_TOPSONG,YEA); +int +topsong() +{ + more(FN_TOPSONG, YEA); return 0; } - -static int strip_blank(char *cbuf, char *buf) { - for(; *buf; buf++) - if(*buf != ' ') - *cbuf++ = *buf; + +static int +strip_blank(char *cbuf, char *buf) +{ + for (; *buf; buf++) + if (*buf != ' ') + *cbuf++ = *buf; *cbuf = 0; return 0; } -void sortsong() { - FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); - songcmp_t songs[MAX_SONGS + 1]; - int n; - char buf[256], cbuf[256]; +void +sortsong() +{ + FILE *fo, *fp = fopen(BBSHOME "/" FN_USSONG, "r"); + songcmp_t songs[MAX_SONGS + 1]; + int n; + char buf[256], cbuf[256]; - memset(songs , 0, sizeof(songs)); - if(!fp) return; - if(!(fo = fopen(FN_TOPSONG,"w"))) { + memset(songs, 0, sizeof(songs)); + if (!fp) + return; + if (!(fo = fopen(FN_TOPSONG, "w"))) { fclose(fp); return; } - totalcount = 0; - while(fgets(buf, 200, fp)) { + while (fgets(buf, 200, fp)) { strtok(buf, "\n\r"); strip_blank(cbuf, buf); - if(!cbuf[0] || !isprint2(cbuf[0])) + if (!cbuf[0] || !isprint2(cbuf[0])) continue; - - for(n = 0; n < MAX_SONGS && songs[n].name[0]; n++) - if(!strcmp(songs[n].cname,cbuf)) + + for (n = 0; n < MAX_SONGS && songs[n].name[0]; n++) + if (!strcmp(songs[n].cname, cbuf)) break; strcpy(songs[n].name, buf); strcpy(songs[n].cname, cbuf); songs[n].count++; totalcount++; } - qsort(songs, MAX_SONGS, sizeof(songcmp_t), (QCAST)count_cmp); + qsort(songs, MAX_SONGS, sizeof(songcmp_t), (QCAST) count_cmp); fprintf(fo, " \033[36m¢w¢w\033[37m¦W¦¸\033[36m¢w¢w¢w¢w¢w¢w\033[37mºq" " ¦W\033[36m¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w\033[37m¦¸¼Æ\033[36m" "¢w¢w\033[32m¦@%ld¦¸\033[36m¢w¢w\033[m\n", totalcount); - for(n = 0; n < 100 && songs[n].name[0]; n++) { - fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, + for (n = 0; n < 100 && songs[n].name[0]; n++) { + fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, songs[n].name, songs[n].count, - (float)songs[n].count/totalcount); + (float)songs[n].count / totalcount); } fclose(fp); fclose(fo); diff --git a/mbbsd/user.c b/mbbsd/user.c index a0895c3e..f5615a88 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1,46 +1,50 @@ -/* $Id: user.c,v 1.27 2002/07/02 14:56:22 in2 Exp $ */ +/* $Id: user.c,v 1.28 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static char *sex[8] = { +static char *sex[8] = { MSG_BIG_BOY, MSG_BIG_GIRL, MSG_LITTLE_BOY, MSG_LITTLE_GIRL, MSG_MAN, MSG_WOMAN, MSG_PLANT, MSG_MIME }; -int u_loginview() { - int i; - unsigned int pbits = cuser.loginview; - char choice[5]; - +int +u_loginview() +{ + int i; + unsigned int pbits = cuser.loginview; + char choice[5]; + clear(); - move(4,0); - for(i = 0; i < NUMVIEWFILE ; i++) + move(4, 0); + for (i = 0; i < NUMVIEWFILE; i++) prints(" %c. %-20s %-15s \n", 'A' + i, - loginview_file[i][1],((pbits >> i) & 1 ? "£¾" : "¢æ")); - + loginview_file[i][1], ((pbits >> i) & 1 ? "£¾" : "¢æ")); + clrtobot(); - while(getdata(b_lines - 1, 0, "½Ð«ö [A-N] ¤Á´«³]©w¡A«ö [Return] µ²§ô¡G", - choice, sizeof(choice), LCECHO)) { + while (getdata(b_lines - 1, 0, "½Ð«ö [A-N] ¤Á´«³]©w¡A«ö [Return] µ²§ô¡G", + choice, sizeof(choice), LCECHO)) { i = choice[0] - 'a'; - if(i >= NUMVIEWFILE || i < 0) + if (i >= NUMVIEWFILE || i < 0) bell(); else { pbits ^= (1 << i); - move( i + 4 , 28 ); + move(i + 4, 28); prints((pbits >> i) & 1 ? "£¾" : "¢æ"); } } - - if(pbits != cuser.loginview) { - cuser.loginview = pbits ; + + if (pbits != cuser.loginview) { + cuser.loginview = pbits; passwd_update(usernum, &cuser); } return 0; } -void user_display(userec_t *u, int real) { - int diff = 0; - char genbuf[200]; - +void +user_display(userec_t * u, int real) +{ + int diff = 0; + char genbuf[200]; + clrtobot(); prints( " \033[30;41m¢r¢s¢r¢s¢r¢s\033[m \033[1;30;45m ¨Ï ¥Î ªÌ" @@ -54,7 +58,7 @@ void user_display(userec_t *u, int real) { " »È¦æ±b¤á: %ld »È¨â\n", u->userid, u->username, u->realname, u->address, u->email, sex[u->sex % 8], u->money); - + sethomedir(genbuf, u->userid); prints(" ¨p¤H«H½c: %d «Ê (ÁʶR«H½c: %d «Ê)\n" " ¨¤ÀÃÒ¸¹: %s\n" @@ -70,10 +74,10 @@ void user_display(userec_t *u, int real) { prints(" ¤W¯¸¤å³¹: %d ¦¸ / %d ½g\n", u->numlogins, u->numposts); - if(real) { + if (real) { strcpy(genbuf, "bTCPRp#@XWBA#VSM0123456789ABCDEF"); - for(diff = 0; diff < 32; diff++) - if(!(u->userlevel & (1 << diff))) + for (diff = 0; diff < 32; diff++) + if (!(u->userlevel & (1 << diff))) genbuf[diff] = '-'; prints(" »{ÃÒ¸ê®Æ: %s\n" " userÅv: %s\n", @@ -83,16 +87,16 @@ void user_display(userec_t *u, int real) { prints(" °±¯d´Á¶¡: %d ¤p®É %2d ¤À\n", diff / 60, diff % 60); } - + /* Thor: ·Q¬Ý¬Ý³oÓ user ¬O¨º¨ÇªOªºªO¥D */ - if(u->userlevel >= PERM_BM) { - int i; - boardheader_t *bhdr; - + if (u->userlevel >= PERM_BM) { + int i; + boardheader_t *bhdr; + outs(" ¾á¥ôªO¥D: "); - - for(i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { - if(is_uBM(bhdr->BM,u->userid)) { + + for (i = 0, bhdr = bcache; i < numboards; i++, bhdr++) { + if (is_uBM(bhdr->BM, u->userid)) { outs(bhdr->brdname); outc(' '); } @@ -101,31 +105,33 @@ void user_display(userec_t *u, int real) { } outs(" \033[30;41m¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r¢s¢r" "¢s¢r¢s¢r¢s¢r¢s\033[m"); - + outs((u->userlevel & PERM_LOGINOK) ? "\n±zªºµù¥Uµ{§Ç¤w¸g§¹¦¨¡AÅwªï¥[¤J¥»¯¸" : "\n¦pªGn´£ª@Åv¡A½Ð°Ñ¦Ò¥»¯¸¤½§GÄæ¿ì²zµù¥U"); - + #ifdef NEWUSER_LIMIT - if((u->lastlogin - u->firstlogin < 3 * 86400) && !HAS_PERM(PERM_POST)) + if ((u->lastlogin - u->firstlogin < 3 * 86400) && !HAS_PERM(PERM_POST)) outs("\n·s¤â¤W¸ô¡A¤T¤Ñ«á¶}©ñÅv"); #endif } -void mail_violatelaw(char* crime, char* police, char* reason, char* result){ - char genbuf[200]; - fileheader_t fhdr; - FILE *fp; +void +mail_violatelaw(char *crime, char *police, char *reason, char *result) +{ + char genbuf[200]; + fileheader_t fhdr; + FILE *fp; sprintf(genbuf, "home/%c/%s", crime[0], crime); stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) - return; + if (!(fp = fopen(genbuf, "w"))) + return; fprintf(fp, "§@ªÌ: [Pttªk°|]\n" "¼ÐÃD: [³ø§i] ¹Hªk§P¨M³ø§i\n" "®É¶¡: %s\n" "\033[1;32m%s\033[m§P¨M¡G\n \033[1;32m%s\033[m" "¦]\033[1;35m%s\033[m¦æ¬°¡A\n¹H¤Ï¥»¯¸¯¸³W¡A³B¥H\033[1;35m%s\033[m¡A¯S¦¹³qª¾" - "\n½Ð¨ì PttLaw ¬d¸ß¬ÛÃöªk³W¸ê°T¡A¨Ã¨ì Play-Pay-ViolateLaw ú¥æ»@³æ", + "\n½Ð¨ì PttLaw ¬d¸ß¬ÛÃöªk³W¸ê°T¡A¨Ã¨ì Play-Pay-ViolateLaw ú¥æ»@³æ", ctime(&now), police, crime, reason, result); fclose(fp); sprintf(fhdr.title, "[³ø§i] ¹Hªk§P¨M³ø§i"); @@ -134,16 +140,18 @@ void mail_violatelaw(char* crime, char* police, char* reason, char* result){ append_record(genbuf, &fhdr, sizeof(fhdr)); } -static void violate_law(userec_t *u, int unum){ - char ans[4], ans2[4]; - char reason[128]; - move(1,0); +static void +violate_law(userec_t * u, int unum) +{ + char ans[4], ans2[4]; + char reason[128]; + move(1, 0); clrtobot(); - move(2,0); + move(2, 0); prints("(1)Cross-post (2)¶Ãµo¼s§i«H (3)¶Ãµo³sÂê«H\n"); prints("(4)ÄÌÂZ¯¸¤W¨Ï¥ÎªÌ (8)¨ä¥L¥H»@³æ³B¸m¦æ¬°\n(9)¬å id ¦æ¬°\n"); getdata(5, 0, "(0)µ²§ô", ans, sizeof(ans), DOECHO); - switch(ans[0]){ + switch (ans[0]) { case '1': sprintf(reason, "%s", "Cross-post"); break; @@ -154,84 +162,84 @@ static void violate_law(userec_t *u, int unum){ sprintf(reason, "%s", "¶Ãµo³sÂê«H"); break; case '4': - while(!getdata(7, 0, "½Ð¿é¤J³QÀËÁ|²z¥Ñ¥H¥Üt³d¡G", reason, 50, DOECHO)); - strcat(reason, "[ÄÌÂZ¯¸¤W¨Ï¥ÎªÌ]"); - break; - case '8': + while (!getdata(7, 0, "½Ð¿é¤J³QÀËÁ|²z¥Ñ¥H¥Üt³d¡G", reason, 50, DOECHO)); + strcat(reason, "[ÄÌÂZ¯¸¤W¨Ï¥ÎªÌ]"); + break; + case '8': case '9': - while(!getdata(6, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", reason, 50, DOECHO)); - break; + while (!getdata(6, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", reason, 50, DOECHO)); + break; default: return; } getdata(7, 0, msg_sure_ny, ans2, sizeof(ans2), LCECHO); - if(*ans2 != 'y') - return; - if (ans[0]=='9'){ - char src[STRLEN], dst[STRLEN]; + if (*ans2 != 'y') + return; + if (ans[0] == '9') { + char src[STRLEN], dst[STRLEN]; sprintf(src, "home/%c/%s", u->userid[0], u->userid); sprintf(dst, "tmp/%s", u->userid); Rename(src, dst); log_usies("KILL", u->userid); - post_violatelaw(u->userid, cuser.userid, reason, "¬å°£ ID"); + post_violatelaw(u->userid, cuser.userid, reason, "¬å°£ ID"); u->userid[0] = '\0'; setuserid(unum, u->userid); passwd_update(unum, u); - } - else{ - u->userlevel |= PERM_VIOLATELAW; - u->vl_count ++; + } else { + u->userlevel |= PERM_VIOLATELAW; + u->vl_count++; passwd_update(unum, u); - post_violatelaw(u->userid, cuser.userid, reason, "»@³æ³B¥÷"); - mail_violatelaw(u->userid, cuser.userid, reason, "»@³æ³B¥÷"); - } + post_violatelaw(u->userid, cuser.userid, reason, "»@³æ³B¥÷"); + mail_violatelaw(u->userid, cuser.userid, reason, "»@³æ³B¥÷"); + } pressanykey(); } -void uinfo_query(userec_t *u, int real, int unum) { - userec_t x; - register int i = 0, fail, mail_changed; - int uid; - char ans[4], buf[STRLEN], *p; - char genbuf[200], reason[50]; +void +uinfo_query(userec_t * u, int real, int unum) +{ + userec_t x; + register int i = 0, fail, mail_changed; + int uid; + char ans[4], buf[STRLEN], *p; + char genbuf[200], reason[50]; unsigned long int money = 0; - fileheader_t fhdr; - int flag = 0, temp = 0, money_change = 0; - - FILE *fp; - + fileheader_t fhdr; + int flag = 0, temp = 0, money_change = 0; + + FILE *fp; + fail = mail_changed = 0; - + memcpy(&x, u, sizeof(userec_t)); getdata(b_lines - 1, 0, real ? "(1)§ï¸ê®Æ(2)³]±K½X(3)³]Åv(4)¬å±b¸¹(5)§ïID" "(6)±þ/´_¬¡Ãdª«(7)¼f§P [0]µ²§ô " : "½Ð¿ï¾Ü (1)קï¸ê®Æ (2)³]©w±K½X ==> [0]µ²§ô ", ans, sizeof(ans), DOECHO); - - if(ans[0] > '2' && !real) + + if (ans[0] > '2' && !real) ans[0] = '0'; - - if(ans[0] == '1' || ans[0] == '3') { + + if (ans[0] == '1' || ans[0] == '3') { clear(); i = 2; move(i++, 0); outs(msg_uid); outs(x.userid); } - - switch(ans[0]) { + switch (ans[0]) { case '7': violate_law(&x, unum); return; case '1': move(0, 0); outs("½Ð³v¶µ×§ï¡C"); - - getdata_buf(i++, 0," ¼Ê ºÙ ¡G",x.username, + + getdata_buf(i++, 0, " ¼Ê ºÙ ¡G", x.username, sizeof(x.username), DOECHO); - if(real) { + if (real) { getdata_buf(i++, 0, "¯u¹ê©m¦W¡G", x.realname, sizeof(x.realname), DOECHO); getdata_buf(i++, 0, "¨¤ÀÃÒ¸¹¡G", @@ -241,55 +249,54 @@ void uinfo_query(userec_t *u, int real, int unum) { } sprintf(buf, "%010d", x.mobile); getdata_buf(i++, 0, "¤â¾÷¸¹½X¡G", buf, 11, LCECHO); - x.mobile=atoi(buf); + x.mobile = atoi(buf); getdata_str(i++, 0, "¹q¤l«H½c[ÅÜ°Ên«·s»{ÃÒ]¡G", buf, 50, DOECHO, x.email); - if(strcmp(buf,x.email) && strchr(buf, '@')) { - strcpy(x.email,buf); + if (strcmp(buf, x.email) && strchr(buf, '@')) { + strcpy(x.email, buf); mail_changed = 1 - real; } - sprintf(genbuf, "%i", (u->sex + 1) % 8); getdata_str(i++, 0, "©Ê§O (1)¸¯®æ (2)©j±µ (3)©³} (4)¬ü¬Ü (5)Á¦¨û " "(6)ªü«¼ (7)´Óª« (8)Äqª«¡G", - buf, 3, DOECHO,genbuf); - if(buf[0] >= '1' && buf[0] <= '8') + buf, 3, DOECHO, genbuf); + if (buf[0] >= '1' && buf[0] <= '8') x.sex = (buf[0] - '1') % 8; else x.sex = u->sex % 8; - - while(1) { - int len; - + + while (1) { + int len; + sprintf(genbuf, "%02i/%02i/%02i", u->month, u->day, u->year % 100); len = getdata_str(i, 0, "¥Í¤é ¤ë¤ë/¤é¤é/¦è¤¸¡G", buf, 9, - DOECHO,genbuf); - if(len && len != 8) + DOECHO, genbuf); + if (len && len != 8) continue; - if(!len) { + if (!len) { x.month = u->month; x.day = u->day; x.year = u->year; - } else if(len == 8) { + } else if (len == 8) { x.month = (buf[0] - '0') * 10 + (buf[1] - '0'); - x.day = (buf[3] - '0') * 10 + (buf[4] - '0'); - x.year = (buf[6] - '0') * 10 + (buf[7] - '0'); + x.day = (buf[3] - '0') * 10 + (buf[4] - '0'); + x.year = (buf[6] - '0') * 10 + (buf[7] - '0'); } else continue; - if(!real && (x.month > 12 || x.month < 1 || x.day > 31 || - x.day < 1 || x.year > 90 || x.year < 40)) + if (!real && (x.month > 12 || x.month < 1 || x.day > 31 || + x.day < 1 || x.year > 90 || x.year < 40)) continue; i++; break; } - if(real) { + if (real) { unsigned long int l; - if(HAS_PERM(PERM_BBSADM)) { + if (HAS_PERM(PERM_BBSADM)) { sprintf(genbuf, "%d", x.money); - if(getdata_str(i++, 0,"»È¦æ±b¤á¡G", buf, 10, DOECHO,genbuf)) - if((l = atol(buf)) != 0) { - if(l != x.money) { + if (getdata_str(i++, 0, "»È¦æ±b¤á¡G", buf, 10, DOECHO, genbuf)) + if ((l = atol(buf)) != 0) { + if (l != x.money) { money_change = 1; money = x.money; x.money = l; @@ -297,92 +304,95 @@ void uinfo_query(userec_t *u, int real, int unum) { } } sprintf(genbuf, "%d", x.exmailbox); - if(getdata_str(i++, 0,"ÁʶR«H½c¼Æ¡G", buf, 4, DOECHO,genbuf)) - if((l = atol(buf)) != 0) + if (getdata_str(i++, 0, "ÁʶR«H½c¼Æ¡G", buf, 4, DOECHO, genbuf)) + if ((l = atol(buf)) != 0) x.exmailbox = (int)l; - + getdata_buf(i++, 0, "»{ÃÒ¸ê®Æ¡G", x.justify, sizeof(x.justify), DOECHO); getdata_buf(i++, 0, "³Ìªñ¥úÁ{¾÷¾¹¡G", x.lasthost, sizeof(x.lasthost), DOECHO); - + sprintf(genbuf, "%d", x.numlogins); - if(getdata_str(i++, 0,"¤W½u¦¸¼Æ¡G", buf, 10, DOECHO, genbuf)) - if((fail = atoi(buf)) >= 0) + if (getdata_str(i++, 0, "¤W½u¦¸¼Æ¡G", buf, 10, DOECHO, genbuf)) + if ((fail = atoi(buf)) >= 0) x.numlogins = fail; - - sprintf(genbuf,"%d", u->numposts); - if(getdata_str(i++, 0, "¤å³¹¼Æ¥Ø¡G", buf, 10, DOECHO,genbuf)) - if((fail = atoi(buf)) >= 0) + + sprintf(genbuf, "%d", u->numposts); + if (getdata_str(i++, 0, "¤å³¹¼Æ¥Ø¡G", buf, 10, DOECHO, genbuf)) + if ((fail = atoi(buf)) >= 0) x.numposts = fail; sprintf(genbuf, "%d", u->vl_count); if (getdata_str(i++, 0, "¹Hªk°O¿ý¡G", buf, 10, DOECHO, genbuf)) if ((fail = atoi(buf)) >= 0) x.vl_count = fail; - + sprintf(genbuf, "%d/%d/%d", u->five_win, u->five_lose, u->five_tie); - if(getdata_str(i++, 0, "¤¤l´Ñ¾ÔÁZ ³Ó/±Ñ/©M¡G", buf, 16, DOECHO, - genbuf)) - while(1) { + if (getdata_str(i++, 0, "¤¤l´Ñ¾ÔÁZ ³Ó/±Ñ/©M¡G", buf, 16, DOECHO, + genbuf)) + while (1) { p = strtok(buf, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_win = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_lose = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.five_tie = atoi(p); break; } sprintf(genbuf, "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); - if(getdata_str(i++, 0, "¶H´Ñ¾ÔÁZ ³Ó/±Ñ/©M¡G", buf, 16, DOECHO, - genbuf)) - while(1) { + if (getdata_str(i++, 0, "¶H´Ñ¾ÔÁZ ³Ó/±Ñ/©M¡G", buf, 16, DOECHO, + genbuf)) + while (1) { p = strtok(buf, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_win = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_lose = atoi(p); p = strtok(NULL, "/\r\n"); - if(!p) break; + if (!p) + break; x.chc_tie = atoi(p); break; } fail = 0; } break; - + case '2': i = 19; - if(!real) { - if(!getdata(i++, 0, "½Ð¿é¤Jì±K½X¡G", buf, PASSLEN, NOECHO) || - !checkpasswd(u->passwd, buf)) { + if (!real) { + if (!getdata(i++, 0, "½Ð¿é¤Jì±K½X¡G", buf, PASSLEN, NOECHO) || + !checkpasswd(u->passwd, buf)) { outs("\n\n±z¿é¤Jªº±K½X¤£¥¿½T\n"); fail++; break; } - } - else{ - char witness[3][32]; - for(i=0;i<3;i++){ - if(!getdata(19+i, 0, "½Ð¿é¤J¨ó§UÃÒ©ú¤§¨Ï¥ÎªÌ¡G", - witness[i], sizeof(witness[i]), DOECHO)){ + } else { + char witness[3][32]; + for (i = 0; i < 3; i++) { + if (!getdata(19 + i, 0, "½Ð¿é¤J¨ó§UÃÒ©ú¤§¨Ï¥ÎªÌ¡G", + witness[i], sizeof(witness[i]), DOECHO)) { outs("\n¤£¿é¤J«hµLªk§ó§ï\n"); fail++; break; - } - else if( !(uid = getuser(witness[i])) ){ + } else if (!(uid = getuser(witness[i]))) { outs("\n¬dµL¦¹¨Ï¥ÎªÌ\n"); fail++; break; - } - else { - userec_t atuser; + } else { + userec_t atuser; passwd_query(uid, &atuser); - if (now - atuser.firstlogin < 6*30*24*60*60){ + if (now - atuser.firstlogin < 6 * 30 * 24 * 60 * 60) { outs("\nµù¥U¥¼¶W¹L¥b¦~¡A½Ð«·s¿é¤J\n"); i--; } @@ -392,17 +402,17 @@ void uinfo_query(userec_t *u, int real, int unum) { break; else i = 20; - } - - if(!getdata(i++, 0, "½Ð³]©w·s±K½X¡G", buf, PASSLEN, NOECHO)) { + } + + if (!getdata(i++, 0, "½Ð³]©w·s±K½X¡G", buf, PASSLEN, NOECHO)) { outs("\n\n±K½X³]©w¨ú®ø, Ä~Äò¨Ï¥Î±K½X\n"); fail++; break; } strncpy(genbuf, buf, PASSLEN); - + getdata(i++, 0, "½ÐÀˬd·s±K½X¡G", buf, PASSLEN, NOECHO); - if(strncmp(buf, genbuf, PASSLEN)) { + if (strncmp(buf, genbuf, PASSLEN)) { outs("\n\n·s±K½X½T»{¥¢±Ñ, µLªk³]©w·s±K½X\n"); fail++; break; @@ -412,26 +422,26 @@ void uinfo_query(userec_t *u, int real, int unum) { if (real) x.userlevel &= (!PERM_LOGINOK); break; - + case '3': i = setperms(x.userlevel, str_permid); - if(i == x.userlevel) + if (i == x.userlevel) fail++; else { - flag=1; - temp=x.userlevel; + flag = 1; + temp = x.userlevel; x.userlevel = i; } break; - + case '4': i = QUIT; break; - + case '5': if (getdata_str(b_lines - 3, 0, "·sªº¨Ï¥ÎªÌ¥N¸¹¡G", genbuf, IDLEN + 1, - DOECHO,x.userid)) { - if(searchuser(genbuf)) { + DOECHO, x.userid)) { + if (searchuser(genbuf)) { outs("¿ù»~! ¤w¸g¦³¦P¼Ë ID ªº¨Ï¥ÎªÌ"); fail++; } else @@ -439,78 +449,75 @@ void uinfo_query(userec_t *u, int real, int unum) { } break; case '6': - if(x.mychicken.name[0]) + if (x.mychicken.name[0]) x.mychicken.name[0] = 0; else - strcpy(x.mychicken.name,"[¦º]"); + strcpy(x.mychicken.name, "[¦º]"); break; default: return; } - if(fail) { + if (fail) { pressanykey(); return; } - getdata(b_lines - 1, 0, msg_sure_ny, ans, 3, LCECHO); - if(*ans == 'y') { - if(flag) - post_change_perm(temp,i,cuser.userid,x.userid); - if(strcmp(u->userid, x.userid)) { - char src[STRLEN], dst[STRLEN]; - + if (*ans == 'y') { + if (flag) + post_change_perm(temp, i, cuser.userid, x.userid); + if (strcmp(u->userid, x.userid)) { + char src[STRLEN], dst[STRLEN]; + sethomepath(src, u->userid); sethomepath(dst, x.userid); Rename(src, dst); setuserid(unum, x.userid); } memcpy(u, &x, sizeof(x)); - if(mail_changed) { + if (mail_changed) { #ifdef EMAIL_JUSTIFY x.userlevel &= ~PERM_LOGINOK; mail_justify(); #endif } - - if(i == QUIT) { - char src[STRLEN], dst[STRLEN]; - + if (i == QUIT) { + char src[STRLEN], dst[STRLEN]; + sprintf(src, "home/%c/%s", x.userid[0], x.userid); sprintf(dst, "tmp/%s", x.userid); - if(Rename(src, dst)) { + if (Rename(src, dst)) { sprintf(genbuf, "/bin/rm -fr %s >/dev/null 2>&1", src); -/* do not remove - system(genbuf); -*/ - } + /* + * do not remove system(genbuf); + */ + } log_usies("KILL", x.userid); x.userid[0] = '\0'; setuserid(unum, x.userid); } else log_usies("SetUser", x.userid); - if(money_change) - setumoney(unum,x.money); + if (money_change) + setumoney(unum, x.money); passwd_update(unum, &x); - if(money_change) { + if (money_change) { strcpy(genbuf, "boards/S/Security"); - stampfile(genbuf, &fhdr); - if(!(fp = fopen(genbuf,"w"))) + stampfile(genbuf, &fhdr); + if (!(fp = fopen(genbuf, "w"))) return; - + fprintf(fp, "§@ªÌ: [¨t²Î¦w¥þ§½] ¬ÝªO: Security\n" "¼ÐÃD: [¤½¦w³ø§i] ¯¸ªøקïª÷¿ú³ø§i\n" "®É¶¡: %s\n" " ¯¸ªø\033[1;32m%s\033[m§â\033[1;32m%s\033[m" "ªº¿ú±q\033[1;35m%ld\033[m§ï¦¨\033[1;35m%d\033[m", ctime(&now), cuser.userid, x.userid, money, x.money); - - clrtobot (); + + clrtobot(); clear(); - while( !getdata(5, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", - reason, sizeof(reason), DOECHO) ) - ; - + while (!getdata(5, 0, "½Ð¿é¤J²z¥Ñ¥H¥Üt³d¡G", + reason, sizeof(reason), DOECHO)); + fprintf(fp, "\n \033[1;37m¯¸ªø%sקï¿ú²z¥Ñ¬O¡G%s\033[m", cuser.userid, reason); fclose(fp); @@ -522,7 +529,9 @@ void uinfo_query(userec_t *u, int real, int unum) { } } -int u_info() { +int +u_info() +{ move(2, 0); user_display(&cuser, 0); uinfo_query(&cuser, 0, usernum); @@ -531,108 +540,122 @@ int u_info() { return 0; } -int u_ansi() { +int +u_ansi() +{ showansi ^= 1; cuser.uflag ^= COLOR_FLAG; outs(reset_color); return 0; } -int u_cloak() { +int +u_cloak() +{ outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); return XEASY; } -int u_switchproverb() { -/* char *state[4]={"¥Î¥\\«¬","¦w¶h«¬","¦Û©w«¬","SHUTUP"}; */ - char buf[100]; +int +u_switchproverb() +{ + /* char *state[4]={"¥Î¥\\«¬","¦w¶h«¬","¦Û©w«¬","SHUTUP"}; */ + char buf[100]; + + cuser.proverb = (cuser.proverb + 1) % 4; + setuserfile(buf, fn_proverb); + if (cuser.proverb == 2 && dashd(buf)) { + FILE *fp = fopen(buf, "a"); - cuser.proverb =(cuser.proverb +1) %4; - setuserfile(buf,fn_proverb); - if(cuser.proverb==2 && dashd(buf)) { - FILE *fp = fopen(buf,"a"); - - fprintf(fp,"®y¥k»Êª¬ºA¬°[¦Û©w«¬]n°O±o³]®y¥k»Êªº¤º®eò!!"); + fprintf(fp, "®y¥k»Êª¬ºA¬°[¦Û©w«¬]n°O±o³]®y¥k»Êªº¤º®eò!!"); fclose(fp); } passwd_update(usernum, &cuser); return 0; } -int u_editproverb() { - char buf[100]; - +int +u_editproverb() +{ + char buf[100]; + setutmpmode(PROVERB); - setuserfile(buf,fn_proverb); - move(1,0); + setuserfile(buf, fn_proverb); + move(1, 0); clrtobot(); outs("\n\n ½Ð¤@¦æ¤@¦æ¨Ì§ÇÁä¤J·Q¨t²Î´£¿ô§Aªº¤º®e,\n" " Àx¦s«á°O±o§âª¬ºA³]¬° [¦Û©w«¬] ¤~¦³§@¥Î\n" " ®y¥k»Ê³Ì¦h100±ø"); pressanykey(); - vedit(buf,NA, NULL); + vedit(buf, NA, NULL); return 0; } -void showplans(char *uid) { - char genbuf[200]; - +void +showplans(char *uid) +{ + char genbuf[200]; + sethomefile(genbuf, uid, fn_plans); - if(!show_file(genbuf, 7, MAX_QUERYLINES, ONLY_COLOR)) + if (!show_file(genbuf, 7, MAX_QUERYLINES, ONLY_COLOR)) prints("¡mÓ¤H¦W¤ù¡n%s ¥Ø«e¨S¦³¦W¤ù", uid); } -int showsignature(char *fname) { - FILE *fp; - char buf[256]; - int i, j; - char ch; +int +showsignature(char *fname) +{ + FILE *fp; + char buf[256]; + int i, j; + char ch; clear(); move(2, 0); setuserfile(fname, "sig.0"); j = strlen(fname) - 1; - for(ch = '1'; ch <= '9'; ch++) { + for (ch = '1'; ch <= '9'; ch++) { fname[j] = ch; - if((fp = fopen(fname, "r"))) { + if ((fp = fopen(fname, "r"))) { prints("\033[36m¡i ñ¦WÀÉ.%c ¡j\033[m\n", ch); - for(i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); + for (i = 0; i++ < MAX_SIGLINES && fgets(buf, 256, fp); outs(buf)); fclose(fp); } } return j; } -int u_editsig() { - int aborted; - char ans[4]; - int j; - char genbuf[200]; - +int +u_editsig() +{ + int aborted; + char ans[4]; + int j; + char genbuf[200]; + j = showsignature(genbuf); - + getdata(0, 0, "ñ¦WÀÉ (E)½s¿è (D)§R°£ (Q)¨ú®ø¡H[Q] ", ans, sizeof(ans), LCECHO); - + aborted = 0; - if(ans[0] == 'd') + if (ans[0] == 'd') aborted = 1; - if(ans[0] == 'e') + if (ans[0] == 'e') aborted = 2; - - if(aborted) { - if(!getdata(1, 0, "½Ð¿ï¾Üñ¦WÀÉ(1-9)¡H[1] ", ans, sizeof(ans), DOECHO)) + + if (aborted) { + if (!getdata(1, 0, "½Ð¿ï¾Üñ¦WÀÉ(1-9)¡H[1] ", ans, sizeof(ans), DOECHO)) ans[0] = '1'; - if(ans[0] >= '1' && ans[0] <= '9') { + if (ans[0] >= '1' && ans[0] <= '9') { genbuf[j] = ans[0]; - if(aborted == 1) { + if (aborted == 1) { unlink(genbuf); outs(msg_del_ok); } else { setutmpmode(EDITSIG); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("ñ¦WÀɧó·s§¹²¦"); } } @@ -641,23 +664,25 @@ int u_editsig() { return 0; } -int u_editplan() { - char genbuf[200]; - +int +u_editplan() +{ + char genbuf[200]; + getdata(b_lines - 1, 0, "¦W¤ù (D)§R°£ (E)½s¿è [Q]¨ú®ø¡H[Q] ", genbuf, 3, LCECHO); - - if(genbuf[0] == 'e') { - int aborted; - + + if (genbuf[0] == 'e') { + int aborted; + setutmpmode(EDITPLAN); setuserfile(genbuf, fn_plans); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("¦W¤ù§ó·s§¹²¦"); pressanykey(); return 0; - } else if(genbuf[0] == 'd') { + } else if (genbuf[0] == 'd') { setuserfile(genbuf, fn_plans); unlink(genbuf); outmsg("¦W¤ù§R°£§¹²¦"); @@ -665,23 +690,25 @@ int u_editplan() { return 0; } -int u_editcalendar() { - char genbuf[200]; - +int +u_editcalendar() +{ + char genbuf[200]; + getdata(b_lines - 1, 0, "¦æ¨Æ¾ä (D)§R°£ (E)½s¿è [Q]¨ú®ø¡H[Q] ", genbuf, 3, LCECHO); - - if(genbuf[0] == 'e') { - int aborted; - + + if (genbuf[0] == 'e') { + int aborted; + setutmpmode(EDITPLAN); setcalfile(genbuf, cuser.userid); aborted = vedit(genbuf, NA, NULL); - if(aborted != -1) + if (aborted != -1) outs("¦æ¨Æ¾ä§ó·s§¹²¦"); pressanykey(); return 0; - } else if(genbuf[0] == 'd') { + } else if (genbuf[0] == 'd') { setcalfile(genbuf, cuser.userid); unlink(genbuf); outmsg("¦æ¨Æ¾ä§R°£§¹²¦"); @@ -690,25 +717,29 @@ int u_editcalendar() { } /* ¨Ï¥ÎªÌ¶ñ¼gµù¥Uªí®æ */ -static void getfield(int line, char *info, char *desc, char *buf, int len) { - char prompt[STRLEN]; - char genbuf[200]; +static void +getfield(int line, char *info, char *desc, char *buf, int len) +{ + char prompt[STRLEN]; + char genbuf[200]; sprintf(genbuf, "ì¥ý³]©w¡G%-30.30s (%s)", buf, info); move(line, 2); outs(genbuf); sprintf(prompt, "%s¡G", desc); - if(getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) + if (getdata_str(line + 1, 2, prompt, genbuf, len, DOECHO, buf)) strcpy(buf, genbuf); move(line, 2); prints("%s¡G%s", desc, buf); clrtoeol(); } -static int removespace(char* s){ - int i, index; +static int +removespace(char *s) +{ + int i, index; - for(i=0, index=0;s[i];i++){ + for (i = 0, index = 0; s[i]; i++) { if (s[i] != ' ') s[index++] = s[i]; } @@ -716,59 +747,62 @@ static int removespace(char* s){ return index; } -static int ispersonalid(char *inid) +static int +ispersonalid(char *inid) { - char *lst="ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; - int i, j, cksum; + char *lst = "ABCDEFGHJKLMNPQRSTUVWXYZIO", id[20]; + int i, j, cksum; strcpy(id, inid); i = cksum = 0; - if( !isalpha(id[0]) && (strlen(id)!=10) ) - return 0; + if (!isalpha(id[0]) && (strlen(id) != 10)) + return 0; id[0] = toupper(id[0]); /* A->10, B->11, ..H->17,I->34, J->18... */ - while( lst[i] != id[0] ) - i++; + while (lst[i] != id[0]) + i++; i += 10; id[0] = i % 10 + '0'; - if( !isdigit(id[9]) ) - return 0; + if (!isdigit(id[9])) + return 0; cksum += (id[9] - '0') + (i / 10); - for( j = 0 ; j < 9 ; ++j ){ - if( !isdigit(id[j]) ) - return 0; - cksum += (id[j] - '0') * (9 - j); + for (j = 0; j < 9; ++j) { + if (!isdigit(id[j])) + return 0; + cksum += (id[j] - '0') * (9 - j); } return (cksum % 10) == 0; } -static char *getregcode(char *buf) +static char * +getregcode(char *buf) { sprintf(buf, "%s", crypt(cuser.userid, "02")); return buf; } -static int isvaildemail(char *email) +static int +isvaildemail(char *email) { - FILE *fp; - char buf[128], *c; - if( !strstr(email, "@") ) + FILE *fp; + char buf[128], *c; + if (!strstr(email, "@")) return 0; - for( c = strstr(email, "@") ; *c != 0 ; ++c ) - if( 'A' <= *c && *c <= 'Z' ) + for (c = strstr(email, "@"); *c != 0; ++c) + if ('A' <= *c && *c <= 'Z') *c += 32; - if( (fp = fopen("etc/banemail", "r")) ){ - while( fgets(buf, sizeof(buf), fp) ){ - if( buf[0] == '#' ) + if ((fp = fopen("etc/banemail", "r"))) { + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#') continue; - buf[ strlen(buf) - 1 ] = 0; - if( buf[0] == 'A' && strcmp(&buf[1], email) == 0 ) + buf[strlen(buf) - 1] = 0; + if (buf[0] == 'A' && strcmp(&buf[1], email) == 0) return 0; - if( buf[0] == 'P' && strstr(email, &buf[1]) ) + if (buf[0] == 'P' && strstr(email, &buf[1])) return 0; - if( buf[0] == 'S' && strcmp(strstr(email, "@") + 1, &buf[1]) == 0 ) + if (buf[0] == 'S' && strcmp(strstr(email, "@") + 1, &buf[1]) == 0) return 0; } fclose(fp); @@ -776,20 +810,20 @@ static int isvaildemail(char *email) return 1; } -static void toregister(char *email, char *genbuf, char *phone, char *career, - char *ident, char *rname, char *addr, char *mobile) +static void +toregister(char *email, char *genbuf, char *phone, char *career, + char *ident, char *rname, char *addr, char *mobile) { - FILE *fn; - char buf[128]; + FILE *fn; + char buf[128]; sethomefile(buf, cuser.userid, "justify.wait"); - if( phone[0] != 0 ){ + if (phone[0] != 0) { fn = fopen(buf, "w"); fprintf(fn, "%s\n%s\n%s\n%s\n%s\n%s\n", phone, career, ident, rname, addr, mobile); fclose(fn); } - clear(); stand_title("»{ÃÒ³]©w"); move(2, 0); @@ -812,43 +846,41 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, " ¦¬¨ì«á½Ð¨ì(U)ser => (R)egister ¿é¤J»{ÃÒ½X, §Y¥i³q¹L»{ÃÒ\n"); #endif - while( 1 ){ + while (1) { email[0] = 0; getfield(15, "¨¤À»{ÃÒ¥Î", "E-Mail Address", email, 50); - if( strcmp(email, "x") == 0 || strcmp(email, "X") == 0 ) + if (strcmp(email, "x") == 0 || strcmp(email, "X") == 0) break; #ifdef HAVEMOBILE - else if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) { - if ( isvaildmobile(mobile) ) { - char yn[3]; - getdata(16, 0, "½Ð¦A¦¸½T»{±z¿é¤Jªº¤â¾÷¸¹½X¥¿½T¹À? [y/N]", - yn, sizeof(yn), LCECHO); - if( yn[0] == 'Y' || yn[0] == 'y' ) - break; - } - else{ - move(17, 0); - prints("«ü©wªº¤â¾÷¸¹½X¤£¦Xªk," - "Y±zµL¤â¾÷ªù¸¹½Ð¿ï¾Ü¨ä¥L¤è¦¡»{ÃÒ"); - } + else if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) { + if (isvaildmobile(mobile)) { + char yn[3]; + getdata(16, 0, "½Ð¦A¦¸½T»{±z¿é¤Jªº¤â¾÷¸¹½X¥¿½T¹À? [y/N]", + yn, sizeof(yn), LCECHO); + if (yn[0] == 'Y' || yn[0] == 'y') + break; + } else { + move(17, 0); + prints("«ü©wªº¤â¾÷¸¹½X¤£¦Xªk," + "Y±zµL¤â¾÷ªù¸¹½Ð¿ï¾Ü¨ä¥L¤è¦¡»{ÃÒ"); + } } #endif - else if( isvaildemail(email) ){ - char yn[3]; + else if (isvaildemail(email)) { + char yn[3]; getdata(16, 0, "½Ð¦A¦¸½T»{±z¿é¤Jªº E-Mail ¦ì¸m¥¿½T¹À? [y/N]", yn, sizeof(yn), LCECHO); - if( yn[0] == 'Y' || yn[0] == 'y' ) + if (yn[0] == 'Y' || yn[0] == 'y') break; - } - else{ + } else { move(17, 0); prints("«ü©wªº E-Mail ¤£¦Xªk," "Y±zµL E-Mail ½Ð¿é¤J x¥Ñ¯¸ªø¤â°Ê»{ÃÒ"); } } strncpy(cuser.email, email, sizeof(cuser.email)); - if( strcasecmp(email, "x") == 0 ){ /* ¤â°Ê»{ÃÒ */ + if (strcasecmp(email, "x") == 0) { /* ¤â°Ê»{ÃÒ */ if ((fn = fopen(fn_register, "a"))) { fprintf(fn, "num: %d, %s", usernum, ctime(&now)); fprintf(fn, "uid: %s\n", cuser.userid); @@ -862,28 +894,27 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, fprintf(fn, "----\n"); fclose(fn); } - } - else{ - char tmp[IDLEN + 1]; - if( phone != NULL ){ + } else { + char tmp[IDLEN + 1]; + if (phone != NULL) { #ifdef HAVEMOBILE - if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) - sprintf(genbuf, "%s:%s:<Mobile>", phone, career); - else + if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) + sprintf(genbuf, "%s:%s:<Mobile>", phone, career); + else #endif - sprintf(genbuf, "%s:%s:<Email>", phone, career); + sprintf(genbuf, "%s:%s:<Email>", phone, career); strncpy(cuser.justify, genbuf, REGLEN); sethomefile(buf, cuser.userid, "justify"); } - sprintf(buf, "±z¦b "BBSNAME" ªº»{ÃÒ½X: %s", getregcode(genbuf)); + sprintf(buf, "±z¦b " BBSNAME " ªº»{ÃÒ½X: %s", getregcode(genbuf)); strcpy(tmp, cuser.userid); strcpy(cuser.userid, "SYSOP"); #ifdef HAVEMOBILE - if ( strcmp(email, "m") == 0 || strcmp(email,"M") == 0 ) - mobile_message(mobile, buf); - else + if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) + mobile_message(mobile, buf); + else #endif - bsmtp("etc/registermail", buf, email, 0); + bsmtp("etc/registermail", buf, email, 0); strcpy(cuser.userid, tmp); outs("\n\n\n§Ú̧Y±N±H¥X»{ÃÒ«H (±zÀ³¸Ó·|¦b 10 ¤ÀÄÁ¤º¦¬¨ì)\n" "¦¬¨ì«á±z¥i¥H¸ò¾Ú»{ÃÒ«H¼ÐÃDªº»{ÃÒ½X\n" @@ -893,25 +924,27 @@ static void toregister(char *email, char *genbuf, char *phone, char *career, } } -int u_register(void) +int +u_register(void) { - char rname[21], addr[51], ident[12], mobile[21]; - char phone[21], career[41], email[51],birthday[9],sex_is[2],year,mon,day; - char inregcode[14], regcode[50]; - char ans[3], *ptr; - char genbuf[200]; - FILE *fn; - - if(cuser.userlevel & PERM_LOGINOK) { + char rname[21], addr[51], ident[12], mobile[21]; + char phone[21], career[41], email[51], birthday[9], sex_is[2], + year, mon, day; + char inregcode[14], regcode[50]; + char ans[3], *ptr; + char genbuf[200]; + FILE *fn; + + if (cuser.userlevel & PERM_LOGINOK) { outs("±zªº¨¥÷½T»{¤w¸g§¹¦¨¡A¤£»Ý¶ñ¼g¥Ó½Ðªí"); return XEASY; } - if((fn = fopen(fn_register, "r"))) { - while(fgets(genbuf, STRLEN, fn)) { - if((ptr = strchr(genbuf, '\n'))) + if ((fn = fopen(fn_register, "r"))) { + while (fgets(genbuf, STRLEN, fn)) { + if ((ptr = strchr(genbuf, '\n'))) *ptr = '\0'; - if(strncmp(genbuf, "uid: ", 5) == 0 && - strcmp(genbuf + 5, cuser.userid) == 0) { + if (strncmp(genbuf, "uid: ", 5) == 0 && + strcmp(genbuf + 5, cuser.userid) == 0) { fclose(fn); outs("±zªºµù¥U¥Ó½Ð³æ©|¦b³B²z¤¤¡A½Ð@¤ßµ¥Ô"); return XEASY; @@ -919,32 +952,38 @@ int u_register(void) } fclose(fn); } - strcpy(ident, cuser.ident); strcpy(rname, cuser.realname); strcpy(addr, cuser.address); strcpy(email, cuser.email); - sprintf(mobile,"0%09d",cuser.mobile); - if( cuser.month == 0 && cuser.day && cuser.year == 0 ) + sprintf(mobile, "0%09d", cuser.mobile); + if (cuser.month == 0 && cuser.day && cuser.year == 0) birthday[0] = 0; else sprintf(birthday, "%02i/%02i/%02i", cuser.month, cuser.day, cuser.year % 100); - sex_is[0]=(cuser.sex % 8)+'1';sex_is[1]=0; + sex_is[0] = (cuser.sex % 8) + '1'; + sex_is[1] = 0; career[0] = phone[0] = '\0'; sethomefile(genbuf, cuser.userid, "justify.wait"); - if( (fn = fopen(genbuf, "r")) ){ - fgets(phone, 21, fn); phone[ strlen(phone) - 1] = 0; - fgets(career,41, fn); career[strlen(career)- 1] = 0; - fgets(ident, 12, fn); ident[ strlen(ident) - 1] = 0; - fgets(rname, 21, fn); rname[ strlen(rname) - 1] = 0; - fgets(addr, 51, fn); addr [ strlen(addr) - 1] = 0; - fgets(mobile,21, fn); mobile[strlen(mobile)- 1] = 0; + if ((fn = fopen(genbuf, "r"))) { + fgets(phone, 21, fn); + phone[strlen(phone) - 1] = 0; + fgets(career, 41, fn); + career[strlen(career) - 1] = 0; + fgets(ident, 12, fn); + ident[strlen(ident) - 1] = 0; + fgets(rname, 21, fn); + rname[strlen(rname) - 1] = 0; + fgets(addr, 51, fn); + addr[strlen(addr) - 1] = 0; + fgets(mobile, 21, fn); + mobile[strlen(mobile) - 1] = 0; fclose(fn); } - if( cuser.year != 0 && /* ¤w¸g²Ä¤@¦¸¶ñ¹L¤F~ ^^" */ - strcmp(cuser.email, "x") != 0 && /* ¤W¦¸¤â°Ê»{ÃÒ¥¢±Ñ */ - strcmp(cuser.email, "X") != 0 ) { + if (cuser.year != 0 && /* ¤w¸g²Ä¤@¦¸¶ñ¹L¤F~ ^^" */ + strcmp(cuser.email, "x") != 0 && /* ¤W¦¸¤â°Ê»{ÃÒ¥¢±Ñ */ + strcmp(cuser.email, "X") != 0) { clear(); stand_title("EMail»{ÃÒ"); move(2, 0); @@ -953,9 +992,9 @@ int u_register(void) cuser.userid, cuser.username); inregcode[0] = 0; getdata(10, 0, "±zªº¿é¤J: ", inregcode, sizeof(inregcode), DOECHO); - if( strcmp(inregcode, getregcode(regcode)) == 0 ){ - int unum; - if( (unum = getuser(cuser.userid)) == 0 ){ + if (strcmp(inregcode, getregcode(regcode)) == 0) { + int unum; + if ((unum = getuser(cuser.userid)) == 0) { outs("¨t²Î¿ù»~¡A¬dµL¦¹¤H\n\n"); pressanykey(); u_exit("getuser error"); @@ -971,89 +1010,88 @@ int u_register(void) u_exit("registed"); exit(0); return QUIT; - } else if( strcmp(inregcode, "x")!=0 && strcmp(inregcode, "X")!=0 ){ + } else if (strcmp(inregcode, "x") != 0 && strcmp(inregcode, "X") != 0) { outs("»{ÃÒ½X¿ù»~\n"); pressanykey(); } toregister(email, genbuf, phone, career, ident, rname, addr, mobile); return FULLUPDATE; } - getdata(b_lines - 1, 0, "±z½T©wn¶ñ¼gµù¥U³æ¶Ü(Y/N)¡H[N] ", ans, sizeof(ans), LCECHO); - if(ans[0] != 'y') + if (ans[0] != 'y') return FULLUPDATE; - + move(2, 0); clrtobot(); - while(1) { + while (1) { clear(); move(1, 0); prints("%s(%s) ±z¦n¡A½Ð¾Ú¹ê¶ñ¼g¥H¤Uªº¸ê®Æ:", cuser.userid, cuser.username); - do{ + do { getfield(3, "D120908396", "¨¤ÀÃÒ¸¹", ident, 11); - if( 'a' <= ident[0] && ident[0] <= 'z' ) + if ('a' <= ident[0] && ident[0] <= 'z') ident[0] -= 32; - }while( !ispersonalid(ident) ); - while( 1 ){ + } while (!ispersonalid(ident)); + while (1) { getfield(5, "½Ð¥Î¤¤¤å", "¯u¹ê©m¦W", rname, 20); - if( removespace(rname) && rname[0] < 0 && - !strstr(rname, "ªü") && !strstr(rname, "¤p") ) + if (removespace(rname) && rname[0] < 0 && + !strstr(rname, "ªü") && !strstr(rname, "¤p")) break; vmsg("±zªº¿é¤J¤£¥¿½T"); } - while( 1 ){ + while (1) { getfield(7, "¾Ç®Õ(§t\033[1;33m¨t©Ò¦~¯Å\033[m)©Î³æ¦ì¾ºÙ", "ªA°È³æ¦ì", career, 40); - if( removespace(career) && career[0] < 0 && strlen(career) >= 4 ) + if (removespace(career) && career[0] < 0 && strlen(career) >= 4) break; vmsg("±zªº¿é¤J¤£¥¿½T"); } - while( 1 ){ + while (1) { getfield(9, "§t¿¤¥«¤Îªù¹ì¸¹½X(¥x¥_½Ð¥[\033[1;33m¦æ¬F°Ï\033[m)", "¥Ø«e¦í§}", addr, 50); - if( removespace(addr) && addr[0] < 0 && strlen(addr) >= 15 ) + if (removespace(addr) && addr[0] < 0 && strlen(addr) >= 15) break; vmsg("³oÓ¦a§}¨Ã¤£¦Xªk"); } - while( 1 ){ + while (1) { getfield(11, "¤£¥[-(), ¥]¬Aªø³~°Ï¸¹", "³sµ¸¹q¸Ü", phone, 11); - if( removespace(phone) && phone[0] == '0' && strlen(phone) >= 9 ) + if (removespace(phone) && phone[0] == '0' && strlen(phone) >= 9) break; vmsg("³oÓ¹q¸Ü¸¹½X¨Ã¤£¦Xªk"); } getfield(13, "¥u¿é¤J¼Æ¦r ¦p:0912345678 (¥i¤£¶ñ)", "¤â¾÷¸¹½X", mobile, 20); - while(1) { - int len; - - getfield(15,"¤ë¤ë/¤é¤é/¦è¤¸ ¦p:09/27/76","¥Í¤é",birthday,9); + while (1) { + int len; + + getfield(15, "¤ë¤ë/¤é¤é/¦è¤¸ ¦p:09/27/76", "¥Í¤é", birthday, 9); len = strlen(birthday); - if(!len) { + if (!len) { sprintf(birthday, "%02i/%02i/%02i", cuser.month, cuser.day, cuser.year % 100); mon = cuser.month; day = cuser.day; year = cuser.year; - } else if(len == 8) { + } else if (len == 8) { mon = (birthday[0] - '0') * 10 + (birthday[1] - '0'); day = (birthday[3] - '0') * 10 + (birthday[4] - '0'); year = (birthday[6] - '0') * 10 + (birthday[7] - '0'); } else continue; - if(mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || - year < 40) + if (mon > 12 || mon < 1 || day > 31 || day < 1 || year > 90 || + year < 40) continue; break; } getfield(17, "1.¸¯®æ 2.©j±µ ", "©Ê§O", sex_is, 2); getdata(18, 0, "¥H¤W¸ê®Æ¬O§_¥¿½T(Y/N)¡H(Q)¨ú®øµù¥U [N] ", ans, sizeof(ans), LCECHO); - if(ans[0] == 'q') + if (ans[0] == 'q') return 0; - if(ans[0] == 'y') + if (ans[0] == 'y') break; } strcpy(cuser.ident, ident); @@ -1072,7 +1110,7 @@ int u_register(void) toregister(email, genbuf, phone, career, ident, rname, addr, mobile); clear(); - move(9,3); + move(9, 3); prints("³Ì«áPost¤@½g\033[32m¦Û§Ú¤¶²Ð¤å³¹\033[mµ¹¤j®a§a¡A" "§i¶D©Ò¦³¦Ñ°©ÀY\033[31m§Ú¨Ó°Õ^$¡C\\n\n\n\n"); pressanykey(); @@ -1085,15 +1123,17 @@ int u_register(void) } /* ¦C¥X©Ò¦³µù¥U¨Ï¥ÎªÌ */ -static int usercounter, totalusers, showrealname; -static ushort u_list_special; - -static int u_list_CB(userec_t *uentp) { - static int i; - char permstr[8], *ptr; - register int level; - - if(uentp == NULL) { +static int usercounter, totalusers, showrealname; +static ushort u_list_special; + +static int +u_list_CB(userec_t * uentp) +{ + static int i; + char permstr[8], *ptr; + register int level; + + if (uentp == NULL) { move(2, 0); clrtoeol(); prints("\033[7m ¨Ï¥ÎªÌ¥N¸¹ %-25s ¤W¯¸ ¤å³¹ %s " @@ -1103,49 +1143,47 @@ static int u_list_CB(userec_t *uentp) { i = 3; return 0; } - - if(bad_user_id(uentp->userid)) + if (bad_user_id(uentp->userid)) return 0; - - if((uentp->userlevel & ~(u_list_special)) == 0) + + if ((uentp->userlevel & ~(u_list_special)) == 0) return 0; - - if(i == b_lines) { + + if (i == b_lines) { prints("\033[34;46m ¤wÅã¥Ü %d/%d ¤H(%d%%) \033[31;47m " "(Space)\033[30m ¬Ý¤U¤@¶ \033[31m(Q)\033[30m Â÷¶} \033[m", usercounter, totalusers, usercounter * 100 / totalusers); i = igetch(); - if(i == 'q' || i == 'Q') + if (i == 'q' || i == 'Q') return QUIT; i = 3; } - if(i == 3) { + if (i == 3) { move(3, 0); clrtobot(); } - level = uentp->userlevel; strcpy(permstr, "----"); - if(level & PERM_SYSOP) + if (level & PERM_SYSOP) permstr[0] = 'S'; - else if(level & PERM_ACCOUNTS) + else if (level & PERM_ACCOUNTS) permstr[0] = 'A'; - else if(level & PERM_DENYPOST) + else if (level & PERM_DENYPOST) permstr[0] = 'p'; - if(level & (PERM_BOARD)) + if (level & (PERM_BOARD)) permstr[1] = 'B'; - else if(level & (PERM_BM)) + else if (level & (PERM_BM)) permstr[1] = 'b'; - if(level & (PERM_XEMPT)) + if (level & (PERM_XEMPT)) permstr[2] = 'X'; - else if(level & (PERM_LOGINOK)) + else if (level & (PERM_LOGINOK)) permstr[2] = 'R'; - if(level & (PERM_CLOAK | PERM_SEECLOAK)) + if (level & (PERM_CLOAK | PERM_SEECLOAK)) permstr[3] = 'C'; - + ptr = (char *)Cdate(&uentp->lastlogin); ptr[18] = '\0'; prints("%-14s %-27.27s%5d %5d %s %s\n", @@ -1158,26 +1196,28 @@ static int u_list_CB(userec_t *uentp) { return 0; } -int u_list() { - char genbuf[3]; - +int +u_list() +{ + char genbuf[3]; + setutmpmode(LAUSERS); showrealname = u_list_special = usercounter = 0; totalusers = SHM->number; - if(HAS_PERM(PERM_SEEULEVELS)) { + if (HAS_PERM(PERM_SEEULEVELS)) { getdata(b_lines - 1, 0, "Æ[¬Ý [1]¯S®íµ¥¯Å (2)¥þ³¡¡H", genbuf, 3, DOECHO); - if(genbuf[0] != '2') + if (genbuf[0] != '2') u_list_special = PERM_BASIC | PERM_CHAT | PERM_PAGE | PERM_POST | PERM_LOGINOK | PERM_BM; } - if(HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { + if (HAS_PERM(PERM_CHATROOM) || HAS_PERM(PERM_SYSOP)) { getdata(b_lines - 1, 0, "Åã¥Ü [1]¯u¹ê©m¦W (2)¼ÊºÙ¡H", genbuf, 3, DOECHO); - if(genbuf[0] != '2') + if (genbuf[0] != '2') showrealname = 1; } u_list_CB(NULL); - if(passwd_apply(u_list_CB) == -1) { + if (passwd_apply(u_list_CB) == -1) { outs(msg_nobody); return XEASY; } diff --git a/mbbsd/var.c b/mbbsd/var.c index fe778782..221c9cb4 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -1,570 +1,565 @@ -/* $Id: var.c,v 1.9 2002/07/05 13:14:14 in2 Exp $ */ +/* $Id: var.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #define INCLUDE_VAR_H #include "bbs.h" -char *str_permid[] = { - "°ò¥»Åv¤O", /* PERM_BASIC */ - "¶i¤J²á¤Ñ«Ç", /* PERM_CHAT */ - "§ä¤H²á¤Ñ", /* PERM_PAGE */ - "µoªí¤å³¹", /* PERM_POST */ - "µù¥Uµ{§Ç»{ÃÒ", /* PERM_LOGINOK */ - "«H¥óµL¤W", /* PERM_MAILLIMIT */ - "Áô¨³N", /* PERM_CLOAK */ - "¬Ý¨£§ÔªÌ", /* PERM_SEECLOAK */ - "¥Ã¤[«O¯d±b¸¹", /* PERM_XEMPT */ - "¯¸ªøÁô¨³N", /* PERM_DENYPOST */ - "ªO¥D", /* PERM_BM */ - "±b¸¹Á`ºÞ", /* PERM_ACCOUNTS */ - "²á¤Ñ«ÇÁ`ºÞ", /* PERM_CHATCLOAK */ - "¬ÝªOÁ`ºÞ", /* PERM_BOARD */ - "¯¸ªø", /* PERM_SYSOP */ - "BBSADM", /* PERM_POSTMARK */ - "¤£¦C¤J±Æ¦æº]", /* PERM_NOTOP */ - "¹Hªk³q½r¤¤", /* PERM_VIOLATELAW */ - "¤£±µ¨ü¯¸¥~ªº«H", /* PERM_ */ - "¨S·Q¨ì", /* PERM_ */ - "µøı¯¸ªø", /* PERM_VIEWSYSOP */ - "Æ[¹î¨Ï¥ÎªÌ¦æÂÜ", /* PERM_LOGUSER */ - "ºëµØ°ÏÁ`¾ã²zÅv", /* PERM_Announce */ - "¤½Ãö²Õ", /* PERM_RELATION */ - "¯S°È²Õ", /* PERM_SMG */ - "µ{¦¡²Õ", /* PERM_PRG */ - "¬¡°Ê²Õ", /* PERM_ACTION */ - "¬ü¤u²Õ", /* PERM_PAINT */ - "¥ßªk²Õ", /* PERM_LAW */ - "¤p²Õªø", /* PERM_SYSSUBOP */ - "¤@¯Å¥DºÞ", /* PERM_LSYSOP */ - "¢Þ¢ü¢ü" /* PERM_PTT */ +char *str_permid[] = { + "°ò¥»Åv¤O", /* PERM_BASIC */ + "¶i¤J²á¤Ñ«Ç", /* PERM_CHAT */ + "§ä¤H²á¤Ñ", /* PERM_PAGE */ + "µoªí¤å³¹", /* PERM_POST */ + "µù¥Uµ{§Ç»{ÃÒ", /* PERM_LOGINOK */ + "«H¥óµL¤W", /* PERM_MAILLIMIT */ + "Áô¨³N", /* PERM_CLOAK */ + "¬Ý¨£§ÔªÌ", /* PERM_SEECLOAK */ + "¥Ã¤[«O¯d±b¸¹", /* PERM_XEMPT */ + "¯¸ªøÁô¨³N", /* PERM_DENYPOST */ + "ªO¥D", /* PERM_BM */ + "±b¸¹Á`ºÞ", /* PERM_ACCOUNTS */ + "²á¤Ñ«ÇÁ`ºÞ", /* PERM_CHATCLOAK */ + "¬ÝªOÁ`ºÞ", /* PERM_BOARD */ + "¯¸ªø", /* PERM_SYSOP */ + "BBSADM", /* PERM_POSTMARK */ + "¤£¦C¤J±Æ¦æº]", /* PERM_NOTOP */ + "¹Hªk³q½r¤¤", /* PERM_VIOLATELAW */ + "¤£±µ¨ü¯¸¥~ªº«H", /* PERM_ */ + "¨S·Q¨ì", /* PERM_ */ + "µøı¯¸ªø", /* PERM_VIEWSYSOP */ + "Æ[¹î¨Ï¥ÎªÌ¦æÂÜ", /* PERM_LOGUSER */ + "ºëµØ°ÏÁ`¾ã²zÅv", /* PERM_Announce */ + "¤½Ãö²Õ", /* PERM_RELATION */ + "¯S°È²Õ", /* PERM_SMG */ + "µ{¦¡²Õ", /* PERM_PRG */ + "¬¡°Ê²Õ", /* PERM_ACTION */ + "¬ü¤u²Õ", /* PERM_PAINT */ + "¥ßªk²Õ", /* PERM_LAW */ + "¤p²Õªø", /* PERM_SYSSUBOP */ + "¤@¯Å¥DºÞ", /* PERM_LSYSOP */ + "¢Þ¢ü¢ü" /* PERM_PTT */ }; -char *str_permboard[] = { - "¤£¥i Zap", /* BRD_NOZAP */ - "¤£¦C¤J²Îp", /* BRD_NOCOUNT */ - "¤£Âà«H", /* BRD_NOTRAN */ - "¸s²ÕªO", /* BRD_GROUP */ - "ÁôÂêO", /* BRD_HIDE */ - "¨î(¤£»Ý³]©w)", /* BRD_POSTMASK */ - "°Î¦WªO", /* BRD_ANONYMOUS */ - "¹w³]°Î¦WªO", /* BRD_DEFAULTANONYMOUS */ - "¹Hªk§ï¶i¤¤¬ÝªO", /* BRD_BAD */ - "³s¸p±M¥Î¬ÝªO", /* BRD_VOTEBOARD */ - "¤wĵ§in¼o°£", /* BRD_WARNEL */ - "¼öªù¬ÝªO¸s²Õ", /* BRD_TOP */ +char *str_permboard[] = { + "¤£¥i Zap", /* BRD_NOZAP */ + "¤£¦C¤J²Îp", /* BRD_NOCOUNT */ + "¤£Âà«H", /* BRD_NOTRAN */ + "¸s²ÕªO", /* BRD_GROUP */ + "ÁôÂêO", /* BRD_HIDE */ + "¨î(¤£»Ý³]©w)", /* BRD_POSTMASK */ + "°Î¦WªO", /* BRD_ANONYMOUS */ + "¹w³]°Î¦WªO", /* BRD_DEFAULTANONYMOUS */ + "¹Hªk§ï¶i¤¤¬ÝªO", /* BRD_BAD */ + "³s¸p±M¥Î¬ÝªO", /* BRD_VOTEBOARD */ + "¤wĵ§in¼o°£", /* BRD_WARNEL */ + "¼öªù¬ÝªO¸s²Õ", /* BRD_TOP */ + "¨S·Q¨ì", + "¨S·Q¨ì", + "¨S·Q¨ì", + "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", - "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", - "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", - "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", "¨S·Q¨ì", - "¨S·Q¨ì", }; -int usernum; -int currmode = 0; -int curredit = 0; -int showansi = 1; -int paste_level; -int currbid; -char quote_file[80] = "\0"; -char quote_user[80] = "\0"; -char paste_title[STRLEN]; -char paste_path[256]; -char currtitle[TTLEN + 1] = "\0"; -char vetitle[TTLEN + 1] = "\0"; -char currowner[IDLEN + 2] = "\0"; -char currauthor[IDLEN + 2] = "\0"; -char currfile[FNLEN]; /* current file name @ bbs.c mail.c */ -char currboard[IDLEN + 2]; -char currBM[IDLEN * 3 + 10]; -char reset_color[4] = "\033[m"; -char margs[64] = "\0"; /* main argv list*/ -pid_t currpid; /* current process ID */ -time_t login_start_time; -time_t start_time; -time_t paste_time; -userec_t cuser; /* current user structure */ -userec_t xuser; /* lookup user structure */ -crosspost_t postrecord; /* anti cross post */ +int usernum; +int currmode = 0; +int curredit = 0; +int showansi = 1; +int paste_level; +int currbid; +char quote_file[80] = "\0"; +char quote_user[80] = "\0"; +char paste_title[STRLEN]; +char paste_path[256]; +char currtitle[TTLEN + 1] = "\0"; +char vetitle[TTLEN + 1] = "\0"; +char currowner[IDLEN + 2] = "\0"; +char currauthor[IDLEN + 2] = "\0"; +char currfile[FNLEN];/* current file name @ bbs.c mail.c */ +char currboard[IDLEN + 2]; +char currBM[IDLEN * 3 + 10]; +char reset_color[4] = "\033[m"; +char margs[64] = "\0"; /* main argv list */ +pid_t currpid; /* current process ID */ +time_t login_start_time; +time_t start_time; +time_t paste_time; +userec_t cuser; /* current user structure */ +userec_t xuser; /* lookup user structure */ +crosspost_t postrecord; /* anti cross post */ unsigned int currbrdattr; unsigned int currstat; -unsigned char currfmode; /* current file mode */ +unsigned char currfmode; /* current file mode */ /* global string variables */ /* filename */ -char *fn_passwd = FN_PASSWD; -char *fn_board = FN_BOARD; -char *fn_note_ans = FN_NOTE_ANS; -char *fn_register = "register.new"; -char *fn_plans = "plans"; -char *fn_writelog = "writelog"; -char *fn_talklog = "talklog"; -char *fn_overrides = FN_OVERRIDES; -char *fn_reject = FN_REJECT; -char *fn_canvote = FN_CANVOTE; -char *fn_notes = "notes"; -char *fn_water = FN_WATER; -char *fn_visable = FN_VISABLE; -char *fn_mandex = "/.Names"; -char *fn_proverb = "proverb"; +char *fn_passwd = FN_PASSWD; +char *fn_board = FN_BOARD; +char *fn_note_ans = FN_NOTE_ANS; +char *fn_register = "register.new"; +char *fn_plans = "plans"; +char *fn_writelog = "writelog"; +char *fn_talklog = "talklog"; +char *fn_overrides = FN_OVERRIDES; +char *fn_reject = FN_REJECT; +char *fn_canvote = FN_CANVOTE; +char *fn_notes = "notes"; +char *fn_water = FN_WATER; +char *fn_visable = FN_VISABLE; +char *fn_mandex = "/.Names"; +char *fn_proverb = "proverb"; /* are descript in userec.loginview */ -char *loginview_file[NUMVIEWFILE][2] = { - {FN_NOTE_ANS ,"»Ä²¢W»¶¬y¨¥ªO"}, - {FN_TOPSONG ,"ÂIºq±Æ¦æº]" }, - {"etc/topusr" ,"¤Q¤j±Æ¦æº]" }, - {"etc/topusr100" ,"¦Ê¤j±Æ¦æº]" }, - {"etc/birth.today" ,"¤µ¤é¹Ø¬P" }, - {"etc/weather.tmp" ,"¤Ñ®ð§Ö³ø" }, - {"etc/stock.tmp" ,"ªÑ¥«§Ö³ø" }, - {"etc/day" ,"¤µ¤é¤Q¤j¸ÜÃD" }, - {"etc/week" ,"¤@¶g¤¤Q¤j¸ÜÃD"}, - {"etc/today" ,"¤µ¤Ñ¤W¯¸¤H¦¸" }, - {"etc/yesterday" ,"¬Q¤é¤W¯¸¤H¦¸" }, - {"etc/history" ,"¾ú¥v¤Wªº¤µ¤Ñ" }, - {"etc/topboardman" ,"ºëµØ°Ï±Æ¦æº]" }, - {"etc/topboard.tmp","¬ÝªO¤H®ð±Æ¦æº]"} +char *loginview_file[NUMVIEWFILE][2] = { + {FN_NOTE_ANS, "»Ä²¢W»¶¬y¨¥ªO"}, + {FN_TOPSONG, "ÂIºq±Æ¦æº]"}, + {"etc/topusr", "¤Q¤j±Æ¦æº]"}, + {"etc/topusr100", "¦Ê¤j±Æ¦æº]"}, + {"etc/birth.today", "¤µ¤é¹Ø¬P"}, + {"etc/weather.tmp", "¤Ñ®ð§Ö³ø"}, + {"etc/stock.tmp", "ªÑ¥«§Ö³ø"}, + {"etc/day", "¤µ¤é¤Q¤j¸ÜÃD"}, + {"etc/week", "¤@¶g¤¤Q¤j¸ÜÃD"}, + {"etc/today", "¤µ¤Ñ¤W¯¸¤H¦¸"}, + {"etc/yesterday", "¬Q¤é¤W¯¸¤H¦¸"}, + {"etc/history", "¾ú¥v¤Wªº¤µ¤Ñ"}, + {"etc/topboardman", "ºëµØ°Ï±Æ¦æº]"}, + {"etc/topboard.tmp", "¬ÝªO¤H®ð±Æ¦æº]"} }; /* message */ -char *msg_seperator = MSG_SEPERATOR; -char *msg_mailer = MSG_MAILER; -char *msg_shortulist = MSG_SHORTULIST; - -char *msg_cancel = MSG_CANCEL; -char *msg_usr_left = MSG_USR_LEFT; -char *msg_nobody = MSG_NOBODY; - -char *msg_sure_ny = MSG_SURE_NY; -char *msg_sure_yn = MSG_SURE_YN; - -char *msg_bid = MSG_BID; -char *msg_uid = MSG_UID; - -char *msg_del_ok = MSG_DEL_OK; -char *msg_del_ny = MSG_DEL_NY; - -char *msg_fwd_ok = MSG_FWD_OK; -char *msg_fwd_err1 = MSG_FWD_ERR1; -char *msg_fwd_err2 = MSG_FWD_ERR2; - -char *err_board_update = ERR_BOARD_UPDATE; -char *err_bid = ERR_BID; -char *err_uid = ERR_UID; -char *err_filename = ERR_FILENAME; - -char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; -char *str_new = "new"; -char *str_reply = "Re: "; -char *str_space = " \t\n\r"; -char *str_sysop = "SYSOP"; -char *str_author1 = STR_AUTHOR1; -char *str_author2 = STR_AUTHOR2; -char *str_post1 = STR_POST1; -char *str_post2 = STR_POST2; -char *BBSName = BBSNAME; +char *msg_seperator = MSG_SEPERATOR; +char *msg_mailer = MSG_MAILER; +char *msg_shortulist = MSG_SHORTULIST; + +char *msg_cancel = MSG_CANCEL; +char *msg_usr_left = MSG_USR_LEFT; +char *msg_nobody = MSG_NOBODY; + +char *msg_sure_ny = MSG_SURE_NY; +char *msg_sure_yn = MSG_SURE_YN; + +char *msg_bid = MSG_BID; +char *msg_uid = MSG_UID; + +char *msg_del_ok = MSG_DEL_OK; +char *msg_del_ny = MSG_DEL_NY; + +char *msg_fwd_ok = MSG_FWD_OK; +char *msg_fwd_err1 = MSG_FWD_ERR1; +char *msg_fwd_err2 = MSG_FWD_ERR2; + +char *err_board_update = ERR_BOARD_UPDATE; +char *err_bid = ERR_BID; +char *err_uid = ERR_UID; +char *err_filename = ERR_FILENAME; + +char *str_mail_address = "." BBSUSER "@" MYHOSTNAME; +char *str_new = "new"; +char *str_reply = "Re: "; +char *str_space = " \t\n\r"; +char *str_sysop = "SYSOP"; +char *str_author1 = STR_AUTHOR1; +char *str_author2 = STR_AUTHOR2; +char *str_post1 = STR_POST1; +char *str_post2 = STR_POST2; +char *BBSName = BBSNAME; /* #define MAX_MODES 78 */ /* MAX_MODES is defined in common.h */ -char *ModeTypeTable[MAX_MODES] = { - "µo§b", /* IDLE */ - "¥D¿ï³æ", /* MMENU */ - "¨t²ÎºûÅ@", /* ADMIN */ - "¶l¥ó¿ï³æ", /* MAIL */ - "¥æ½Í¿ï³æ", /* TMENU */ - "¨Ï¥ÎªÌ¿ï³æ", /* UMENU */ - "XYZ ¿ï³æ", /* XMENU */ - "¤ÀÃþ¬ÝªO", /* CLASS */ - "Play¿ï³æ", /* PMENU */ - "½s¯S§O¦W³æ", /* NMENU */ - "¢Þtt¶q³c©±", /* PSALE */ - "µoªí¤å³¹", /* POSTING */ - "¬ÝªO¦Cªí", /* READBRD */ - "¾\\Ū¤å³¹", /* READING */ - "·s¤å³¹¦Cªí", /* READNEW */ - "¿ï¾Ü¬ÝªO", /* SELECT */ - "Ū«H", /* RMAIL */ - "¼g«H", /* SMAIL */ - "²á¤Ñ«Ç", /* CHATING */ - "¨ä¥L", /* XMODE */ - "´M§ä¦n¤Í", /* FRIEND */ - "¤W½u¨Ï¥ÎªÌ", /* LAUSERS */ - "¨Ï¥ÎªÌ¦W³æ", /* LUSERS */ - "°lÂܯ¸¤Í", /* MONITOR */ - "©I¥s", /* PAGE */ - "¬d¸ß", /* TQUERY */ - "¥æ½Í", /* TALK */ - "½s¦W¤ùÀÉ", /* EDITPLAN */ - "½sñ¦WÀÉ", /* EDITSIG */ - "§ë²¼¤¤", /* VOTING */ - "³]©w¸ê®Æ", /* XINFO */ - "±Hµ¹¯¸ªø", /* MSYSOP */ - "¨L¨L¨L", /* WWW */ - "¥´¤j¦Ñ¤G", /* BIG2 */ - "¦^À³", /* REPLY */ - "³Q¤ô²y¥´¤¤", /* HIT */ - "¤ô²y·Ç³Æ¤¤", /* DBACK */ - "µ§°O¥»", /* NOTE */ - "½s¿è¤å³¹", /* EDITING */ - "µo¨t²Î³q§i", /* MAILALL */ - "ºN¨â°é", /* MJ */ - "¹q¸£¾Ü¤Í", /* P_FRIEND */ - "¤W¯¸³~¤¤", /* LOGIN */ - "¬d¦r¨å", /* DICT */ - "¥´¾ôµP", /* BRIDGE */ - "§äÀÉ®×", /* ARCHIE */ - "¥´¦a¹«", /* GOPHER */ - "¬ÝNews", /* NEWS */ - "±¡®Ñ²£¥Í¾¹", /* LOVE */ - "½sÄy»²§U¾¹", /* EDITEXP */ - "¥Ó½ÐIP¦ì§}", /* IPREG */ - "ºôºÞ¿ì¤½¤¤", /* NetAdm */ - "µêÀÀ¹ê·~§{", /* DRINK */ - "pºâ¾÷", /* CAL */ - "½sÄy®y¥k»Ê", /* PROVERB */ - "¤½§GÄæ", /* ANNOUNCE */ - "¨è¬y¨¥ªO", /* EDNOTE */ - "^º~½Ķ¾÷", /* CDICT */ - "À˵ø¦Û¤vª««~", /* LOBJ */ - "ÂIºq", /* OSONG */ - "¥¿¦bª±¤pÂû", /* CHICKEN */ - "ª±±m¨é", /* TICKET */ - "²q¼Æ¦r", /* GUESSNUM */ - "¹C¼Ö³õ", /* AMUSE */ - "¶Â¥Õ´Ñ", /* OTHELLO */ - "ª±»ë¤l", /* DICE*/ - "µo²¼¹ï¼ú", /* VICE */ - "¹G¹Gáàing", /* BBCALL */ - "ú»@³æ", /* CROSSPOST */ - "¤¤l´Ñ", /* M_FIVE */ - "21ÂIing", /* JACK_CARD */ - "10ÂI¥bing", /* TENHALF */ - "¶W¯Å¤E¤Q¤E", /* CARD_99 */ - "¤õ¨®¬d¸ß", /* RAIL_WAY */ - "·j´M¿ï³æ", /* SREG */ - "¤U¶H´Ñ", /* CHC */ - "¤U·tµX", /* DARK */ - "NBA¤j²q´ú" /* TMPJACK */ - "¢Þtt¬dº]¨t²Î", /* JCEE */ - "«½s¤å³¹" /* REEDIT */ +char *ModeTypeTable[MAX_MODES] = { + "µo§b", /* IDLE */ + "¥D¿ï³æ", /* MMENU */ + "¨t²ÎºûÅ@", /* ADMIN */ + "¶l¥ó¿ï³æ", /* MAIL */ + "¥æ½Í¿ï³æ", /* TMENU */ + "¨Ï¥ÎªÌ¿ï³æ", /* UMENU */ + "XYZ ¿ï³æ", /* XMENU */ + "¤ÀÃþ¬ÝªO", /* CLASS */ + "Play¿ï³æ", /* PMENU */ + "½s¯S§O¦W³æ", /* NMENU */ + "¢Þtt¶q³c©±", /* PSALE */ + "µoªí¤å³¹", /* POSTING */ + "¬ÝªO¦Cªí", /* READBRD */ + "¾\\Ū¤å³¹", /* READING */ + "·s¤å³¹¦Cªí", /* READNEW */ + "¿ï¾Ü¬ÝªO", /* SELECT */ + "Ū«H", /* RMAIL */ + "¼g«H", /* SMAIL */ + "²á¤Ñ«Ç", /* CHATING */ + "¨ä¥L", /* XMODE */ + "´M§ä¦n¤Í", /* FRIEND */ + "¤W½u¨Ï¥ÎªÌ", /* LAUSERS */ + "¨Ï¥ÎªÌ¦W³æ", /* LUSERS */ + "°lÂܯ¸¤Í", /* MONITOR */ + "©I¥s", /* PAGE */ + "¬d¸ß", /* TQUERY */ + "¥æ½Í", /* TALK */ + "½s¦W¤ùÀÉ", /* EDITPLAN */ + "½sñ¦WÀÉ", /* EDITSIG */ + "§ë²¼¤¤", /* VOTING */ + "³]©w¸ê®Æ", /* XINFO */ + "±Hµ¹¯¸ªø", /* MSYSOP */ + "¨L¨L¨L", /* WWW */ + "¥´¤j¦Ñ¤G", /* BIG2 */ + "¦^À³", /* REPLY */ + "³Q¤ô²y¥´¤¤", /* HIT */ + "¤ô²y·Ç³Æ¤¤", /* DBACK */ + "µ§°O¥»", /* NOTE */ + "½s¿è¤å³¹", /* EDITING */ + "µo¨t²Î³q§i", /* MAILALL */ + "ºN¨â°é", /* MJ */ + "¹q¸£¾Ü¤Í", /* P_FRIEND */ + "¤W¯¸³~¤¤", /* LOGIN */ + "¬d¦r¨å", /* DICT */ + "¥´¾ôµP", /* BRIDGE */ + "§äÀÉ®×", /* ARCHIE */ + "¥´¦a¹«", /* GOPHER */ + "¬ÝNews", /* NEWS */ + "±¡®Ñ²£¥Í¾¹", /* LOVE */ + "½sÄy»²§U¾¹", /* EDITEXP */ + "¥Ó½ÐIP¦ì§}", /* IPREG */ + "ºôºÞ¿ì¤½¤¤", /* NetAdm */ + "µêÀÀ¹ê·~§{", /* DRINK */ + "pºâ¾÷", /* CAL */ + "½sÄy®y¥k»Ê", /* PROVERB */ + "¤½§GÄæ", /* ANNOUNCE */ + "¨è¬y¨¥ªO", /* EDNOTE */ + "^º~½Ķ¾÷", /* CDICT */ + "À˵ø¦Û¤vª««~", /* LOBJ */ + "ÂIºq", /* OSONG */ + "¥¿¦bª±¤pÂû", /* CHICKEN */ + "ª±±m¨é", /* TICKET */ + "²q¼Æ¦r", /* GUESSNUM */ + "¹C¼Ö³õ", /* AMUSE */ + "¶Â¥Õ´Ñ", /* OTHELLO */ + "ª±»ë¤l", /* DICE */ + "µo²¼¹ï¼ú", /* VICE */ + "¹G¹Gáàing", /* BBCALL */ + "ú»@³æ", /* CROSSPOST */ + "¤¤l´Ñ", /* M_FIVE */ + "21ÂIing", /* JACK_CARD */ + "10ÂI¥bing", /* TENHALF */ + "¶W¯Å¤E¤Q¤E", /* CARD_99 */ + "¤õ¨®¬d¸ß", /* RAIL_WAY */ + "·j´M¿ï³æ", /* SREG */ + "¤U¶H´Ñ", /* CHC */ + "¤U·tµX", /* DARK */ + "NBA¤j²q´ú" /* TMPJACK */ + "¢Þtt¬dº]¨t²Î", /* JCEE */ + "«½s¤å³¹" /* REEDIT */ }; /* indict.c */ -char dict[41], database[41]; +char dict[41], database[41]; /* term.c */ -int b_lines = 23; -int t_lines = 24; -int p_lines = 20; -int t_columns = 80; -char *strtstandout = "\33[7m"; -int strtstandoutlen = 4; -char *endstandout = "\33[m"; -int endstandoutlen = 3; -char *clearbuf = "\33[H\33[J"; -int clearbuflen = 6; -char *cleolbuf = "\33[K"; -int cleolbuflen = 3; -char *scrollrev = "\33M"; -int scrollrevlen = 2; -int automargins = 1; +int b_lines = 23; +int t_lines = 24; +int p_lines = 20; +int t_columns = 80; +char *strtstandout = "\33[7m"; +int strtstandoutlen = 4; +char *endstandout = "\33[m"; +int endstandoutlen = 3; +char *clearbuf = "\33[H\33[J"; +int clearbuflen = 6; +char *cleolbuf = "\33[K"; +int cleolbuflen = 3; +char *scrollrev = "\33M"; +int scrollrevlen = 2; +int automargins = 1; /* io.c */ -time_t now; -int KEY_ESC_arg; -int watermode = -1; -int wmofo = -1; +time_t now; +int KEY_ESC_arg; +int watermode = -1; +int wmofo = -1; /* - WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): - Ptt ¤ô²y¦^ÅU¥Îªº°Ñ¼Æ - watermode = -1 ¨S¦b¦^¤ô²y - = 0 ¦b¦^¤W¤@Áû¤ô²y (Ctrl-R) - > 0 ¦b¦^«e n Áû¤ô²y (Ctrl-R Ctrl-R) - - WATERMODE(WATER_OFO) by in2 - wmofo = -1 ¨S¦b¦^¤ô²y - = 0 ¥¿¦b¦^¤ô²y - = 1 ¦^¤ô²y¶¡¤S±µ¨ì¤ô²y - wmofo >=0 ®É¦¬¨ì¤ô²y±N¥uÅã¥Ü, ¤£·|¨ìwater[]¸Ì, - «Ý¦^§¹¤ô²yªº®ÉÔ¤@¦¸¼g¤J. -*/ + * WATERMODE(WATER_ORIG) | WATERMODE(WATER_NEW): Ptt ¤ô²y¦^ÅU + * e = -1 ¨S¦b¦^¤ô²y = 0 ¦b¦^¤W¤@Áû¤ô²y (Ctrl-R) > 0 ¦b¦^«e n Áû¤ô²y + * (Ctrl-R Ctrl-R) + * + * WATERMODE(WATER_OFO) by in2 wmofo = -1 ¨S¦b¦^¤ô²y = 0 ¥¿¦b¦^¤ô²y = 1 + * ¦^¤ô²y¶¡¤S±µ¨ì¤ô²y wmofo >=0 ®É¦¬¨ì¤ô²y±N¥uÅã¥Ü, ¤£·|¨ìwater[]¸Ì, + * «Ý¦^§¹¤ô²yªº®ÉÔ¤@¦¸¼g¤J. + */ /* cache.c */ -int numboards = -1; -int *GLOBALVAR; -SHM_t *SHM; -boardheader_t *bcache; -userinfo_t *currutmp; +int numboards = -1; +int *GLOBALVAR; +SHM_t *SHM; +boardheader_t *bcache; +userinfo_t *currutmp; /* board.c */ -int class_bid = 0; -int brc_num; -int brc_list[BRC_MAXNUM]; +int class_bid = 0; +int brc_num; +int brc_list[BRC_MAXNUM]; /* read.c */ -int TagNum; /* tag's number */ -TagItem TagList[MAXTAGS]; /* ascending list */ -char currdirect[64]; +int TagNum; /* tag's number */ +TagItem TagList[MAXTAGS]; /* ascending list */ +char currdirect[64]; /* edit.c */ -char save_title[STRLEN]; +char save_title[STRLEN]; /* bbs.c */ -time_t board_visit_time; -char real_name[IDLEN + 1]; -int local_article; +time_t board_visit_time; +char real_name[IDLEN + 1]; +int local_article; /* mbbsd.c */ -int talkrequest = NA; -char fromhost[STRLEN] = "\0"; -char water_usies = 0; -FILE *fp_writelog = NULL; -water_t water[6], *swater[6], *water_which = &water[0]; +int talkrequest = NA; +char fromhost[STRLEN] = "\0"; +char water_usies = 0; +FILE *fp_writelog = NULL; +water_t water[6], *swater[6], *water_which = &water[0]; /* announce.c */ -char trans_buffer[256]; +char trans_buffer[256]; /* chc_play.c */ -rc_t chc_from, chc_to, chc_select, chc_cursor; -int chc_lefttime; -int chc_my, chc_turn, chc_selected, chc_firststep; -char chc_warnmsg[64], *chc_mateid; -int chc_hiswin, chc_hislose, chc_histie; +rc_t chc_from, chc_to, chc_select, chc_cursor; +int chc_lefttime; +int chc_my, chc_turn, chc_selected, chc_firststep; +char chc_warnmsg[64], *chc_mateid; +int chc_hiswin, chc_hislose, chc_histie; /* screen.c */ -screenline_t *big_picture = NULL; +screenline_t *big_picture = NULL; unsigned char scr_lns, scr_cols; /* gomo.c */ -char ku[BRDSIZ][BRDSIZ]; -unsigned char *pat, *adv; -unsigned char *pat_gomoku /* [1954] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" -/* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" -/* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" -/* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" -/* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" -/* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" -/* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" -/* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" -/* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" -/* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" -/* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" -/* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" -/* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" -/* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" -/* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" -/* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" -/* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" -/* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" -/* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" -/* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" -/* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" -/* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" -/* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" -/* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" -/* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" -/* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" -/* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" -/* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" -/* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" -/* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" -/* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" -/* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" -/* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" -/* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" -/* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" -/* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" -/* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" -/* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" -/* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" -/* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" -/* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" -/* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" -/* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" -/* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" -/* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" -/* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" -/* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" -/* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" -/* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" -/* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" -/* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" -/* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" -/* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" -/* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" -/* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" -/* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" -/* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" -/* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" -/* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" -/* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" -/* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" -/* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" -/* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" -/* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" -/* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" -/* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" -/* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" -/* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" -/* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" -/* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" -/* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" -/* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" -/* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" -/* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" -/* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" -/* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" -/* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" -/* 1952 */ "\x0a"; - -unsigned char *adv_gomoku /* [978] */ = -/* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" -/* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" -/* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" -/* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" -/* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" -/* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" -/* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" -/* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" -/* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" -/* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" -/* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" -/* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" -/* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" -/* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" -/* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" -/* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" -/* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" -/* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" -/* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" -/* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" -/* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" -/* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" -/* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" -/* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" -/* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" -/* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" -/* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" -/* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" -/* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" -/* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" -/* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" -/* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" -/* 976 */ "\x00"; +char ku[BRDSIZ][BRDSIZ]; +unsigned char *pat, *adv; +unsigned char *pat_gomoku /* [1954] */ = + /* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 16 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x55\xcc\x00\x00\x00\x00" + /* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x44\x00\x33\x00\x00\x00" + /* 48 */ "\x00\x22\x00\x55\x00\x22\x00\x00\x00\x44\x33\x66\x55\xcc\x33\x66" + /* 64 */ "\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" + /* 80 */ "\x55\x00\x55\x00\x05\x00\x55\x02\x46\x00\xaa\x00\x00\x55\x00\x55" + /* 96 */ "\x00\x05\x00\x55\x00\x05\x00\x55\x00\x00\x44\xcc\x44\xcc\x05\xbb" + /* 112 */ "\x44\xcc\x05\xbb\x44\xcc\x05\xbb\x00\x00\x00\x00\x00\x00\x00\x00" + /* 128 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x00\x00\x33\x00\x44\x00" + /* 144 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x00\x00\x00\x00\x22\x00\x55" + /* 160 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x00\x33\x44\x33\x66" + /* 176 */ "\x55\xcc\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" + /* 192 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" + /* 208 */ "\x33\x00\x00\x22\x55\x22\x55\x02\x05\x22\x55\x02\x46\x22\xaa\x55" + /* 224 */ "\xcc\x22\x55\x02\x46\x22\xaa\x00\x22\x55\x22\x55\x02\x05\x22\x55" + /* 240 */ "\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x44\x66\xcc" + /* 256 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 272 */ "\x66\xcc\x46\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" + /* 288 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x00\x00" + /* 304 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" + /* 320 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" + /* 336 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\x55" + /* 352 */ "\x55\x05\x55\x46\xaa\xcc\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 368 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x00\x00\x00\x00\x00\x00" + /* 384 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" + /* 400 */ "\x66\x00\x00\x00\x55\x00\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55" + /* 416 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" + /* 432 */ "\x06\x55\x0a\x55\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" + /* 448 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x05\x55\x5a\x55\x5a" + /* 464 */ "\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 480 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00" + /* 512 */ "\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00" + /* 528 */ "\x00\x00\x00\x00\x33\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 544 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x02\x46\x00\x05\x05\xbb\x00" + /* 560 */ "\x33\x00\x00\x00\x00\x22\x00\x55\x00\x22\x00\x55\x00\x02\x00\x05" + /* 576 */ "\x00\x22\x00\x55\x00\x02\x02\x46\x00\x22\x00\xaa\x00\x55\x55\xcc" + /* 592 */ "\x00\x22\x00\x00\x33\x44\x33\x66\x55\xcc\x33\x66\x55\xcc\x33\x46" + /* 608 */ "\x05\xbb\x33\x66\x55\xcc\x33\x46\x05\xbb\x33\x66\x55\xcc\x33\x46" + /* 624 */ "\x05\xbb\x33\x66\x55\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 640 */ "\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00" + /* 656 */ "\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x00\x22\x55\x22\x55\x02" + /* 672 */ "\x05\x22\x55\x02\x46\x22\xaa\x55\xcc\x22\x55\x02\x46\x22\xaa\x55" + /* 688 */ "\xcc\x22\x55\x02\x06\x22\x5a\x05\xbb\x22\x55\x02\x46\x22\xaa\x00" + /* 704 */ "\x22\x55\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55\x02\x05\x22\x55" + /* 720 */ "\x02\x05\x22\x55\x02\x46\x22\x55\x02\x5a\x22\xaa\x55\xcc\x22\x55" + /* 736 */ "\x02\x05\x22\x55\x02\x44\x66\xcc\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 752 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb" + /* 768 */ "\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x66\xcc\x46\xbb\x00\x00\x00\x00" + /* 784 */ "\x00\x00\x00\x00\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00" + /* 800 */ "\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00" + /* 816 */ "\x22\x22\x66\x00\x00\x00\x00\x00\x03\x00\x44\x00\x33\x22\x66\x00" + /* 832 */ "\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x02\x46\x00" + /* 848 */ "\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x03\x00\x00\x00" + /* 864 */ "\x00\x02\x00\x55\x00\x02\x00\x55\x00\x02\x00\x05\x00\x02\x00\x55" + /* 880 */ "\x00\x02\x02\x46\x00\x02\x00\xaa\x00\x55\x55\xcc\x00\x02\x00\x55" + /* 896 */ "\x00\x02\x02\x46\x00\x02\x00\x55\x55\x05\x55\x46\xaa\xcc\x55\x46" + /* 912 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 928 */ "\xaa\xcc\x55\x06\x5a\xbb\x55\x46\xaa\xcc\x55\x06\x5a\xbb\x55\x46" + /* 944 */ "\xaa\xcc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00" + /* 960 */ "\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" + /* 976 */ "\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55" + /* 992 */ "\x05\x55\x05\x55\x05\x55\x05\x55\x46\x55\x5a\xaa\xcc\x55\x05\x55" + /* 1008 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x5a\xbb\x55\x05\x55" + /* 1024 */ "\x46\x55\x5a\xaa\xcc\x55\x05\x55\x06\x55\x0a\x55\x55\x05\x55\x05" + /* 1040 */ "\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05\x55\x05" + /* 1056 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\x55\x05\x55\x05\x55\x05" + /* 1072 */ "\x55\x46\x55\x05\x55\x5a\x55\x5a\xaa\xcc\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1088 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1104 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb" + /* 1120 */ "\xcc\xbb\xcc\xbb\xcc\xbb\xcc\xbb\x00\x00\x00\x00\x00\x00\x00\x00" + /* 1136 */ "\x00\x00\x33\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00" + /* 1152 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00" + /* 1168 */ "\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x00\x00\x33\x00\x44\x00" + /* 1184 */ "\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 1200 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00\x55\x55\xcc\x00" + /* 1216 */ "\x33\x02\x46\x00\x05\x05\xbb\x00\x33\x00\x00\x00\x00\x22\x00\x55" + /* 1232 */ "\x00\x22\x00\x55\x00\x02\x00\x05\x00\x22\x00\x55\x00\x02\x02\x46" + /* 1248 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x55\x00\x02\x02\x46" + /* 1264 */ "\x00\x22\x00\xaa\x00\x55\x55\xcc\x00\x22\x00\x00\x03\x44\x33\x66" + /* 1280 */ "\x55\xcc\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" + /* 1296 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x03\x46" + /* 1312 */ "\x05\xbb\x33\x66\x55\xcc\x03\x46\x05\xbb\x33\x66\x55\xcc\x00\x00" + /* 1328 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00" + /* 1344 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" + /* 1360 */ "\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00" + /* 1376 */ "\x03\x00\x00\x02\x55\x02\x55\x02\x05\x02\x55\x02\x46\x02\xaa\x55" + /* 1392 */ "\xcc\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" + /* 1408 */ "\xbb\x02\x55\x02\x46\x02\xaa\x55\xcc\x02\x55\x02\x06\x02\x5a\x05" + /* 1424 */ "\xbb\x02\x55\x02\x46\x02\xaa\x00\x02\x55\x02\x55\x02\x05\x02\x55" + /* 1440 */ "\x02\x05\x02\x55\x02\x05\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" + /* 1456 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x46\x02\x55" + /* 1472 */ "\x02\x5a\x02\xaa\x55\xcc\x02\x55\x02\x05\x02\x55\x02\x05\x46\xcc" + /* 1488 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1504 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1520 */ "\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb\x46\xcc\x06\xbb" + /* 1536 */ "\x46\xcc\x06\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x33\x00" + /* 1552 */ "\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" + /* 1568 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22\x66\x00\x00\x00\x55\x00" + /* 1584 */ "\x55\x55\xcc\x00\x00\x00\x33\x00\x02\x02\x46\x00\x00\x00\x00\x00" + /* 1600 */ "\x03\x00\x44\x00\x33\x22\x66\x00\x55\x55\xcc\x00\x33\x22\x66\x00" + /* 1616 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" + /* 1632 */ "\x55\x55\xcc\x00\x03\x02\x46\x00\x05\x05\xbb\x00\x33\x22\x66\x00" + /* 1648 */ "\x55\x55\xcc\x00\x03\x00\x00\x00\x00\x02\x00\x55\x00\x02\x00\x55" + /* 1664 */ "\x00\x02\x00\x05\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" + /* 1680 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x46\x00\x02\x00\xaa" + /* 1696 */ "\x00\x55\x55\xcc\x00\x02\x00\x55\x00\x02\x02\x06\x00\x02\x00\x05" + /* 1712 */ "\x05\x05\x05\x46\x5a\xcc\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1728 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1744 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x05\x06\x0a\xbb\x05\x46" + /* 1760 */ "\x5a\xcc\x05\x06\x0a\xbb\x05\x46\x5a\xcc\x00\x00\x00\x00\x00\x00" + /* 1776 */ "\x00\x00\x00\x00\x03\x00\x00\x00\x44\x00\x00\x00\x33\x00\x22\x22" + /* 1792 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x33\x00\x22\x22" + /* 1808 */ "\x66\x00\x00\x00\x55\x00\x55\x55\xcc\x00\x00\x00\x03\x00\x02\x02" + /* 1824 */ "\x46\x00\x00\x00\x05\x00\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" + /* 1840 */ "\x46\x05\x5a\x5a\xcc\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1856 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1872 */ "\x06\x05\x0a\x0a\xbb\x05\x05\x05\x46\x05\x5a\x5a\xcc\x05\x05\x05" + /* 1888 */ "\x06\x05\x0a\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05\x05" + /* 1904 */ "\x05\x05\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" + /* 1920 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x46\x05\x05\x05\x5a\x05\x5a" + /* 1936 */ "\x5a\xcc\x05\x05\x05\x05\x05\x05\x05\x06\x05\x05\x05\x0a\x05\x0a" + /* 1952 */ "\x0a"; + +unsigned char *adv_gomoku /* [978] */ = + /* 0 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 16 */ "\x00\x00\x00\x00\xa0\x00\xa0\x00\x04\x00\x04\x00\x00\xd0\x00\xd0" + /* 32 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 48 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 64 */ "\x00\x70\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00\xa0\x00\x04\x00" + /* 80 */ "\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00" + /* 96 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00\x08\x00\x08\x00" + /* 112 */ "\x08\x00\x08\x00\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x00" + /* 128 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" + /* 144 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00\x00\x00\xa1\x00" + /* 160 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 176 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 192 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" + /* 208 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 224 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 240 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00" + /* 256 */ "\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00\xa1\x00\x00\x00" + /* 272 */ "\xa1\x00\x00\x00\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00" + /* 288 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\xd0\xd0\x00\xd0\x00\xd0" + /* 304 */ "\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\xd0\x00\x00\x00\x00\x00\x00" + /* 320 */ "\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x08\x08\x00" + /* 336 */ "\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00" + /* 352 */ "\x40\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40\x00\x40" + /* 368 */ "\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 384 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70" + /* 400 */ "\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\xa1\x00" + /* 416 */ "\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00" + /* 432 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 448 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 464 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 480 */ "\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00" + /* 496 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 512 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 528 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 544 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 560 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00" + /* 576 */ "\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\xa0\x00" + /* 592 */ "\xa1\x00\x00\x00\xa1\x00\x00\x00\xa0\x00\x00\x00\xa1\x00\x00\x00" + /* 608 */ "\xa0\x00\x00\x00\xa0\x00\x04\x00\x04\x00\x00\x00\x04\x00\x00\x00" + /* 624 */ "\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\x00\x04\x00\x00\xd0" + /* 640 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\xd0\x00\x00" + /* 656 */ "\x00\xd0\x00\x00\x00\xd0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 672 */ "\x70\x21\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00" + /* 688 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 704 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 720 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 736 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 752 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 768 */ "\x00\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x70\x21\x00\x00\x00" + /* 784 */ "\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x70\x00\x00\x00\x00" + /* 800 */ "\x00\x00\xa1\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\xa1\x00" + /* 816 */ "\x00\x00\x00\x00\x00\x00\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 832 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 848 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 864 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 880 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x21" + /* 896 */ "\x00\x00\x00\x00\x00\x00\x70\x21\x00\x00\x00\x00\x00\x00\x00\x00" + /* 912 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 928 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 944 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 960 */ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + /* 976 */ "\x00"; /* name.c */ -word_t *toplev; +word_t *toplev; /* menu.c */ commands_t cmdlist[] = { - {admin,PERM_SYSOP|PERM_VIEWSYSOP, "00Admin ¡i ¨t²ÎºûÅ@°Ï ¡j"}, - {Announce, 0, "AAnnounce ¡i ºëµØ¤½§GÄæ ¡j"}, - {Boards, 0, "FFavorite ¡i §Ú ªº ³Ì·R ¡j"}, - {root_board, 0, "CClass ¡i ¤À²Õ°Q½×°Ï ¡j"}, - {Mail, PERM_BASIC, "MMail ¡i ¨p¤H«H¥ó°Ï ¡j"}, - {Talk, 0, "TTalk ¡i ¥ð¶¢²á¤Ñ°Ï ¡j"}, - {User, 0, "UUser ¡i Ó¤H³]©w°Ï ¡j"}, - {Xyz, 0, "XXyz ¡i ¨t²Î¤u¨ã°Ï ¡j"}, - {Play_Play,0, "PPlay ¡i ¹C¼Ö³õ/¤j¾Ç¬dº]¡j"}, - {Name_Menu,PERM_LOGINOK, "NNamelist ¡i ½s¯S§O¦W³æ ¡j"}, - {Goodbye, 0, "GGoodbye Â÷¶}¡A¦A¨£¡K¡K"}, + {admin, PERM_SYSOP | PERM_VIEWSYSOP, "00Admin ¡i ¨t²ÎºûÅ@°Ï ¡j"}, + {Announce, 0, "AAnnounce ¡i ºëµØ¤½§GÄæ ¡j"}, + {Boards, 0, "FFavorite ¡i §Ú ªº ³Ì·R ¡j"}, + {root_board, 0, "CClass ¡i ¤À²Õ°Q½×°Ï ¡j"}, + {Mail, PERM_BASIC, "MMail ¡i ¨p¤H«H¥ó°Ï ¡j"}, + {Talk, 0, "TTalk ¡i ¥ð¶¢²á¤Ñ°Ï ¡j"}, + {User, 0, "UUser ¡i Ó¤H³]©w°Ï ¡j"}, + {Xyz, 0, "XXyz ¡i ¨t²Î¤u¨ã°Ï ¡j"}, + {Play_Play, 0, "PPlay ¡i ¹C¼Ö³õ/¤j¾Ç¬dº]¡j"}, + {Name_Menu, PERM_LOGINOK, "NNamelist ¡i ½s¯S§O¦W³æ ¡j"}, + {Goodbye, 0, "GGoodbye Â÷¶}¡A¦A¨£¡K¡K"}, {NULL, 0, NULL} }; /* friend.c */ /* Ptt ¦UºØ¯S§O¦W³æªºÀɦW */ -char *friend_file[8] = { +char *friend_file[8] = { FN_OVERRIDES, FN_REJECT, "alohaed", diff --git a/mbbsd/vice.c b/mbbsd/vice.c index 8b8abe0f..d52f12ad 100644 --- a/mbbsd/vice.c +++ b/mbbsd/vice.c @@ -1,4 +1,4 @@ -/* $Id: vice.c,v 1.3 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: vice.c,v 1.4 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define VICE_PLAY BBSHOME "/etc/vice/vice.play" @@ -14,122 +14,133 @@ #define MAX_LOST_PICTURE 3 #define MAX_END_PICTURE 5 -static int vice_load(char tbingo[6][15]) { - FILE *fb = fopen(VICE_BINGO, "r"); - char buf[16], *ptr; - int i = 0; - if(!fb) return -1; bzero((char*)tbingo, sizeof(tbingo)); - while(i < 6 && fgets(buf, 15, fb)) { - if((ptr = strchr(buf, '\n'))) - *ptr = 0; - strcpy(tbingo[i++], buf); +static int +vice_load(char tbingo[6][15]) +{ + FILE *fb = fopen(VICE_BINGO, "r"); + char buf[16], *ptr; + int i = 0; + if (!fb) + return -1; + bzero((char *)tbingo, sizeof(tbingo)); + while (i < 6 && fgets(buf, 15, fb)) { + if ((ptr = strchr(buf, '\n'))) + *ptr = 0; + strcpy(tbingo[i++], buf); } fclose(fb); return 0; } -static int check(char tbingo[6][15], char *data) { - int i = 0, j; +static int +check(char tbingo[6][15], char *data) +{ + int i = 0, j; - if(!strcmp(data, tbingo[0])) - return 8; + if (!strcmp(data, tbingo[0])) + return 8; - for(j = 8; j > 0; j--) - for(i = 1; i < 6; i++) - if(!strncmp(data+8-j, tbingo[i]+8-j,j)) - return j - 1; + for (j = 8; j > 0; j--) + for (i = 1; i < 6; i++) + if (!strncmp(data + 8 - j, tbingo[i] + 8 - j, j)) + return j - 1; return 0; } -// Ptt: showfile ran_showfile more ¤TªÌn¾ã¦X -static int ran_showfile(int y, int x, char *filename, int maxnum) { - FILE *fs; - char buf[512]; +//Ptt:showfile ran_showfile more ¤ T ª Ìn ¾ ã¦X +static int +ran_showfile(int y, int x, char *filename, int maxnum) +{ + FILE *fs; + char buf[512]; bzero(buf, sizeof(char) * 512); sprintf(buf, "%s%d", filename, rand() % maxnum + 1); - if(!(fs = fopen(buf, "r"))) { - move(10,10); - prints("can't open file: %s", buf); - return 0; + if (!(fs = fopen(buf, "r"))) { + move(10, 10); + prints("can't open file: %s", buf); + return 0; } - move(y, x); - while(fgets(buf, 511, fs)) - prints("%s", buf); + while (fgets(buf, 511, fs)) + prints("%s", buf); fclose(fs); return 1; } -static int ran_showmfile(char *filename, int maxnum) { - char buf[256]; +static int +ran_showmfile(char *filename, int maxnum) +{ + char buf[256]; sprintf(buf, "%s%d", filename, rand() % maxnum + 1); return more(buf, YEA); } -int vice_main() { - FILE *fd; - char tbingo[6][15]; - char buf_data[256] - , serial[16], ch[2], *ptr; - int TABLE[] = {0,10,200,1000,4000,10000,40000,100000,200000}; - int total = 0, money, i = 4, j = 0; +int +vice_main() +{ + FILE *fd; + char tbingo[6][15]; + char buf_data[256] + ,serial[16], ch[2], *ptr; + int TABLE[] = {0, 10, 200, 1000, 4000, 10000, 40000, 100000, 200000}; + int total = 0, money, i = 4, j = 0; setuserfile(buf_data, VICE_DATA); - if(!dashf(buf_data)) { - ran_showmfile(VICE_NO, MAX_NO_PICTURE); - return 0; + if (!dashf(buf_data)) { + ran_showmfile(VICE_NO, MAX_NO_PICTURE); + return 0; } - if(vice_load(tbingo)<0) return -1; + if (vice_load(tbingo) < 0) + return -1; clear(); ran_showfile(0, 0, VICE_PLAY, 1); ran_showfile(10, 0, VICE_SHOW, 1); - if(!(fd = fopen(buf_data, "r"))) - return 0; + if (!(fd = fopen(buf_data, "r"))) + return 0; j = 0; i = 0; - move(10,24); + move(10, 24); clrtoeol(); prints("³o¤@´Áªºµo²¼¸¹½X"); - while(fgets(serial, 15, fd)) { - if((ptr = strchr(serial,'\r'))) - *ptr = 0; - if(j == 0) - i++; - move(10 + i, 24 + j); - prints("%s", serial); - j += 9; - j %= 45; + while (fgets(serial, 15, fd)) { + if ((ptr = strchr(serial, '\r'))) + *ptr = 0; + if (j == 0) + i++; + move(10 + i, 24 + j); + prints("%s", serial); + j += 9; + j %= 45; } getdata(8, 0, "«ö'c'¶}©l¹ï¼ú¤F(©Î¬O¥ô·NÁäÂ÷¶})): ", ch, sizeof(ch), LCECHO); - if(ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)){ - fclose(fd); - return 0; - } - + if (ch[0] != 'c' || lockutmpmode(VICE, LOCK_MULTI)) { + fclose(fd); + return 0; + } showtitle("µo²¼¹ï¼ú", BBSNAME); rewind(fd); - while(fgets(serial, 15, fd)) { - if((ptr = strchr(serial,'\n'))) - *ptr = 0; - money = TABLE[check(tbingo,serial)]; - total += money; - prints("%s ¤¤¤F %d\n", serial, money); + while (fgets(serial, 15, fd)) { + if ((ptr = strchr(serial, '\n'))) + *ptr = 0; + money = TABLE[check(tbingo, serial)]; + total += money; + prints("%s ¤¤¤F %d\n", serial, money); } pressanykey(); - if(total > 0) { - ran_showmfile(VICE_WIN, MAX_WIN_PICTURE); - move(22,0); - clrtoeol(); - prints("¥þ³¡ªºµo²¼¤¤¤F %d ¶ô¿ú\n", total); - demoney(total); + if (total > 0) { + ran_showmfile(VICE_WIN, MAX_WIN_PICTURE); + move(22, 0); + clrtoeol(); + prints("¥þ³¡ªºµo²¼¤¤¤F %d ¶ô¿ú\n", total); + demoney(total); } else - ran_showmfile(VICE_LOST, MAX_LOST_PICTURE); + ran_showmfile(VICE_LOST, MAX_LOST_PICTURE); fclose(fd); unlink(buf_data); diff --git a/mbbsd/vote.c b/mbbsd/vote.c index 914ac24a..e54bc7a2 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -1,79 +1,85 @@ -/* $Id: vote.c,v 1.9 2002/06/04 13:08:34 in2 Exp $ */ +/* $Id: vote.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" -static int total; - -static char STR_bv_control[] = "control"; /* §ë²¼¤é´Á ¿ï¶µ */ -static char STR_bv_desc[] = "desc"; /* §ë²¼¥Øªº */ -static char STR_bv_ballots[] = "ballots"; -static char STR_bv_flags[] = "flags"; -static char STR_bv_comments[] = "comments"; /* §ë²¼ªÌªº«Ø·N */ -static char STR_bv_limited[] = "limited"; /* ¨p¤H§ë²¼ */ -static char STR_bv_title[] = "vtitle"; - -static char STR_bv_results[] = "results"; - -static char STR_new_control[] = "control0\0"; /* §ë²¼¤é´Á ¿ï¶µ */ -static char STR_new_desc[] = "desc0\0"; /* §ë²¼¥Øªº */ -static char STR_new_ballots[] = "ballots0\0"; -static char STR_new_flags[] = "flags0\0"; -static char STR_new_comments[] = "comments0\0"; /* §ë²¼ªÌªº«Ø·N */ -static char STR_new_limited[] = "limited0\0"; /* ¨p¤H§ë²¼ */ -static char STR_new_title[] = "vtitle0\0"; - -int strip_ansi(char *buf, char *str, int mode) { - register int ansi, count = 0; - - for(ansi = 0; *str /*&& *str != '\n' */; str++) { - if(*str == 27) { - if(mode) { - if(buf) +static int total; + +static char STR_bv_control[] = "control"; /* §ë²¼¤é´Á ¿ï¶µ */ +static char STR_bv_desc[] = "desc"; /* §ë²¼¥Øªº */ +static char STR_bv_ballots[] = "ballots"; +static char STR_bv_flags[] = "flags"; +static char STR_bv_comments[] = "comments"; /* §ë²¼ªÌªº«Ø·N */ +static char STR_bv_limited[] = "limited"; /* ¨p¤H§ë²¼ */ +static char STR_bv_title[] = "vtitle"; + +static char STR_bv_results[] = "results"; + +static char STR_new_control[] = "control0\0"; /* §ë²¼¤é´Á ¿ï¶µ */ +static char STR_new_desc[] = "desc0\0"; /* §ë²¼¥Øªº */ +static char STR_new_ballots[] = "ballots0\0"; +static char STR_new_flags[] = "flags0\0"; +static char STR_new_comments[] = "comments0\0"; /* §ë²¼ªÌªº«Ø·N */ +static char STR_new_limited[] = "limited0\0"; /* ¨p¤H§ë²¼ */ +static char STR_new_title[] = "vtitle0\0"; + +int +strip_ansi(char *buf, char *str, int mode) +{ + register int ansi, count = 0; + + for (ansi = 0; *str /* && *str != '\n' */ ; str++) { + if (*str == 27) { + if (mode) { + if (buf) *buf++ = *str; count++; } ansi = 1; - } else if(ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { - if((mode == NO_RELOAD && !strchr("c=n", *str)) || - (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { - if(buf) + } else if (ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) { + if ((mode == NO_RELOAD && !strchr("c=n", *str)) || + (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) { + if (buf) *buf++ = *str; count++; } - if(strchr("mHn ", *str)) + if (strchr("mHn ", *str)) ansi = 0; } else { - ansi =0; - if(buf) + ansi = 0; + if (buf) *buf++ = *str; count++; } } - if(buf) + if (buf) *buf = '\0'; return count; } -void b_suckinfile(FILE *fp, char *fname) { - FILE *sfp; +void +b_suckinfile(FILE * fp, char *fname) +{ + FILE *sfp; - if((sfp = fopen(fname, "r"))) { - char inbuf[256]; + if ((sfp = fopen(fname, "r"))) { + char inbuf[256]; - while(fgets(inbuf, sizeof(inbuf), sfp)) + while (fgets(inbuf, sizeof(inbuf), sfp)) fputs(inbuf, fp); fclose(sfp); } } -static void b_count(char *buf, int counts[]) { - char inchar; - int fd; +static void +b_count(char *buf, int counts[]) +{ + char inchar; + int fd; memset(counts, 0, 31 * sizeof(counts[0])); total = 0; - if((fd = open(buf, O_RDONLY)) != -1) { - flock(fd, LOCK_EX); /* Thor: ¨¾¤î¦h¤H¦P®Éºâ */ - while(read(fd, &inchar, 1) == 1) { + if ((fd = open(buf, O_RDONLY)) != -1) { + flock(fd, LOCK_EX); /* Thor: ¨¾¤î¦h¤H¦P®Éºâ */ + while (read(fd, &inchar, 1) == 1) { counts[(int)(inchar - 'A')]++; total++; } @@ -83,92 +89,97 @@ static void b_count(char *buf, int counts[]) { } -static int b_nonzeroNum(char *buf) { - int i = 0; - char inchar; - int fd; +static int +b_nonzeroNum(char *buf) +{ + int i = 0; + char inchar; + int fd; - if((fd = open(buf, O_RDONLY)) != -1) { - while(read(fd, &inchar, 1) == 1) - if(inchar) + if ((fd = open(buf, O_RDONLY)) != -1) { + while (read(fd, &inchar, 1) == 1) + if (inchar) i++; close(fd); } return i; } -static void vote_report(char *bname, char *fname, char *fpath) { - register char *ip; - time_t dtime; - int fd, bid; - fileheader_t header; +static void +vote_report(char *bname, char *fname, char *fpath) +{ + register char *ip; + time_t dtime; + int fd, bid; + fileheader_t header; ip = fpath; - while(*(++ip)); + while (*(++ip)); *ip++ = '/'; /* get a filename by timestamp */ dtime = now; - for(;;) { + for (;;) { sprintf(ip, "M.%ld.A", ++dtime); fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644); - if(fd >= 0) + if (fd >= 0) break; dtime++; } close(fd); - + unlink(fpath); link(fname, fpath); - + /* append record to .DIR */ - + memset(&header, 0, sizeof(fileheader_t)); strcpy(header.owner, "[°¨¸ô±´¤l]"); sprintf(header.title, "[%s] ¬ÝªO ¿ï±¡³ø¾É", bname); { register struct tm *ptime = localtime(&dtime); - + sprintf(header.date, "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday); } strcpy(header.filename, ip); strcpy(ip, ".DIR"); - if((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { + if ((fd = open(fpath, O_WRONLY | O_CREAT, 0644)) >= 0) { flock(fd, LOCK_EX); lseek(fd, 0, SEEK_END); write(fd, &header, sizeof(fileheader_t)); flock(fd, LOCK_UN); close(fd); - if((bid = getbnum(bname)) > 0) - setbtotal(bid); + if ((bid = getbnum(bname)) > 0) + setbtotal(bid); } - } -static void b_result_one(boardheader_t *fh, int ind) { - FILE *cfp, *tfp, *frp, *xfp; - char *bname ; - char buf[STRLEN]; - char inbuf[80]; - int counts[31]; - int num ; - int junk; - char b_control[64]; - char b_newresults[64]; - char b_report[64]; - time_t closetime; +static void +b_result_one(boardheader_t * fh, int ind) +{ + FILE *cfp, *tfp, *frp, *xfp; + char *bname; + char buf[STRLEN]; + char inbuf[80]; + int counts[31]; + int num; + int junk; + char b_control[64]; + char b_newresults[64]; + char b_report[64]; + time_t closetime; fh->bvote--; - if(fh->bvote==0) - fh->bvote=2; - else if(fh->bvote==2) - fh->bvote=1; + if (fh->bvote == 0) + fh->bvote = 2; + else if (fh->bvote == 2) + fh->bvote = 1; - if(ind) { + if (ind) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); sprintf(STR_new_control, "%s%d", STR_bv_control, ind); sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); @@ -189,12 +200,12 @@ static void b_result_one(boardheader_t *fh, int ind) { bname = fh->brdname; setbfile(buf, bname, STR_new_control); - cfp = fopen(buf,"r"); + cfp = fopen(buf, "r"); fscanf(cfp, "%d\n%lu\n", &junk, &closetime); fclose(cfp); setbfile(b_control, bname, "tmp"); - if(rename(buf, b_control) == -1) + if (rename(buf, b_control) == -1) return; setbfile(buf, bname, STR_new_flags); num = b_nonzeroNum(buf); @@ -204,61 +215,60 @@ static void b_result_one(boardheader_t *fh, int ind) { unlink(buf); setbfile(b_newresults, bname, "newresults"); - if((tfp = fopen(b_newresults, "w")) == NULL) + if ((tfp = fopen(b_newresults, "w")) == NULL) return; setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) { + if ((xfp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), xfp); fprintf(tfp, "%s\n¡» §ë²¼¦WºÙ: %s\n\n", msg_seperator, inbuf); } - fprintf(tfp, "%s\n¡» §ë²¼¤¤¤î©ó: %s\n\n¡» ²¼¿ïÃD¥Ø´yz:\n\n", msg_seperator, ctime(&closetime)); fh->vtime = now; - + setbfile(buf, bname, STR_new_desc); - + b_suckinfile(tfp, buf); unlink(buf); - - if((cfp = fopen(b_control, "r"))) { + + if ((cfp = fopen(b_control, "r"))) { fgets(inbuf, sizeof(inbuf), cfp); fgets(inbuf, sizeof(inbuf), cfp); fprintf(tfp, "\n¡»§ë²¼µ²ªG:(¦@¦³ %d ¤H§ë²¼,¨C¤H³Ì¦h¥i§ë %d ²¼)\n", num, junk); - while(fgets(inbuf, sizeof(inbuf), cfp)) { + while (fgets(inbuf, sizeof(inbuf), cfp)) { inbuf[(strlen(inbuf) - 1)] = '\0'; num = counts[inbuf[0] - 'A']; fprintf(tfp, " %-42s %3d ²¼ %02.2f%%\n", inbuf + 3, num, - (float)(num*100)/(float)(total)); + (float)(num * 100) / (float)(total)); } fclose(cfp); } unlink(b_control); - + fprintf(tfp, "%s\n¡» ¨Ï¥ÎªÌ«Øij¡G\n\n", msg_seperator); setbfile(buf, bname, STR_new_comments); b_suckinfile(tfp, buf); unlink(buf); - + fprintf(tfp, "%s\n¡» Á`²¼¼Æ = %d ²¼\n\n", msg_seperator, total); fclose(tfp); - + setbfile(b_report, bname, "report"); - if((frp = fopen(b_report, "w"))) { + if ((frp = fopen(b_report, "w"))) { b_suckinfile(frp, b_newresults); fclose(frp); } sprintf(inbuf, "boards/%c/%s", bname[0], bname); vote_report(bname, b_report, inbuf); - if(!(fh->brdattr &BRD_NOCOUNT)) { + if (!(fh->brdattr & BRD_NOCOUNT)) { sprintf(inbuf, "boards/%c/%s", 'R', "Record"); vote_report(bname, b_report, inbuf); } unlink(b_report); - + tfp = fopen(b_newresults, "a"); setbfile(buf, bname, STR_bv_results); b_suckinfile(tfp, buf); @@ -266,91 +276,97 @@ static void b_result_one(boardheader_t *fh, int ind) { Rename(b_newresults, buf); } -static void b_result(boardheader_t *fh) { - FILE *cfp; - time_t closetime; - int i; - char buf[STRLEN]; - char temp[STRLEN]; - - for(i = 0; i < 20; i++) { - if(i) +static void +b_result(boardheader_t * fh) +{ + FILE *cfp; + time_t closetime; + int i; + char buf[STRLEN]; + char temp[STRLEN]; + + for (i = 0; i < 20; i++) { + if (i) sprintf(STR_new_control, "%s%d", STR_bv_control, i); - else + else strcpy(STR_new_control, STR_bv_control); - setbfile(buf, fh->brdname, STR_new_control); - cfp = fopen(buf,"r"); - if (!cfp) - continue; - fgets(temp,sizeof(temp),cfp); - fscanf(cfp, "%lu\n", &closetime); - fclose(cfp); - if(closetime < now) - b_result_one(fh,i); + setbfile(buf, fh->brdname, STR_new_control); + cfp = fopen(buf, "r"); + if (!cfp) + continue; + fgets(temp, sizeof(temp), cfp); + fscanf(cfp, "%lu\n", &closetime); + fclose(cfp); + if (closetime < now) + b_result_one(fh, i); } } -static int b_close(boardheader_t *fh) { +static int +b_close(boardheader_t * fh) +{ - if(fh->bvote == 2) { - if(fh->vtime < now - 3 * 86400) { + if (fh->bvote == 2) { + if (fh->vtime < now - 3 * 86400) { fh->bvote = 0; return 1; - } - else + } else return 0; } b_result(fh); return 1; } -int b_closepolls() { - static char *fn_vote_polling = ".polling"; - boardheader_t *fhp; - FILE *cfp; - int pos, dirty; - time_t last; - char timebuf[100]; - -/* Edited by CharlieL for can't auto poll bug */ - - if((cfp = fopen(fn_vote_polling,"r"))) { - fgets(timebuf,100*sizeof(char),cfp); - sscanf(timebuf, "%lu", &last); - fclose(cfp); - if(last + 3600 >= now) - return 0; +int +b_closepolls() +{ + static char *fn_vote_polling = ".polling"; + boardheader_t *fhp; + FILE *cfp; + int pos, dirty; + time_t last; + char timebuf[100]; + + /* Edited by CharlieL for can't auto poll bug */ + + if ((cfp = fopen(fn_vote_polling, "r"))) { + fgets(timebuf, 100 * sizeof(char), cfp); + sscanf(timebuf, "%lu", &last); + fclose(cfp); + if (last + 3600 >= now) + return 0; } - - if((cfp = fopen(fn_vote_polling, "w")) == NULL) + if ((cfp = fopen(fn_vote_polling, "w")) == NULL) return 0; fprintf(cfp, "%lu\n%s\n", now, ctime(&now)); fclose(cfp); dirty = 0; - for(fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { - if(fhp->bvote && b_close(fhp)) { - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + for (fhp = bcache, pos = 1; pos <= numboards; fhp++, pos++) { + if (fhp->bvote && b_close(fhp)) { + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); dirty = 1; } } - if(dirty) /* vote flag changed */ + if (dirty) /* vote flag changed */ reset_board(pos); return 0; } -static int vote_view(char *bname, int index) { - boardheader_t *fhp; - FILE* fp; - char buf[STRLEN], genbuf[STRLEN], inbuf[STRLEN]; - struct stat stbuf; - int fd, num = 0, i, pos, counts[31]; - time_t closetime; - - if(index) { +static int +vote_view(char *bname, int index) +{ + boardheader_t *fhp; + FILE *fp; + char buf[STRLEN], genbuf[STRLEN], inbuf[STRLEN]; + struct stat stbuf; + int fd, num = 0, i, pos, counts[31]; + time_t closetime; + + if (index) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, index); sprintf(STR_new_control, "%s%d", STR_bv_control, index); sprintf(STR_new_desc, "%s%d", STR_bv_desc, index); @@ -369,43 +385,42 @@ static int vote_view(char *bname, int index) { } setbfile(buf, bname, STR_new_ballots); - if((fd = open(buf, O_RDONLY)) > 0) { + if ((fd = open(buf, O_RDONLY)) > 0) { fstat(fd, &stbuf); close(fd); } else stbuf.st_size = 0; - + setbfile(buf, bname, STR_new_title); move(0, 0); clrtobot(); - - if((fp = fopen(buf, "r"))) { + + if ((fp = fopen(buf, "r"))) { fgets(inbuf, sizeof(inbuf), fp); prints("\n§ë²¼¦WºÙ: %s", inbuf); } - setbfile(buf, bname, STR_new_control); fp = fopen(buf, "r"); fgets(inbuf, sizeof(inbuf), fp); fscanf(fp, "%lu\n", &closetime); prints("\n¡» ¹wª¾§ë²¼¬ö¨Æ: ¨C¤H³Ì¦h¥i§ë %d ²¼,¥Ø«e¦@¦³ %d ²¼,\n" - "¥»¦¸§ë²¼±Nµ²§ô©ó %s", atoi(inbuf), stbuf.st_size, + "¥»¦¸§ë²¼±Nµ²§ô©ó %s", atoi(inbuf), stbuf.st_size, ctime(&closetime)); - + /* Thor: ¶}©ñ ²¼¼Æ ¹wª¾ */ setbfile(buf, bname, STR_new_flags); num = b_nonzeroNum(buf); - + setbfile(buf, bname, STR_new_ballots); b_count(buf, counts); - + prints("¦@¦³ %d ¤H§ë²¼\n", num); total = 0; - - while(fgets(inbuf, sizeof(inbuf), fp)) { + + while (fgets(inbuf, sizeof(inbuf), fp)) { inbuf[(strlen(inbuf) - 1)] = '\0'; - inbuf[30] = '\0'; /* truncate */ + inbuf[30] = '\0'; /* truncate */ i = inbuf[0] - 'A'; num = counts[i]; move(i % 15 + 6, i / 15 * 40); @@ -419,7 +434,7 @@ static int vote_view(char *bname, int index) { prints("¡» ¥Ø«eÁ`²¼¼Æ = %d ²¼", total); getdata(b_lines - 1, 0, "(A)¨ú®ø§ë²¼ (B)´£¦¶}²¼ (C)Ä~Äò¡H[C] ", genbuf, 4, LCECHO); - if(genbuf[0] == 'a') { + if (genbuf[0] == 'a') { setbfile(buf, bname, STR_new_control); unlink(buf); setbfile(buf, bname, STR_new_flags); @@ -430,63 +445,64 @@ static int vote_view(char *bname, int index) { unlink(buf); setbfile(buf, bname, STR_new_limited); unlink(buf); - setbfile(buf,bname, STR_new_title); + setbfile(buf, bname, STR_new_title); unlink(buf); - - if(fhp->bvote) + + if (fhp->bvote) fhp->bvote--; if (fhp->bvote == 2) fhp->bvote = 1; - - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); reset_board(pos); - } else if(genbuf[0] == 'b') { - b_result_one(fhp,index); - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + } else if (genbuf[0] == 'b') { + b_result_one(fhp, index); + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); - + reset_board(pos); } return FULLUPDATE; } -static int vote_view_all(char *bname) { - int i; - int x = -1; - FILE *fp, *xfp; - char buf[STRLEN], genbuf[STRLEN]; - char inbuf[80]; - +static int +vote_view_all(char *bname) +{ + int i; + int x = -1; + FILE *fp, *xfp; + char buf[STRLEN], genbuf[STRLEN]; + char inbuf[80]; + strcpy(STR_new_control, STR_bv_control); strcpy(STR_new_title, STR_bv_title); setbfile(buf, bname, STR_new_control); move(0, 0); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { prints("(0) "); x = 0; fclose(fp); - + setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "µL¼ÐÃD"); prints("%s\n", inbuf); fclose(xfp); } - - for(i = 1; i < 20; i++) { + for (i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); x = i; fclose(fp); setbfile(buf, bname, STR_new_title); - if((xfp=fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "µL¼ÐÃD"); @@ -495,56 +511,57 @@ static int vote_view_all(char *bname) { } } - if(x < 0) + if (x < 0) return FULLUPDATE; sprintf(buf, "n¬Ý´X¸¹§ë²¼ [%d] ", x); - + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - if(atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf,"%d",x); - if(genbuf[0] != '0') + if (atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf, "%d", x); + if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); - + setbfile(buf, bname, STR_new_control); - if((fp=fopen(buf,"r"))) { + if ((fp = fopen(buf, "r"))) { fclose(fp); return vote_view(bname, atoi(genbuf)); - } - else + } else return FULLUPDATE; } -static int vote_maintain(char *bname) { - FILE *fp = NULL; - char inbuf[STRLEN], buf[STRLEN]; - int num = 0, aborted, pos, x, i; - time_t closetime; - boardheader_t *fhp; - char genbuf[4]; - - if(!(currmode & MODE_BOARD)) +static int +vote_maintain(char *bname) +{ + FILE *fp = NULL; + char inbuf[STRLEN], buf[STRLEN]; + int num = 0, aborted, pos, x, i; + time_t closetime; + boardheader_t *fhp; + char genbuf[4]; + + if (!(currmode & MODE_BOARD)) return 0; - if((pos = getbnum(bname)) <= 0) + if ((pos = getbnum(bname)) <= 0) return 0; stand_title("Á|¿ì§ë²¼"); fhp = bcache + pos - 1; -/* CharlieL */ - if(fhp->bvote != 2 && fhp->bvote !=0) { + /* CharlieL */ + if (fhp->bvote != 2 && fhp->bvote != 0) { getdata(b_lines - 1, 0, "(V)Æ[¹î¥Ø«e§ë²¼ (M)Á|¿ì·s§ë²¼ (A)¨ú®ø©Ò¦³§ë²¼ (Q)Ä~Äò [Q]", genbuf, 4, LCECHO); - if(genbuf[0] == 'v') + if (genbuf[0] == 'v') return vote_view_all(bname); - else if(genbuf[0] == 'a') { - fhp->bvote=0; - + else if (genbuf[0] == 'a') { + fhp->bvote = 0; + setbfile(buf, bname, STR_bv_control); unlink(buf); setbfile(buf, bname, STR_bv_flags); @@ -557,8 +574,8 @@ static int vote_maintain(char *bname) { unlink(buf); setbfile(buf, bname, STR_bv_title); unlink(buf); - - for(i = 1; i < 20; i++) { + + for (i = 1; i < 20; i++) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, i); sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_desc, "%s%d", STR_bv_desc, i); @@ -566,7 +583,7 @@ static int vote_maintain(char *bname) { sprintf(STR_new_comments, "%s%d", STR_bv_comments, i); sprintf(STR_new_limited, "%s%d", STR_bv_limited, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); - + setbfile(buf, bname, STR_new_control); unlink(buf); setbfile(buf, bname, STR_new_flags); @@ -580,35 +597,34 @@ static int vote_maintain(char *bname) { setbfile(buf, bname, STR_new_title); unlink(buf); } - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); - + return FULLUPDATE; - } else if(genbuf[0] != 'm' || fhp->bvote >= 20) + } else if (genbuf[0] != 'm' || fhp->bvote >= 20) return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); - setbfile(buf,bname, STR_new_control); + setbfile(buf, bname, STR_new_control); x = 0; - while(x < 20 && (fp = fopen(buf,"r")) != NULL) { + while (x < 20 && (fp = fopen(buf, "r")) != NULL) { fclose(fp); - x++; - sprintf(STR_new_control, "%s%d", STR_bv_control, x); + x++; + sprintf(STR_new_control, "%s%d", STR_bv_control, x); setbfile(buf, bname, STR_new_control); } - if(fp) + if (fp) fclose(fp); - if(x >=20) - return FULLUPDATE; - if(x) { - sprintf(STR_new_ballots, "%s%d", STR_bv_ballots,x); - sprintf(STR_new_control, "%s%d", STR_bv_control,x); - sprintf(STR_new_desc, "%s%d", STR_bv_desc,x); - sprintf(STR_new_flags, "%s%d", STR_bv_flags,x); - sprintf(STR_new_comments, "%s%d", STR_bv_comments,x); - sprintf(STR_new_limited, "%s%d", STR_bv_limited,x); - sprintf(STR_new_title, "%s%d", STR_bv_title,x); + if (x >= 20) + return FULLUPDATE; + if (x) { + sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, x); + sprintf(STR_new_control, "%s%d", STR_bv_control, x); + sprintf(STR_new_desc, "%s%d", STR_bv_desc, x); + sprintf(STR_new_flags, "%s%d", STR_bv_flags, x); + sprintf(STR_new_comments, "%s%d", STR_bv_comments, x); + sprintf(STR_new_limited, "%s%d", STR_bv_limited, x); + sprintf(STR_new_title, "%s%d", STR_bv_title, x); } else { strcpy(STR_new_ballots, STR_bv_ballots); strcpy(STR_new_control, STR_bv_control); @@ -619,21 +635,21 @@ static int vote_maintain(char *bname) { strcpy(STR_new_title, STR_bv_title); } clear(); - move(0,0); + move(0, 0); prints("²Ä %d ¸¹§ë²¼\n", x); setbfile(buf, bname, STR_new_title); getdata(4, 0, "½Ð¿é¤J§ë²¼¦WºÙ:", inbuf, 50, LCECHO); - if(inbuf[0]=='\0') - strcpy(inbuf,"¤£ª¾¦Wªº"); + if (inbuf[0] == '\0') + strcpy(inbuf, "¤£ª¾¦Wªº"); fp = fopen(buf, "w"); fprintf(fp, "%s", inbuf); fclose(fp); - + prints("«ö¥ô¦óÁä¶}©l½s¿è¦¹¦¸ [§ë²¼©v¦®]"); pressanykey(); setbfile(buf, bname, STR_new_desc); aborted = vedit(buf, NA, NULL); - if(aborted== -1) { + if (aborted == -1) { clear(); outs("¨ú®ø¦¹¦¸§ë²¼"); pressanykey(); @@ -642,29 +658,29 @@ static int vote_maintain(char *bname) { aborted = 0; setbfile(buf, bname, STR_new_flags); unlink(buf); - + getdata(4, 0, "¬O§_©w§ë²¼ªÌ¦W³æ¡G(y)½sÄy¥i§ë²¼¤Hû¦W³æ[n]¥ô¦ó¤H¬Ò¥i§ë²¼:[N]", inbuf, 2, LCECHO); setbfile(buf, bname, STR_new_limited); - if(inbuf[0] == 'y') { + if (inbuf[0] == 'y') { fp = fopen(buf, "w"); - fprintf(fp,"¦¹¦¸§ë²¼³]"); + fprintf(fp, "¦¹¦¸§ë²¼³]"); fclose(fp); friend_edit(FRIEND_CANVOTE); } else { - if(dashf(buf)) + if (dashf(buf)) unlink(buf); } clear(); getdata(0, 0, "¦¹¦¸§ë²¼¶i¦æ´X¤Ñ (¤@¨ì¤Q¤Ñ)¡H", inbuf, 4, DOECHO); closetime = atoi(inbuf); - if(closetime <= 0) + if (closetime <= 0) closetime = 1; - else if(closetime >10) + else if (closetime > 10) closetime = 10; - + closetime = closetime * 86400 + now; setbfile(buf, bname, STR_new_control); fp = fopen(buf, "w"); @@ -672,67 +688,69 @@ static int vote_maintain(char *bname) { outs("\n½Ð¨Ì§Ç¿é¤J¿ï¶µ, «ö ENTER §¹¦¨³]©w"); num = 0; - while(!aborted) { + while (!aborted) { sprintf(buf, "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, inbuf, 50, DOECHO); - if(*inbuf) { - fprintf(fp, "%1c) %s\n", (num+'A'), inbuf); + if (*inbuf) { + fprintf(fp, "%1c) %s\n", (num + 'A'), inbuf); num++; } - if((*inbuf == '\0' && num >= 1) || num == 30) + if ((*inbuf == '\0' && num >= 1) || num == 30) aborted = 1; } sprintf(buf, "½Ð°Ý¨C¤H³Ì¦h¥i§ë´X²¼¡H([1]¡ã%d): ", num); - - getdata(t_lines-3, 0, buf, inbuf, 3, DOECHO); - - if(atoi(inbuf) <= 0 || atoi(inbuf) > num) - strcpy(inbuf,"1"); - + + getdata(t_lines - 3, 0, buf, inbuf, 3, DOECHO); + + if (atoi(inbuf) <= 0 || atoi(inbuf) > num) + strcpy(inbuf, "1"); + rewind(fp); fprintf(fp, "%2d\n", MAX(1, atoi(inbuf))); fclose(fp); - - if(fhp->bvote == 2) - fhp->bvote = 0; - else if(fhp->bvote == 1) - fhp->bvote = 2; - else if(fhp->bvote == 2) - fhp->bvote = 1; - - fhp->bvote ++; - - if(substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) + + if (fhp->bvote == 2) + fhp->bvote = 0; + else if (fhp->bvote == 1) + fhp->bvote = 2; + else if (fhp->bvote == 2) + fhp->bvote = 1; + + fhp->bvote++; + + if (substitute_record(fn_board, fhp, sizeof(*fhp), pos) == -1) outs(err_board_update); reset_board(pos); outs("¶}©l§ë²¼¤F¡I"); - + return FULLUPDATE; } -static int vote_flag(char *bname, int index, char val) { - char buf[256], flag; - int fd, num, size; +static int +vote_flag(char *bname, int index, char val) +{ + char buf[256], flag; + int fd, num, size; - if(index) + if (index) sprintf(STR_new_flags, "%s%d", STR_bv_flags, index); else strcpy(STR_new_flags, STR_bv_flags); - + num = usernum - 1; setbfile(buf, bname, STR_new_flags); - if((fd = open(buf, O_RDWR | O_CREAT, 0600)) == -1) + if ((fd = open(buf, O_RDWR | O_CREAT, 0600)) == -1) return -1; size = lseek(fd, 0, SEEK_END); memset(buf, 0, sizeof(buf)); - while(size <= num) { + while (size <= num) { write(fd, buf, sizeof(buf)); size += sizeof(buf); } lseek(fd, num, SEEK_SET); read(fd, &flag, 1); - if(flag == 0 && val != 0) { + if (flag == 0 && val != 0) { lseek(fd, num, SEEK_SET); write(fd, &val, 1); } @@ -740,28 +758,32 @@ static int vote_flag(char *bname, int index, char val) { return flag; } -static int same(char compare, char list[], int num) { - int n; - int rep = 0; +static int +same(char compare, char list[], int num) +{ + int n; + int rep = 0; - for(n = 0; n < num; n++) { - if(compare == list[n]) + for (n = 0; n < num; n++) { + if (compare == list[n]) rep = 1; - if(rep == 1) + if (rep == 1) list[n] = list[n + 1]; } return rep; } -static int user_vote_one(char *bname, int ind) { - FILE* cfp,*fcm; - char buf[STRLEN]; - boardheader_t *fhp; - int pos = 0, i = 0, count = 0, tickets, fd; - char inbuf[80], choices[31], vote[4], chosen[31]; - time_t closetime; - - if(ind) { +static int +user_vote_one(char *bname, int ind) +{ + FILE *cfp, *fcm; + char buf[STRLEN]; + boardheader_t *fhp; + int pos = 0, i = 0, count = 0, tickets, fd; + char inbuf[80], choices[31], vote[4], chosen[31]; + time_t closetime; + + if (ind) { sprintf(STR_new_ballots, "%s%d", STR_bv_ballots, ind); sprintf(STR_new_control, "%s%d", STR_bv_control, ind); sprintf(STR_new_desc, "%s%d", STR_bv_desc, ind); @@ -778,14 +800,14 @@ static int user_vote_one(char *bname, int ind) { } setbfile(buf, bname, STR_new_control); - cfp = fopen(buf,"r"); - if(!cfp) - return FULLUPDATE; + cfp = fopen(buf, "r"); + if (!cfp) + return FULLUPDATE; - setbfile(buf, bname, STR_new_limited); /* Ptt */ - if(dashf(buf)) { + setbfile(buf, bname, STR_new_limited); /* Ptt */ + if (dashf(buf)) { setbfile(buf, bname, FN_CANVOTE); - if(!belong(buf, cuser.userid)) { + if (!belong(buf, cuser.userid)) { fclose(cfp); outs("\n\n¹ï¤£°_! ³o¬O¨p¤H§ë²¼..§A¨Ã¨S¦³¨üÁÜò!"); pressanykey(); @@ -796,24 +818,23 @@ static int user_vote_one(char *bname, int ind) { more(buf, YEA); } } - if(vote_flag(bname, ind, '\0')) { + if (vote_flag(bname, ind, '\0')) { outs("\n\n¦¹¦¸§ë²¼¡A§A¤w§ë¹L¤F¡I"); pressanykey(); return FULLUPDATE; } - setutmpmode(VOTING); setbfile(buf, bname, STR_new_desc); more(buf, YEA); stand_title("§ë²¼½c"); - if((pos = getbnum(bname)) <= 0) + if ((pos = getbnum(bname)) <= 0) return 0; fhp = bcache + pos - 1; fgets(inbuf, sizeof(inbuf), cfp); tickets = atoi(inbuf); - fscanf(cfp,"%lu\n", &closetime); + fscanf(cfp, "%lu\n", &closetime); prints("§ë²¼¤è¦¡¡G½T©w¦n±zªº¿ï¾Ü«á¡A¿é¤J¨ä¥N½X(A, B, C...)§Y¥i¡C\n" "¦¹¦¸§ë²¼§A¥i¥H§ë %1d ²¼¡C" @@ -822,61 +843,60 @@ static int user_vote_one(char *bname, int ind) { tickets, ctime(&closetime)); move(5, 0); memset(choices, 0, sizeof(choices)); - memset(chosen , 0, sizeof(chosen)); + memset(chosen, 0, sizeof(chosen)); - while(fgets(inbuf, sizeof(inbuf), cfp)) { + while (fgets(inbuf, sizeof(inbuf), cfp)) { move((count % 15) + 5, (count / 15) * 40); - prints( " %s", strtok(inbuf, "\n\0")); + prints(" %s", strtok(inbuf, "\n\0")); choices[count++] = inbuf[0]; } fclose(cfp); - while(1) { + while (1) { vote[0] = vote[1] = '\0'; move(t_lines - 2, 0); prints("§AÁÙ¥i¥H§ë %2d ²¼", tickets - i); getdata(t_lines - 4, 0, "¿é¤J±zªº¿ï¾Ü: ", vote, sizeof(vote), DOECHO); *vote = toupper(*vote); - if(vote[0] == '0' || (!vote[0] && !i)) { + if (vote[0] == '0' || (!vote[0] && !i)) { outs("°Oªº¦A¨Ó§ë³á!!"); break; - } else if(vote[0] == '1' && i) - ; - else if(!vote[0]) + } else if (vote[0] == '1' && i); + else if (!vote[0]) continue; - else if(index(choices, vote[0]) == NULL) /* µL®Ä */ + else if (index(choices, vote[0]) == NULL) /* µL®Ä */ continue; - else if(same(vote[0], chosen, i)) { + else if (same(vote[0], chosen, i)) { move(((vote[0] - 'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); prints(" "); i--; continue; } else { - if(i == tickets) + if (i == tickets) continue; chosen[i] = vote[0]; - move(((vote[0]-'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); + move(((vote[0] - 'A') % 15) + 5, (((vote[0] - 'A')) / 15) * 40); prints("*"); i++; continue; } - - if(vote_flag(bname, ind, vote[0]) != 0) + + if (vote_flag(bname, ind, vote[0]) != 0) prints("«ÂЧ벼! ¤£¤©p²¼¡C"); else { setbfile(buf, bname, STR_new_ballots); - if((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0) + if ((fd = open(buf, O_WRONLY | O_CREAT | O_APPEND, 0600)) == 0) outs("µLªk§ë¤J²¼Ôo\n"); else { - struct stat statb; - char buf[3], mycomments[3][74], b_comments[80]; - - for(i = 0; i < 3; i++) + struct stat statb; + char buf[3], mycomments[3][74], b_comments[80]; + + for (i = 0; i < 3; i++) strcpy(mycomments[i], "\n"); flock(fd, LOCK_EX); - for(count = 0; count < 31; count++) { - if(chosen[count]) + for (count = 0; count < 31; count++) { + if (chosen[count]) write(fd, &chosen[count], 1); } flock(fd, LOCK_UN); @@ -884,35 +904,36 @@ static int user_vote_one(char *bname, int ind) { close(fd); getdata(b_lines - 2, 0, "±z¹ï³o¦¸§ë²¼¦³¤°»òÄ_¶Qªº·N¨£¶Ü¡H(y/n)[N]", - buf, 3 ,DOECHO); - if(buf[0] == 'Y' || buf[0] == 'y'){ + buf, 3, DOECHO); + if (buf[0] == 'Y' || buf[0] == 'y') { do { - move(5,0);clrtobot(); + move(5, 0); + clrtobot(); outs("½Ð°Ý±z¹ï³o¦¸§ë²¼¦³¤°»òÄ_¶Qªº·N¨£¡H" "³Ì¦h¤T¦æ¡A«ö[Enter]µ²§ô"); - for(i = 0; (i < 3) && - getdata(7 + i, 0, "¡G", - mycomments[i], sizeof(mycomments[i]), - DOECHO); i++); - getdata(b_lines-2,0, "(S)Àx¦s (E)«·s¨Ó¹L " + for (i = 0; (i < 3) && + getdata(7 + i, 0, "¡G", + mycomments[i], sizeof(mycomments[i]), + DOECHO); i++); + getdata(b_lines - 2, 0, "(S)Àx¦s (E)«·s¨Ó¹L " "(Q)¨ú®ø¡H[S]", buf, 3, LCECHO); - } while(buf[0] == 'E' || buf[0] == 'e'); - if(buf[0] == 'Q' || buf[0] == 'q') + } while (buf[0] == 'E' || buf[0] == 'e'); + if (buf[0] == 'Q' || buf[0] == 'q') break; setbfile(b_comments, bname, STR_new_comments); - if(mycomments[0]) - if((fcm = fopen(b_comments, "a"))){ - fprintf(fcm, - "\033[36m¡³¨Ï¥ÎªÌ\033[1;36m %s " - "\033[;36mªº«Øij¡G\033[m\n", + if (mycomments[0]) + if ((fcm = fopen(b_comments, "a"))) { + fprintf(fcm, + "\033[36m¡³¨Ï¥ÎªÌ\033[1;36m %s " + "\033[;36mªº«Øij¡G\033[m\n", cuser.userid); - for(i = 0; i < 3; i++) + for (i = 0; i < 3; i++) fprintf(fcm, " %s\n", mycomments[i]); fprintf(fcm, "\n"); fclose(fcm); - } + } } - move(b_lines - 1 ,0); + move(b_lines - 1, 0); prints("¤w§¹¦¨§ë²¼¡I\n"); } } @@ -922,64 +943,63 @@ static int user_vote_one(char *bname, int ind) { return FULLUPDATE; } -static int user_vote(char *bname) { - int pos; - boardheader_t *fhp; - char buf[STRLEN]; - FILE* fp,*xfp; - int i, x = -1; - char genbuf[STRLEN]; - char inbuf[80]; - - if((pos = getbnum(bname)) <= 0) +static int +user_vote(char *bname) +{ + int pos; + boardheader_t *fhp; + char buf[STRLEN]; + FILE *fp, *xfp; + int i, x = -1; + char genbuf[STRLEN]; + char inbuf[80]; + + if ((pos = getbnum(bname)) <= 0) return 0; - + fhp = bcache + pos - 1; - - move(0,0); + + move(0, 0); clrtobot(); - - if(fhp->bvote == 2 || fhp->bvote == 0) { + + if (fhp->bvote == 2 || fhp->bvote == 0) { outs("\n\n¥Ø«e¨Ã¨S¦³¥ô¦ó§ë²¼Á|¦æ¡C"); pressanykey(); return FULLUPDATE; } - - if(!HAS_PERM(PERM_LOGINOK)) { + if (!HAS_PERM(PERM_LOGINOK)) { outs("\n¹ï¤£°_! ±z¥¼º¡¤G¤Q·³, ÁÙ¨S¦³§ë²¼Åv³á!"); pressanykey(); return FULLUPDATE; } - strcpy(STR_new_control, STR_bv_control); strcpy(STR_new_title, STR_bv_title); setbfile(buf, bname, STR_new_control); move(0, 0); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { prints("(0) "); x = 0; fclose(fp); setbfile(buf, bname, STR_new_title); - if((xfp = fopen(buf,"r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "µL¼ÐÃD"); prints("%s\n", inbuf); fclose(xfp); } - - for(i = 1; i < 20; i++) { + for (i = 1; i < 20; i++) { sprintf(STR_new_control, "%s%d", STR_bv_control, i); sprintf(STR_new_title, "%s%d", STR_bv_title, i); setbfile(buf, bname, STR_new_control); - if((fp = fopen(buf, "r"))) { + if ((fp = fopen(buf, "r"))) { prints("(%d) ", i); x = i; fclose(fp); - + setbfile(buf, bname, STR_new_title); - if((xfp = fopen(buf, "r"))) + if ((xfp = fopen(buf, "r"))) fgets(inbuf, sizeof(inbuf), xfp); else strcpy(inbuf, "µL¼ÐÃD"); @@ -987,49 +1007,57 @@ static int user_vote(char *bname) { fclose(xfp); } } - - if(x < 0) + + if (x < 0) return FULLUPDATE; - + sprintf(buf, "n§ë´X¸¹§ë²¼ [%d] ", x); - + getdata(b_lines - 1, 0, buf, genbuf, 4, LCECHO); - - if(atoi(genbuf) < 0 || atoi(genbuf) > 20) - sprintf(genbuf,"%d",x); - - if(genbuf[0] != '0') + + if (atoi(genbuf) < 0 || atoi(genbuf) > 20) + sprintf(genbuf, "%d", x); + + if (genbuf[0] != '0') sprintf(STR_new_control, "%s%d", STR_bv_control, atoi(genbuf)); else strcpy(STR_new_control, STR_bv_control); - + setbfile(buf, bname, STR_new_control); - if((fp = fopen(buf, "r"))){ + if ((fp = fopen(buf, "r"))) { fclose(fp); - + return user_vote_one(bname, atoi(genbuf)); } else return FULLUPDATE; } -static int vote_results(char *bname) { - char buf[STRLEN]; +static int +vote_results(char *bname) +{ + char buf[STRLEN]; setbfile(buf, bname, STR_bv_results); - if(more(buf, YEA) == -1) + if (more(buf, YEA) == -1) outs("\n¥Ø«e¨S¦³¥ô¦ó§ë²¼ªºµ²ªG¡C"); return FULLUPDATE; } -int b_vote_maintain() { +int +b_vote_maintain() +{ return vote_maintain(currboard); } -int b_vote() { +int +b_vote() +{ return user_vote(currboard); } -int b_results() { +int +b_results() +{ return vote_results(currboard); } diff --git a/mbbsd/voteboard.c b/mbbsd/voteboard.c index 3d35cead..e720d920 100644 --- a/mbbsd/voteboard.c +++ b/mbbsd/voteboard.c @@ -1,83 +1,84 @@ -/* $Id: voteboard.c,v 1.8 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: voteboard.c,v 1.9 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" #define VOTEBOARD "NewBoard" -void do_voteboardreply(fileheader_t *fhdr){ - char genbuf[1024]; - char reason[50]; - char fpath[80]; - char oldfpath[80]; - char opnion[10]; - char *ptr; - FILE *fo, *fp; - fileheader_t votefile; - int len; - int i, j; - int fd; - time_t endtime; - int hastime = 0; - +void +do_voteboardreply(fileheader_t * fhdr) +{ + char genbuf[1024]; + char reason[50]; + char fpath[80]; + char oldfpath[80]; + char opnion[10]; + char *ptr; + FILE *fo, *fp; + fileheader_t votefile; + int len; + int i, j; + int fd; + time_t endtime; + int hastime = 0; + clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("¹ï¤£°_¡A±z¥Ø«eµLªk¦b¦¹µoªí¤å³¹¡I"); pressanykey(); return; - } - + } setbpath(fpath, currboard); stampfile(fpath, &votefile); setbpath(oldfpath, currboard); - + strcat(oldfpath, "/"); strcat(oldfpath, fhdr->filename); - + fp = fopen(oldfpath, "r"); - + len = strlen(cuser.userid); - - while(fgets(genbuf, 1024, fp)){ - if (!strncmp(genbuf, "³s¸pµ²§ô®É¶¡", 12)){ + + while (fgets(genbuf, 1024, fp)) { + if (!strncmp(genbuf, "³s¸pµ²§ô®É¶¡", 12)) { hastime = 1; ptr = strchr(genbuf, '('); - sscanf(ptr+1, "%ld", &endtime); - if (endtime < now){ + sscanf(ptr + 1, "%ld", &endtime); + if (endtime < now) { prints("³s¸p®É¶¡¤w¹L"); pressanykey(); fclose(fp); return; } } - if (!strncmp(genbuf+4, cuser.userid, len)){ + if (!strncmp(genbuf + 4, cuser.userid, len)) { move(5, 10); prints("±z¤w¸g³s¸p¹L¥»½g¤F"); opnion[0] = 'n'; getdata(7, 0, "nקï±z¤§«eªº³s¸p¶Ü¡H(Y/N) [N]", opnion, 3, LCECHO); - if (opnion[0] != 'y'){ + if (opnion[0] != 'y') { fclose(fp); return; } - strcpy(reason, genbuf+19); + strcpy(reason, genbuf + 19); } } - fclose(fp); - - if((fd = open(oldfpath, O_RDONLY)) == -1) + fclose(fp); + + if ((fd = open(oldfpath, O_RDONLY)) == -1) return; flock(fd, LOCK_EX); - + fo = fopen(fpath, "w"); - + if (!fo) return; i = 0; - while(fo){ + while (fo) { j = 0; - do{ - if (read(fd, genbuf+j, 1)<=0){ + do { + if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); fclose(fo); @@ -85,114 +86,113 @@ void do_voteboardreply(fileheader_t *fhdr){ return; } j++; - }while(genbuf[j-1] !='\n'); - genbuf[j] = '\0'; + } while (genbuf[j - 1] != '\n'); + genbuf[j] = '\0'; i++; if (!strncmp("----------", genbuf, 10)) break; if (i > 3) prints(genbuf); - fprintf(fo, "%s", genbuf); + fprintf(fo, "%s", genbuf); } - if (!hastime){ - now += 14*24*60*60; + if (!hastime) { + now += 14 * 24 * 60 * 60; fprintf(fo, "³s¸pµ²§ô®É¶¡: (%ld)%s", now, ctime(&now)); - now -= 14*24*60*60; + now -= 14 * 24 * 60 * 60; } - fprintf(fo, "%s", genbuf); - do{ - if (!getdata(18, 0, "½Ð°Ý±z (Y)¤ä«ù (N)¤Ï¹ï ³oÓijÃD¡G", opnion, 3, LCECHO)){ + do { + if (!getdata(18, 0, "½Ð°Ý±z (Y)¤ä«ù (N)¤Ï¹ï ³oÓijÃD¡G", opnion, 3, LCECHO)) { flock(fd, LOCK_UN); - close(fd); + close(fd); fclose(fo); unlink(fpath); return; } - }while(opnion[0] != 'y' && opnion[0] != 'n'); - + } while (opnion[0] != 'y' && opnion[0] != 'n'); + if (!getdata(20, 0, "½Ð°Ý±z»P³oÓijÃDªºÃö«Y©Î³s¸p²z¥Ñ¬°¦ó¡G", - reason, sizeof(reason), DOECHO)){ + reason, sizeof(reason), DOECHO)) { flock(fd, LOCK_UN); - close(fd); + close(fd); fclose(fo); unlink(fpath); - return; + return; } - i = 0; - - while(fo){ + + while (fo) { i++; j = 0; - do{ - if (read(fd, genbuf+j, 1)<=0){ + do { + if (read(fd, genbuf + j, 1) <= 0) { flock(fd, LOCK_UN); close(fd); fclose(fo); unlink(fpath); return; - } + } j++; - }while(genbuf[j-1] !='\n'); + } while (genbuf[j - 1] != '\n'); genbuf[j] = '\0'; if (!strncmp("----------", genbuf, 10)) break; - if (strncmp(genbuf+4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf+4); + if (strncmp(genbuf + 4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'y') - fprintf(fo, "%3d.%-15s%-34s ¨Ó·½:%s\n", i, cuser.userid, reason,cuser.lasthost); + fprintf(fo, "%3d.%-15s%-34s ¨Ó·½:%s\n", i, cuser.userid, reason, cuser.lasthost); i = 0; fprintf(fo, "%s", genbuf); - while(fo){ + while (fo) { i++; j = 0; - do{ - if (!read(fd, genbuf+j, 1)) + do { + if (!read(fd, genbuf + j, 1)) break; j++; - }while(genbuf[j-1] !='\n'); + } while (genbuf[j - 1] != '\n'); genbuf[j] = '\0'; if (j <= 3) - break; - if (strncmp(genbuf+4, cuser.userid, len)) - fprintf(fo, "%3d.%s", i, genbuf+4); + break; + if (strncmp(genbuf + 4, cuser.userid, len)) + fprintf(fo, "%3d.%s", i, genbuf + 4); else i--; } if (opnion[0] == 'n') - fprintf(fo, "%3d.%-15s%-34s ¨Ó·½:%s\n", i, cuser.userid, reason,cuser.lasthost); - flock(fd, LOCK_UN); + fprintf(fo, "%3d.%-15s%-34s ¨Ó·½:%s\n", i, cuser.userid, reason, cuser.lasthost); + flock(fd, LOCK_UN); close(fd); fclose(fo); unlink(oldfpath); rename(fpath, oldfpath); #ifdef MDCACHE close(updatemdcache(NULL, oldfpath)); -#endif +#endif } -int do_voteboard() { - fileheader_t votefile; - char topic[100]; - char title[80]; - char genbuf[1024]; - char fpath[80]; - FILE* fp; - int temp, i; +int +do_voteboard() +{ + fileheader_t votefile; + char topic[100]; + char title[80]; + char genbuf[1024]; + char fpath[80]; + FILE *fp; + int temp, i; clear(); - if(!(currmode & MODE_POST)) { + if (!(currmode & MODE_POST)) { move(5, 10); outs("¹ï¤£°_¡A±z¥Ø«eµLªk¦b¦¹µoªí¤å³¹¡I"); pressanykey(); return FULLUPDATE; - } - + } move(0, 0); clrtobot(); prints("±z¥¿¦b¨Ï¥Î PTT ªº³s¸p¨t²Î\n"); @@ -200,23 +200,23 @@ int do_voteboard() { prints("¥ô·N´£¥X³s¸p®×ªÌ¡A±N³Q¦C¤J¥»¨t²Î¤£¨üÅwªï¨Ï¥ÎªÌ³á\n"); pressanykey(); move(0, 0); - clrtobot(); + clrtobot(); prints("(1)¥Ó½Ð·sªO (2)¼o°£ÂªO (3)³s¸pªO¥D (4)½}§KªO¥D\n"); if (!strcmp(currboard, VOTEBOARD)) prints("(5)³s¸p¤p²Õªø (6)½}§K¤p²Õªø "); if (!strcmp(currboard, VOTEBOARD) && HAS_PERM(PERM_SYSOP)) prints("(7)¯¸¥Á¤½§ë"); prints("(8)¥Ó½Ð·s¸s²Õ"); - - do{ + + do { getdata(3, 0, "½Ð¿é¤J³s¸pÃþ§O¡G", topic, 3, DOECHO); temp = atoi(topic); - }while(temp <= 0 && temp >= 9); - - switch(temp){ - case 1: - do{ - if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN+1, DOECHO)) + } while (temp <= 0 && temp >= 9); + + switch (temp) { + case 1: + do { + if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (invalid_brdname(topic)) outs("¤£¬O¥¿½Tªº¬ÝªO¦WºÙ"); @@ -224,198 +224,198 @@ int do_voteboard() { outs("¥»¦WºÙ¤w¸g¦s¦b"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[¥Ó½Ð·sªO] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","¥Ó½Ð·sªO", "^¤å¦WºÙ: ", topic, "¤¤¤å¦WºÙ: "); - + sprintf(genbuf, "%s\n\n%s%s\n%s", "¥Ó½Ð·sªO", "^¤å¦WºÙ: ", topic, "¤¤¤å¦WºÙ: "); + if (!getdata(5, 0, "½Ð¿é¤J¬ÝªO¤¤¤å¦WºÙ¡G", topic, 20, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); strcat(genbuf, "\n¬ÝªOÃþ§O: "); if (!getdata(6, 0, "½Ð¿é¤J¬ÝªOÃþ§O¡G", topic, 20, DOECHO)) return FULLUPDATE; - strcat(genbuf, topic); + strcat(genbuf, topic); strcat(genbuf, "\nªO¥D¦W³æ: "); getdata(7, 0, "½Ð¿é¤JªO¥D¦W³æ¡G", topic, IDLEN * 3 + 3, DOECHO); strcat(genbuf, topic); strcat(genbuf, "\n¥Ó½Ðì¦]: \n"); outs("½Ð¿é¤J¥Ó½Ðì¦](¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; case 2: - do{ - if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN+1, DOECHO)) + do { + if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("¥»¦WºÙ¨Ã¤£¦s¦b"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[¼o°£ÂªO] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n","¼o°£ÂªO", "^¤å¦WºÙ: ", topic); + sprintf(genbuf, "%s\n\n%s%s\n", "¼o°£ÂªO", "^¤å¦WºÙ: ", topic); strcat(genbuf, "\n¼o°£ì¦]: \n"); outs("½Ð¿é¤J¼o°£ì¦](¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - + break; - case 3: - do{ - if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN+1, DOECHO)) + case 3: + do { + if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if (getbnum(topic) <= 0) outs("¥»¦WºÙ¨Ã¤£¦s¦b"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[³s¸pªO¥D] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","³s¸pªO¥D", "^¤å¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "³s¸pªO¥D", "^¤å¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); strcat(genbuf, "\n¥Ó½Ð¬F¨£: \n"); outs("½Ð¿é¤J¥Ó½Ð¬F¨£(¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) - return FULLUPDATE; - break; - case 4: - do{ - if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN+1, DOECHO)) + if (i == 8) + return FULLUPDATE; + break; + case 4: + do { + if (!getdata(4, 0, "½Ð¿é¤J¬ÝªO^¤å¦WºÙ¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; else if ((i = getbnum(topic)) <= 0) outs("¥»¦WºÙ¨Ã¤£¦s¦b"); else break; - }while(temp > 0); + } while (temp > 0); sprintf(title, "[½}§KªO¥D] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","½}§KªO¥D", "^¤å¦WºÙ: ", topic, "ªO¥D ID : "); - do{ + sprintf(genbuf, "%s\n\n%s%s\n%s", "½}§KªO¥D", "^¤å¦WºÙ: ", topic, "ªO¥D ID : "); + do { if (!getdata(6, 0, "½Ð¿é¤JªO¥DID¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; - else if (!userid_is_BM(topic, bcache[i-1].BM)) + else if (!userid_is_BM(topic, bcache[i - 1].BM)) outs("¤£¬O¸ÓªOªºªO¥D"); else break; - }while(temp > 0); + } while (temp > 0); strcat(genbuf, topic); strcat(genbuf, "\n½}§Kì¦]: \n"); outs("½Ð¿é¤J½}§Kì¦](¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; - case 5: + break; + case 5: if (!getdata(4, 0, "½Ð¿é¤J¤p²Õ¤¤^¤å¦WºÙ¡G", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[³s¸p¤p²Õªø] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","³s¸p¤p²Õªø", "¤p²Õ¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "³s¸p¤p²Õªø", "¤p²Õ¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); strcat(genbuf, "\n¥Ó½Ð¬F¨£: \n"); outs("½Ð¿é¤J¥Ó½Ð¬F¨£(¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; case 6: - + if (!getdata(4, 0, "½Ð¿é¤J¤p²Õ¤¤^¤å¦WºÙ¡G", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[½}§K¤p²Õªø] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s","½}§K¤p²Õªø", "¤p²Õ¦WºÙ: ", topic, "¤p²Õªø ID : "); + sprintf(genbuf, "%s\n\n%s%s\n%s", "½}§K¤p²Õªø", "¤p²Õ¦WºÙ: ", topic, "¤p²Õªø ID : "); if (!getdata(6, 0, "½Ð¿é¤J¤p²ÕªøID¡G", topic, IDLEN + 1, DOECHO)) return FULLUPDATE; strcat(genbuf, topic); strcat(genbuf, "\n½}§Kì¦]: \n"); outs("½Ð¿é¤J½}§Kì¦](¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; - case 7: + break; + case 7: if (!HAS_PERM(PERM_SYSOP)) return FULLUPDATE; if (!getdata(4, 0, "½Ð¿é¤J¤½§ë¥DÃD¡G", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "%s %s", "[¯¸¥Á¤½§ë]", topic); - sprintf(genbuf, "%s\n\n%s%s\n","¯¸¥Á¤½§ë", "¤½§ë¥DÃD: ", topic); + sprintf(genbuf, "%s\n\n%s%s\n", "¯¸¥Á¤½§ë", "¤½§ë¥DÃD: ", topic); strcat(genbuf, "\n¤½§ëì¦]: \n"); outs("½Ð¿é¤J¤½§ëì¦](¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; - break; + break; case 8: - if(!getdata(4, 0, "½Ð¿é¤J¸s²Õ¤¤^¤å¦WºÙ¡G", topic, 30, DOECHO)) + if (!getdata(4, 0, "½Ð¿é¤J¸s²Õ¤¤^¤å¦WºÙ¡G", topic, 30, DOECHO)) return FULLUPDATE; sprintf(title, "[¥Ó½Ð·s¸s²Õ] %s", topic); - sprintf(genbuf, "%s\n\n%s%s\n%s%s","¥Ó½Ð¸s²Õ", "¸s²Õ¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); + sprintf(genbuf, "%s\n\n%s%s\n%s%s", "¥Ó½Ð¸s²Õ", "¸s²Õ¦WºÙ: ", topic, "¥Ó½Ð ID : ", cuser.userid); strcat(genbuf, "\n¥Ó½Ð¬F¨£: \n"); outs("½Ð¿é¤J¥Ó½Ð¬F¨£(¦Ü¦h¤¦æ)¡An²M·¡¶ñ¼g¤£µM¤£·|®Öã³á"); - for(i= 8;i<13;i++){ + for (i = 8; i < 13; i++) { if (!getdata(i, 0, "¡G", topic, 60, DOECHO)) break; strcat(genbuf, topic); strcat(genbuf, "\n"); } - if (i==8) + if (i == 8) return FULLUPDATE; break; default: return FULLUPDATE; } strcat(genbuf, "³s¸pµ²§ô®É¶¡: "); - now += 14*24*60*60; + now += 14 * 24 * 60 * 60; sprintf(topic, "(%ld)", now); strcat(genbuf, topic); strcat(genbuf, ctime(&now)); - now -= 14*24*60*60; + now -= 14 * 24 * 60 * 60; strcat(genbuf, "----------¤ä«ù----------\n"); - strcat(genbuf, "----------¤Ï¹ï----------\n"); + strcat(genbuf, "----------¤Ï¹ï----------\n"); outs("¶}©l³s¸p¹Æ"); setbpath(fpath, currboard); stampfile(fpath, &votefile); - - if (!(fp = fopen(fpath, "w"))){ + + if (!(fp = fopen(fpath, "w"))) { outs("¶}ÀÉ¥¢±Ñ¡A½ÐµyÔ«¨Ó¤@¦¸"); return FULLUPDATE; } fprintf(fp, "%s%s %s%s\n%s%s\n%s%s", "§@ªÌ: ", cuser.userid, - "¬ÝªO: ", currboard, + "¬ÝªO: ", currboard, "¼ÐÃD: ", title, "®É¶¡: ", ctime(&now)); fprintf(fp, "%s\n", genbuf); @@ -423,7 +423,7 @@ int do_voteboard() { strcpy(votefile.owner, cuser.userid); strcpy(votefile.title, title); setbdir(genbuf, currboard); - if(append_record(genbuf, &votefile, sizeof(votefile)) != -1) + if (append_record(genbuf, &votefile, sizeof(votefile)) != -1) setbtotal(currbid); do_voteboardreply(&votefile); return FULLUPDATE; diff --git a/mbbsd/xyz.c b/mbbsd/xyz.c index 3a14b4b5..21701df8 100644 --- a/mbbsd/xyz.c +++ b/mbbsd/xyz.c @@ -1,9 +1,11 @@ -/* $Id: xyz.c,v 1.9 2002/06/19 13:32:23 lwms Exp $ */ +/* $Id: xyz.c,v 1.10 2002/07/05 17:10:28 in2 Exp $ */ #include "bbs.h" /* ¦UºØ²Îp¤Î¬ÛÃö¸ê°T¦Cªí */ /* Ptt90¦~«×¤j¾ÇÁp©Û¬dº]¨t²Î */ -int x_90() { +int +x_90() +{ strcpy(dict, "(90)ã¦ÒÃÒ¸¹/©m¦W/¾Ç®Õ/¬ì¨t/Ãþ²Õ"); strcpy(database, "etc/90"); use_dict(); @@ -11,221 +13,258 @@ int x_90() { } /* Ptt89¦~«×¤j¾ÇÁp©Û¬dº]¨t²Î */ -int x_89() { +int +x_89() +{ strcpy(dict, "(89)ã¦ÒÃÒ¸¹/©m¦W/¾Ç®Õ/¬ì¨t/Ãþ²Õ"); strcpy(database, "etc/89"); use_dict(); return 0; } /* Ptt88¦~«×¤j¾ÇÁp©Û¬dº]¨t²Î */ -int x_88() { +int +x_88() +{ strcpy(dict, "(88)ã¦ÒÃÒ¸¹/©m¦W/¾Ç®Õ/¬ì¨t/Ãþ²Õ"); strcpy(database, "etc/88"); use_dict(); return 0; -} +} /* Ptt87¦~«×¤j¾ÇÁp©Û¬dº]¨t²Î */ -int x_87() { +int +x_87() +{ strcpy(dict, "(87)ã¦ÒÃÒ¸¹/©m¦W/¾Ç®Õ/¬ì¨t"); strcpy(database, "etc/87"); use_dict(); return 0; -} +} /* Ptt86¦~«×¤j¾ÇÁp©Û¬dº]¨t²Î */ -int x_86() { +int +x_86() +{ strcpy(dict, "(86)ã¦ÒÃÒ¸¹/©m¦W/¾Ç®Õ/¬ì¨t"); strcpy(database, "etc/86"); use_dict(); return 0; } -int x_boardman() { +int +x_boardman() +{ more("etc/topboardman", YEA); return 0; } -int x_user100() { +int +x_user100() +{ more("etc/topusr100", YEA); return 0; } -int x_history() { +int +x_history() +{ more("etc/history", YEA); return 0; } #ifdef HAVE_X_BOARDS -static int x_boards() { +static int +x_boards() +{ more("etc/topboard.tmp", YEA); return 0; } #endif -int x_birth() { +int +x_birth() +{ more("etc/birth.today", YEA); return 0; } -int x_weather() { +int +x_weather() +{ more("etc/weather.tmp", YEA); return 0; } -int x_stock() { +int +x_stock() +{ more("etc/stock.tmp", YEA); return 0; } -int x_note() { +int +x_note() +{ more(fn_note_ans, YEA); return 0; } -int x_issue() { +int +x_issue() +{ more("etc/day", YEA); return 0; } -int x_week() { +int +x_week() +{ more("etc/week", YEA); return 0; } -int x_today() { +int +x_today() +{ more("etc/today", YEA); return 0; } -int x_yesterday() { +int +x_yesterday() +{ more("etc/yesterday", YEA); return 0; } -int x_login() { +int +x_login() +{ more("etc/Welcome_login.0", YEA); return 0; } #ifdef HAVE_INFO -static int x_program() { +static int +x_program() +{ more("etc/version", YEA); return 0; } #endif #ifdef HAVE_LICENSE -static int x_gpl() { +static int +x_gpl() +{ more("etc/GPL", YEA); return 0; } #endif -int note() { - static char *fn_note_tmp = "note.tmp"; - static char *fn_note_dat = "note.dat"; - int total = 0, i, collect, len; - struct stat st; - char buf[256], buf2[80]; - int fd, fx; - FILE *fp, *foo; +int +note() +{ + static char *fn_note_tmp = "note.tmp"; + static char *fn_note_dat = "note.dat"; + int total = 0, i, collect, len; + struct stat st; + char buf[256], buf2[80]; + int fd, fx; + FILE *fp, *foo; typedef struct notedata_t { - time_t date; - char userid[IDLEN + 1]; - char username[19]; - char buf[3][80]; - } notedata_t; - notedata_t myitem; - - if(cuser.money < 5) { + time_t date; + char userid[IDLEN + 1]; + char username[19]; + char buf[3][80]; + } notedata_t; + notedata_t myitem; + + if (cuser.money < 5) { outmsg("\033[1;41m «u§r! n§ë¤»È¤~¯à¯d¨¥...¨S¿úC..\033[m"); clrtoeol(); refresh(); return 0; } - setutmpmode(EDNOTE); do { myitem.buf[0][0] = myitem.buf[1][0] = myitem.buf[2][0] = '\0'; move(12, 0); clrtobot(); outs("\n§ë¤»È... ¹Í... ½Ð¯d¨¥ (¦Ü¦h¤T¦æ)¡A«ö[Enter]µ²§ô"); - for(i = 0; (i < 3) && getdata(16 + i, 0, "¡G", myitem.buf[i], - sizeof(myitem.buf[i])-5, DOECHO) - && *myitem.buf[i]; i++); + for (i = 0; (i < 3) && getdata(16 + i, 0, "¡G", myitem.buf[i], + sizeof(myitem.buf[i]) - 5, DOECHO) + && *myitem.buf[i]; i++); getdata(b_lines - 1, 0, "(S)Àx¦s (E)«·s¨Ó¹L (Q)¨ú®ø¡H[S] ", buf, 3, LCECHO); - if(buf[0] == 'q' || (i == 0 && *buf != 'e')) + if (buf[0] == 'q' || (i == 0 && *buf != 'e')) return 0; - } while(buf[0] == 'e'); + } while (buf[0] == 'e'); demoney(-5); strcpy(myitem.userid, cuser.userid); strncpy(myitem.username, cuser.username, 18); myitem.username[18] = '\0'; - myitem.date=now; + myitem.date = now; /* begin load file */ - if((foo = fopen(".note", "a")) == NULL) + if ((foo = fopen(".note", "a")) == NULL) return 0; - if((fp = fopen(fn_note_ans, "w")) == NULL) + if ((fp = fopen(fn_note_ans, "w")) == NULL) return 0; - if((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) + if ((fx = open(fn_note_tmp, O_WRONLY | O_CREAT, 0644)) <= 0) return 0; - if((fd = open(fn_note_dat, O_RDONLY)) == -1) + if ((fd = open(fn_note_dat, O_RDONLY)) == -1) total = 1; - else if(fstat(fd, &st) != -1) { + else if (fstat(fd, &st) != -1) { total = st.st_size / sizeof(notedata_t) + 1; if (total > MAX_NOTE) total = MAX_NOTE; } - fputs("\033[1;31;44m¡ó¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢t" "\033[37m»Ä²¢W»¶ªO\033[31m¢u¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¡ó" "\033[m\n", fp); collect = 1; - while(total) { + while (total) { sprintf(buf, "\033[1;31m¢~¢t\033[32m %s \033[37m(%s)", myitem.userid, myitem.username); len = strlen(buf); - for(i = len ; i < 73; i++) + for (i = len; i < 73; i++) strcat(buf, " "); sprintf(buf2, " \033[1;36m%.14s\033[31m ¢u¢¡\033[m\n", Cdate(&(myitem.date))); strcat(buf, buf2); fputs(buf, fp); - if(collect) + if (collect) fputs(buf, foo); - for(i = 0 ; i < 3 && *myitem.buf[i]; i++) { - fprintf(fp, "\033[1;31m¢x\033[m%-74.74s\033[1;31m¢x\033[m\n", + for (i = 0; i < 3 && *myitem.buf[i]; i++) { + fprintf(fp, "\033[1;31m¢x\033[m%-74.74s\033[1;31m¢x\033[m\n", myitem.buf[i]); - if(collect) + if (collect) fprintf(foo, "\033[1;31m¢x\033[m%-74.74s\033[1;31m¢x\033[m\n", myitem.buf[i]); - } + } fputs("\033[1;31m¢¢¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" - "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢£\033[m\n",fp); + "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢£\033[m\n", fp); - if(collect) { + if (collect) { fputs("\033[1;31m¢¢¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢£\033[m\n", foo); fclose(foo); collect = 0; } - write(fx, &myitem, sizeof(myitem)); - - if(--total) - read(fd, (char *) &myitem, sizeof(myitem)); + + if (--total) + read(fd, (char *)&myitem, sizeof(myitem)); } fputs("\033[1;31;44m¡ó¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" - "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¡ó\033[m\n",fp); + "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¡ó\033[m\n", fp); fclose(fp); close(fd); close(fx); @@ -234,92 +273,97 @@ int note() { return 0; } -static void mail_sysop() { - FILE *fp; - char genbuf[200]; - - if((fp = fopen("etc/sysop", "r"))) { - int i, j; - char *ptr; - +static void +mail_sysop() +{ + FILE *fp; + char genbuf[200]; + + if ((fp = fopen("etc/sysop", "r"))) { + int i, j; + char *ptr; + typedef struct sysoplist_t { - char userid[IDLEN + 1]; - char duty[40]; - } sysoplist_t; - sysoplist_t sysoplist[9]; - + char userid[IDLEN + 1]; + char duty[40]; + } sysoplist_t; + sysoplist_t sysoplist[9]; + j = 0; - while(fgets(genbuf, 128, fp)) { - if((ptr = strchr(genbuf, '\n'))) { + while (fgets(genbuf, 128, fp)) { + if ((ptr = strchr(genbuf, '\n'))) { *ptr = '\0'; - if((ptr = strchr(genbuf, ':'))) { + if ((ptr = strchr(genbuf, ':'))) { *ptr = '\0'; do { i = *++ptr; - } while(i == ' ' || i == '\t'); - if(i) { + } while (i == ' ' || i == '\t'); + if (i) { strcpy(sysoplist[j].userid, genbuf); strcpy(sysoplist[j++].duty, ptr); } } } } - + move(12, 0); clrtobot(); prints("%16s %-18sÅv³d¹º¤À\n\n", "½s¸¹", "¯¸ªø ID"); - for(i = 0; i < j; i++) + for (i = 0; i < j; i++) prints("%15d. \033[1;%dm%-16s%s\033[0m\n", - i + 1, 31 + i % 7, sysoplist[i].userid, sysoplist[i].duty); + i + 1, 31 + i % 7, sysoplist[i].userid, sysoplist[i].duty); prints("%-14s0. \033[1;%dmÂ÷¶}\033[0m", "", 31 + j % 7); getdata(b_lines - 1, 0, " ½Ð¿é¤J¥N½X[0]¡G", genbuf, 4, DOECHO); i = genbuf[0] - '0' - 1; - if(i >= 0 && i < j) { + if (i >= 0 && i < j) { clear(); do_send(sysoplist[i].userid, NULL); } } } -int m_sysop() { +int +m_sysop() +{ setutmpmode(MSYSOP); mail_sysop(); return 0; } -int Goodbye() { - char genbuf[100]; +int +Goodbye() +{ + char genbuf[100]; getdata(b_lines - 1, 0, "±z½T©wnÂ÷¶}¡i " BBSNAME " ¡j¶Ü(Y/N)¡H[N] ", genbuf, 3, LCECHO); - if(*genbuf != 'y') + if (*genbuf != 'y') return 0; movie(999); - if(cuser.userlevel) { + if (cuser.userlevel) { getdata(b_lines - 1, 0, "(G)ÀH·¦Ó³u (M)¦«¹Ú¯¸ªø (N)»Ä²¢W»¶¬y¨¥ªO¡H[G] ", genbuf, 3, LCECHO); - if(genbuf[0] == 'm') + if (genbuf[0] == 'm') mail_sysop(); - else if(genbuf[0] == 'n') + else if (genbuf[0] == 'n') note(); } - clear(); prints("\033[1;36m¿Ë·Rªº \033[33m%s(%s)\033[36m¡A§O§Ñ¤F¦A«×¥úÁ{\033[45;33m" " %s \033[40;36m¡I\n¥H¤U¬O±z¦b¯¸¤ºªºµù¥U¸ê®Æ:\033[0m\n", cuser.userid, cuser.username, BBSName); user_display(&cuser, 0); pressanykey(); - - more("etc/Logout",NA); + + more("etc/Logout", NA); pressanykey(); u_exit("EXIT "); - return QUIT; + return QUIT; } /* ¤ä´©¥~±¾µ{¦¡ : tin¡Bgopher¡Bwww¡Bbbsnet¡Bgame¡Bcsh */ @@ -334,36 +378,46 @@ int Goodbye() { #define MAXPATHLEN 256 #ifdef HAVE_TIN -static int x_tin() { +static int +x_tin() +{ clear(); return exec_cmd(NEWS, YEA, "bin/tin.sh", "TIN"); } #endif #ifdef HAVE_GOPHER -static int x_gopher() { +static int +x_gopher() +{ clear(); return exec_cmd(GOPHER, YEA, "bin/gopher.sh", "GOPHER"); } #endif #ifdef HAVE_WWW -static int x_www() { +static int +x_www() +{ return exec_cmd(WWW, NA, "bin/www.sh", "WWW"); } #endif #ifdef HAVE_IRC -static int x_irc() { +static int +x_irc() +{ return exec_cmd(XMODE, NA, "bin/irc.sh", "IRC"); } #endif #ifdef HAVE_ARCHIE -static int x_archie() { - char buf[STRLEN], ans[4]; - char genbuf1[100], genbuf2[200]; - char *s; +static int +x_archie() +{ + char buf[STRLEN], ans[4]; + char genbuf1[100], genbuf2[200]; + char *s; setutmpmode(ARCHIE); clear(); @@ -373,18 +427,17 @@ static int x_archie() { outs("\n½Ð¿é¤J±ý·j´Mªº¦r¦ê, ©Îª½±µ«ö <ENTER> ¨ú®ø¡C\n"); outs("\n coder by Harimau\n"); outs(" modified by Leeym\n"); - getdata(13,0,"·j´M¦r¦ê¡G",buf,20,DOECHO,0); - if(buf[0]=='\0') { + getdata(13, 0, "·j´M¦r¦ê¡G", buf, 20, DOECHO, 0); + if (buf[0] == '\0') { prints("\n¨ú®ø·j´M.....\n"); pressanykey(); return; } - - for(s = buf; *s != '\0'; s++) { - if(isspace(*s)) { - prints("\n¤@¦¸¥u¯à·j´M¤@Ó¦r¦ê°Õ, ¤£¯à¤Ó³g¤ß³á!!"); - pressanykey(); - return; + for (s = buf; *s != '\0'; s++) { + if (isspace(*s)) { + prints("\n¤@¦¸¥u¯à·j´M¤@Ó¦r¦ê°Õ, ¤£¯à¤Ó³g¤ß³á!!"); + pressanykey(); + return; } } bbssetenv("ARCHIESTRING", buf); @@ -392,14 +445,14 @@ static int x_archie() { log_usies("ARCHIE", ""); strcpy(genbuf1, buf); sprintf(buf, BBSHOME "/tmp/archie.%s", cuser.userid); - if(dashf(buf)) { + if (dashf(buf)) { getdata(0, 0, "n±Nµ²ªG±H¦^«H½c¶Ü(Y/N)¡H[N]", ans, sizeof(ans), DOECHO, 0); - if(*ans == 'y') { - fileheader_t mhdr; - char title[128], buf1[80]; - FILE* fp; - + if (*ans == 'y') { + fileheader_t mhdr; + char title[128], buf1[80]; + FILE *fp; + sethomepath(buf1, cuser.userid); stampfile(buf1, &mhdr); strcpy(mhdr.owner, cuser.userid); @@ -410,8 +463,8 @@ static int x_archie() { append_record(title, &mhdr, sizeof(mhdr)); Link(buf, buf1); } - more( buf, YEA); - unlink (buf); + more(buf, YEA); + unlink(buf); } } -#endif /* HAVE_ARCHIE */ +#endif /* HAVE_ARCHIE */ |