diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-01-16 21:28:48 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-01-16 21:28:48 +0800 |
commit | f20ec866a1837924674452effdd1bc99df77e258 (patch) | |
tree | cdff800c75bdacefb68fbc180b4d0610cd4b990d /mbbsd/syspost.c | |
parent | ab3ed372972ab2a54d56914c7696412da1a38f48 (diff) | |
download | pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar.gz pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar.bz2 pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar.lz pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar.xz pttbbs-f20ec866a1837924674452effdd1bc99df77e258.tar.zst pttbbs-f20ec866a1837924674452effdd1bc99df77e258.zip |
move post_msg() and post_file() from gamble.c to syspost.c
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@608 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/syspost.c')
-rw-r--r-- | mbbsd/syspost.c | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/mbbsd/syspost.c b/mbbsd/syspost.c index 36939485..a44ffdb3 100644 --- a/mbbsd/syspost.c +++ b/mbbsd/syspost.c @@ -1,6 +1,59 @@ -/* $Id: syspost.c,v 1.16 2002/11/15 05:56:10 lwms Exp $ */ +/* $Id: syspost.c,v 1.17 2003/01/16 13:28:48 kcwu Exp $ */ #include "bbs.h" +int +post_msg(char *bname, char *title, char *msg, char *author) +{ + FILE *fp; + int bid; + fileheader_t fhdr; + char genbuf[256]; + + /* 在 bname 板發表新文章 */ + snprintf(genbuf, sizeof(genbuf), "boards/%c/%s", bname[0], bname); + stampfile(genbuf, &fhdr); + fp = fopen(genbuf, "w"); + + if (!fp) + return -1; + + fprintf(fp, "作者: %s 看板: %s\n標題: %s \n", author, bname, title); + fprintf(fp, "時間: %s\n", ctime(&now)); + + /* 文章的內容 */ + fprintf(fp, "%s", msg); + fclose(fp); + + /* 將檔案加入列表 */ + strlcpy(fhdr.title, title, sizeof(fhdr.title)); + strlcpy(fhdr.owner, author, sizeof(fhdr.owner)); + 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 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; +} + void post_change_perm(int oldperm, int newperm, char *sysopid, char *userid) { |