From f0d604f8f201acd2360bceb8db3cfef99164a4a5 Mon Sep 17 00:00:00 2001 From: scw Date: Mon, 4 Jun 2007 07:08:34 +0000 Subject: Log angel changing action and report every week git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3532 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/angel.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'util/angel.c') diff --git a/util/angel.c b/util/angel.c index e434a46b..c12cb555 100644 --- a/util/angel.c +++ b/util/angel.c @@ -26,6 +26,7 @@ int RejCmp(const void * a, const void * b){ void readData(); void sendResult(); +void slurp(FILE* to, FILE* from); int main(int argc, char* argv[]){ if (argc > 1) @@ -109,7 +110,7 @@ int mailalertuser(char* userid) if (userid[0] && (uentp = search_ulist_userid(userid))) uentp->alerts|=ALERT_NEW_MAIL; return 0; -} +} void sendResult(){ int i; @@ -164,6 +165,17 @@ void sendResult(){ } if (i % 4 != 0) fputc('\n', fp); + { + FILE* changefp = fopen(BBSHOME "/log/changeangel.log", "r"); + if (changefp) { + remove(BBSHOME "/log/changeangel.log"); + + fputs("\n== 本周更換小天使紀錄 ==\n", fp); + slurp(fp, changefp); + fclose(changefp); + } + } + fputs("\n--\n\n 本資料由 angel 程式產生\n\n", fp); fclose(fp); @@ -174,4 +186,22 @@ void sendResult(){ mailalertuser(mailto); } +void slurp(FILE* to, FILE* from) +{ + char buf[4096]; // 4K block + int count; + + while ((count = fread(buf, 1, sizeof(buf), from)) > 0) { + char * p = buf; + while (count > 0) { + int i = fwrite(p, 1, count, to); + + if (i <= 0) return; + + p += i; + count -= i; + } + } +} + #endif /* defined PLAY_ANGEL */ -- cgit v1.2.3