diff options
-rw-r--r-- | pttbbs/util/Makefile | 2 | ||||
-rw-r--r-- | pttbbs/util/removebm.c | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 539d5a85..2ede206b 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -22,7 +22,7 @@ CPROG_WITH_UTIL= \ outmail chkhbf merge_dir \ angel gamblegive \ chesscountry tunepasswd buildir xchatd \ - uhash_loader timecap_buildref showuser + uhash_loader timecap_buildref showuser removebm # 下面是 C++ 的程式 CPP_WITH_UTIL= \ diff --git a/pttbbs/util/removebm.c b/pttbbs/util/removebm.c new file mode 100644 index 00000000..5a3308e6 --- /dev/null +++ b/pttbbs/util/removebm.c @@ -0,0 +1,76 @@ +/* $Id $ */ +#define _UTIL_C_ +#include "bbs.h" + +/* Remove an user from any BM of existing boards */ + +int check(void *data, int bid, boardheader_t *bh) +{ + char changed = 0; + char has_quote = 0; + char *p; + const char *userid = (const char *) data; + char bmsrc[IDLEN * 3 + 3], bmout[IDLEN * 3 + 3] = ""; + if (!bh->brdname[0] || !bh->BM[0]) + return 0; + + strlcpy(bmsrc, bh->BM, sizeof(bmsrc)); + p = bmsrc; + + if (*p == '[') { + p++; + has_quote = 1; + } + p = strtok(p,"/ ]"); + + while (p) { + const char *bmid = p; + p = strtok(NULL, "/ ]"); + + if (!*bmid) + continue; + + if (strcasecmp(bmid, userid) == 0) { + // found match, to remove it + changed = 1; + continue; + } + if (bmout[0]) + strlcat(bmout, "/", sizeof(bmout)); + strlcat(bmout, bmid, sizeof(bmout)); + } + + if (!changed) + return 0; + + printf("%s: %s -> %s\n", bh->brdname, bh->BM, bmout); + + if (has_quote) + snprintf(bh->BM, sizeof(bh->BM), "[%s]", bmout); + else + strlcpy(bh->BM, bmout, sizeof(bh->BM)); + + substitute_record(BBSHOME "/" FN_BOARD, bh, sizeof(boardheader_t), bid); + reset_board(bid); + return 0; +} + +int main(int argc, char **argv) +{ + int i = 0; + + now = time(NULL); + chdir(BBSHOME); + attach_SHM(); + + if (argc != 2) { + printf("syntax: %s userid\n", argv[0]); + return -1; + } + + for (i = 0; i < MAX_BOARD; i++) { + check(argv[1], i+1, &SHM->bcache[i]); + } + + return 0; +} |