diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-10-04 22:54:32 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2010-10-04 22:54:32 +0800 |
commit | 02d436796f896224b718af6a773c967122c50d08 (patch) | |
tree | f9225472da60ed6574af318c88ddb82e0e62cce0 | |
parent | 96d37985071cfd5c22f96905d2f559ac89528e9c (diff) | |
download | pttbbs-02d436796f896224b718af6a773c967122c50d08.tar pttbbs-02d436796f896224b718af6a773c967122c50d08.tar.gz pttbbs-02d436796f896224b718af6a773c967122c50d08.tar.bz2 pttbbs-02d436796f896224b718af6a773c967122c50d08.tar.lz pttbbs-02d436796f896224b718af6a773c967122c50d08.tar.xz pttbbs-02d436796f896224b718af6a773c967122c50d08.tar.zst pttbbs-02d436796f896224b718af6a773c967122c50d08.zip |
Simplify today's holiday storage/rotation
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5109 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/common/bbs/cache.c | 8 | ||||
-rw-r--r-- | pttbbs/util/account.c | 54 | ||||
-rw-r--r-- | pttbbs/util/uhash_loader.c | 1 |
3 files changed, 34 insertions, 29 deletions
diff --git a/pttbbs/common/bbs/cache.c b/pttbbs/common/bbs/cache.c index 7160cdbe..592c732c 100644 --- a/pttbbs/common/bbs/cache.c +++ b/pttbbs/common/bbs/cache.c @@ -811,14 +811,6 @@ reload_pttcache(void) } SHM->last_film = id - 1; - 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); - } /* 等所有資料更新後再設定 uptime */ SHM->Puptime = SHM->Ptouchtime; diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 4d103a19..a2e8b9f8 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -320,15 +320,44 @@ out: return 0; } +static int +update_holiday(struct tm *ptime) +{ + int i = 0, cnt = 0; + char buf[128], *p; + FILE *fp; + + if ((fp = fopen("etc/today_is", "r")) == NULL) + return 1; + + for (i = 0; i < ptime->tm_hour; i++) { + if (!fgets(buf, sizeof(buf), fp)) { + cnt = i; + i = i - 1 + (ptime->tm_hour - i) / cnt * cnt; + rewind(fp); + } + } + + fclose(fp); + + if ((p = strchr(buf, '\n'))) + *p = 0; + + memset(SHM->today_is, 0, sizeof(SHM->today_is)); + strlcpy(SHM->today_is, buf, sizeof(SHM->today_is)); + + return 0; +} + int main(int argc, char **argv) { - int i, j; + int i; int mo, da; int peak_hour_login, peak_hour, day_login; const char const log_file[] = "usies"; char buf[256], buf1[256]; - FILE *fp, *fp1; + FILE *fp; int act[27]; /* 次數/累計時間/pointer */ time_t now; struct tm tm_now, tm_adjusted; @@ -366,25 +395,6 @@ main(int argc, char **argv) /* Ptt 歷史事件處理 */ update_history(&tm_adjusted, peak_hour, peak_hour_login, day_login); - if (tm_now.tm_hour) { - /* rotate one line in today_is */ - /* XXX totally meaningless, it is only relative sequence since rotate, not mapping to real time */ - puts("多個節日處理"); - if ((fp1 = fopen("etc/today_is", "r"))) { - char tod[100][20]; - - i = 0; - while (i < 100 && fgets(tod[i], sizeof(tod[0]), fp1)) - i++; - fclose(fp1); - - fp1 = fopen("etc/today_is", "w"); - for (j = 0; j < i; j++) - fputs(tod[j + 1 < i ? j + 1 : 0], fp1); - fclose(fp1); - } - } - if (tm_now.tm_hour == 0) { system("/bin/cp etc/today etc/yesterday"); /* system("rm -f note.dat"); */ @@ -455,6 +465,8 @@ main(int argc, char **argv) /* Ptt reset Ptt's share memory */ printf("重設cache 與fcache\n"); + update_holiday(&tm_now); + SHM->Puptime = 0; resolve_fcache(); reset_garbage(); diff --git a/pttbbs/util/uhash_loader.c b/pttbbs/util/uhash_loader.c index 4fac0b21..aeca4cd4 100644 --- a/pttbbs/util/uhash_loader.c +++ b/pttbbs/util/uhash_loader.c @@ -59,6 +59,7 @@ void load_uhash(void) { if( SHM->number == 0 && SHM->loaded == 0 ){ SHM->loaded = 0; fill_uhash(0); + SHM->today_is[0] = '\0'; SHM->loaded = 1; } else{ |