summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-07-10 19:50:42 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-07-10 19:50:42 +0800
commit9351e5d49572d05a6aa21309daa315434def299c (patch)
tree0549097b74134403f1307136d2006881394d9a71
parent8d16862e885b22d24432996c8e3039a34b910f2a (diff)
downloadpttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar.gz
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar.bz2
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar.lz
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar.xz
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.tar.zst
pttbbs-9351e5d49572d05a6aa21309daa315434def299c.zip
reindentptt.fpg@2121
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2121 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/account.c312
1 files changed, 134 insertions, 178 deletions
diff --git a/util/account.c b/util/account.c
index 6c05b569..ce7e5f94 100644
--- a/util/account.c
+++ b/util/account.c
@@ -1,45 +1,42 @@
/* $Id$ */
#include "bbs.h"
-//test
+// test
#define ACCOUNT_MAX_LINE 16
#define ADJUST_M 6 /* adjust back 5 minutes */
void
-reset_garbage()
+reset_garbage(void)
{
- if (SHM == NULL)
- {
+ if (SHM == NULL) {
attach_SHM();
if (SHM->Ptouchtime == 0)
SHM->Ptouchtime = 1;
}
-
-/* 不整個reload?
- for(n=0;n<=SHM->max_film;n++)
- printf("\n**%d**\n %s \n",n,SHM->notes[n]);
- */
+ /*
+ * 不整個reload? for(n=0;n<=SHM->max_film;n++) printf("\n**%d**\n %s
+ * \n",n,SHM->notes[n]);
+ */
SHM->Puptime = 0;
reload_pttcache();
printf("\n動態看板數[%d]\n", SHM->max_film);
-/*
- for(n=0; n<MAX_MOVIE_SECTION; n++)
- printf("sec%d=> 起點:%d 下次要換的:%d\n ",n,SHM->n_notes[n],
- SHM->next_refresh[n]);
- printf("\n");
-*/
+ /*
+ * for(n=0; n<MAX_MOVIE_SECTION; n++) printf("sec%d=> 起點:%d
+ * 下次要換的:%d\n ",n,SHM->n_notes[n], SHM->next_refresh[n]);
+ * printf("\n");
+ */
}
void
keeplog(fpath, board, title)
- char *fpath;
- char *board;
- char *title;
+ char *fpath;
+ char *board;
+ char *title;
{
- fileheader_t fhdr;
- int bid;
- char genbuf[256], buf[256];
+ fileheader_t fhdr;
+ int bid;
+ char genbuf[256], buf[256];
if (!board)
board = "Record";
@@ -49,57 +46,58 @@ keeplog(fpath, board, title)
stampfile(genbuf, &fhdr);
sprintf(buf, "mv %s %s", fpath, genbuf);
system(buf);
-/*
- printf("keep record:[%s][%s][%s][%s]\n",fpath, board, title,genbuf);
-*/
+ /*
+ * printf("keep record:[%s][%s][%s][%s]\n",fpath, board, title,genbuf);
+ */
strcpy(fhdr.title, title);
strcpy(fhdr.owner, "[歷史老師]");
sprintf(genbuf, "boards/%c/%s/.DIR", board[0], board);
append_record(genbuf, &fhdr, sizeof(fhdr));
/* XXX: bid of cache.c's getbnum starts from 1 */
- if((bid = getbnum(board)) > 0)
+ if ((bid = getbnum(board)) > 0)
touchbtotal(bid);
}
static void
my_outs(fp, buf, mode)
- FILE *fp;
- char buf[], mode;
+ FILE *fp;
+ char buf[], mode;
{
- static char state = '0';
+ static char state = '0';
if (state != mode)
fprintf(fp, "[3%cm", state = mode);
- if (buf[0])
- {
+ if (buf[0]) {
fprintf(fp, buf);
buf[0] = 0;
}
}
-void gzip(source, target, stamp)
- char *source, *target, *stamp;
+void
+gzip(source, target, stamp)
+ char *source, *target, *stamp;
{
- char buf[128];
+ char buf[128];
sprintf(buf, "gzip -f9n adm/%s%s", target, stamp);
rename(source, &buf[14]);
system(buf);
}
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
{
- int hour, max, item, total, i, j, mo, da, max_user = 0, max_login = 0,
- max_reg = 0, mahour = 0, k, wday;
- char *act_file = ".act";
- char *log_file = "usies";
- char *wday_str = "UMTWRFS";
- char buf[256], buf1[256], *p;
- FILE *fp, *fp1;
- int act[27]; /* 次數/累計時間/pointer */
- time_t now;
- struct tm *ptime;
+ int hour, max, item, total, i, j, mo, da, max_user = 0,
+ max_login = 0, max_reg = 0, mahour = 0, k, wday;
+ char *act_file = ".act";
+ char *log_file = "usies";
+ char *wday_str = "UMTWRFS";
+ char buf[256], buf1[256], *p;
+ FILE *fp, *fp1;
+ int act[27]; /* 次數/累計時間/pointer */
+ time_t now;
+ struct tm *ptime;
attach_SHM();
nice(10);
@@ -109,36 +107,30 @@ int main(int argc, char **argv)
memset(act, 0, sizeof(act));
printf("次數/累計時間\n");
- if ((ptime->tm_hour != 0) && (fp = fopen(act_file, "r")))
- {
+ if ((ptime->tm_hour != 0) && (fp = fopen(act_file, "r"))) {
fread(act, sizeof(act), 1, fp);
fclose(fp);
}
- if ((fp = fopen(log_file, "r")) == NULL)
- {
+ if ((fp = fopen(log_file, "r")) == NULL) {
printf("cann't open usies\n");
return 1;
}
if (act[26])
fseek(fp, act[26], 0);
- while (fgets(buf, 256, fp))
- {
- buf[11+2]=0;
+ while (fgets(buf, 256, fp)) {
+ buf[11 + 2] = 0;
hour = atoi(buf + 11);
- if (hour < 0 || hour > 23)
- {
+ if (hour < 0 || hour > 23) {
continue;
}
-//"09/06/1999 17:44:58 Mon "
-// 012345678901234567890123
- if (strstr(buf + 20, "ENTER"))
- {
+ //"09/06/1999 17:44:58 Mon "
+ // 012345678901234567890123
+ if (strstr(buf + 20, "ENTER")) {
act[hour]++;
continue;
}
- if ((p = (char *) strstr(buf + 40, "Stay:")))
- {
- if((hour = atoi(p + 5))) {
+ if ((p = (char *)strstr(buf + 40, "Stay:"))) {
+ if ((hour = atoi(p + 5))) {
act[24] += hour;
act[25]++;
}
@@ -147,50 +139,39 @@ int main(int argc, char **argv)
}
act[26] = ftell(fp);
fclose(fp);
- for (i = max = total = 0; i < 24; i++)
- {
+ for (i = max = total = 0; i < 24; i++) {
total += act[i];
- if (act[i] > max)
- {
+ if (act[i] > max) {
max_user = max = act[i];
mahour = i;
}
}
item = max / ACCOUNT_MAX_LINE + 1;
- if (!ptime->tm_hour)
- {
+ if (!ptime->tm_hour) {
keeplog("etc/today", "Record", "上站人次統計");
keeplog("etc/money", "Security", "本日金錢往來記錄");
keeplog("etc/illegal_money", "Security", "本日違法賺錢記錄");
keeplog("etc/chicken", "Record", "雞場報告");
}
-
printf("上站人次統計\n");
- if ((fp = fopen("etc/today", "w")) == NULL)
- {
+ if ((fp = fopen("etc/today", "w")) == NULL) {
printf("cann't open etc/today\n");
return 1;
}
fprintf(fp, "\t\t\t 每小時上站人次統計 [%02d/%02d/%02d] \n\n", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
- for (i = ACCOUNT_MAX_LINE + 1; i > 0; i--)
- {
+ for (i = ACCOUNT_MAX_LINE + 1; i > 0; i--) {
strcpy(buf, " ");
- for (j = 0; j < 24; j++)
- {
+ for (j = 0; j < 24; j++) {
max = item * i;
hour = act[j];
- if (hour && (max > hour) && (max - item <= hour))
- {
+ if (hour && (max > hour) && (max - item <= hour)) {
my_outs(fp, buf, '3');
fprintf(fp, "%-3d", hour / 10);
- }
- else if (max <= hour)
- {
+ } else if (max <= hour) {
my_outs(fp, buf, '4');
fprintf(fp, "█ ");
- }
- else
+ } else
strcat(buf, " ");
}
fprintf(fp, "\n");
@@ -201,12 +182,11 @@ int main(int argc, char **argv)
fprintf(fp, " 總共上站人次:%-7d平均使用人數:%d\n", total, total / 24);
fclose(fp);
- if((fp = fopen(act_file, "w"))) {
+ if ((fp = fopen(act_file, "w"))) {
fwrite(act, sizeof(act), 1, fp);
fclose(fp);
}
-
-/* -------------------------------------------------------------- */
+ /* -------------------------------------------------------------- */
sprintf(buf, "-%02d%02d%02d",
ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday);
@@ -215,104 +195,89 @@ int main(int argc, char **argv)
printf("歷史事件處理\n");
-/* Ptt 歷史事件處理 */
- if((fp = fopen("etc/history.data", "r"))) { /*最多同時上線 */
- if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k))
- {
- int a;
+ /* Ptt 歷史事件處理 */
+ if ((fp = fopen("etc/history.data", "r"))) { /* 最多同時上線 */
+ if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k)) {
+ int a;
resolve_fcache();
printf("此時段最多同時上線:%d 過去:%d\n", a = SHM->max_user, k);
fclose(fp);
- if (a > k)
- {
+ if (a > k) {
ptime = localtime(&SHM->max_time);
- if((fp1 = fopen("etc/history", "a")))
- {
+ if ((fp1 = fopen("etc/history", "a"))) {
fprintf(fp1,
"◎ 【%02d/%02d/%02d %02d:%02d】"
- "同時在坊內人數首次達到 %d 人次\n",
- ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100,
+ "同時在坊內人數首次達到 %d 人次\n",
+ ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100,
ptime->tm_hour, ptime->tm_min, a);
fclose(fp1);
}
- if((fp = fopen("etc/history.data", "w")))
- {
+ if ((fp = fopen("etc/history.data", "w"))) {
fprintf(fp, "%d %d %d %d", max_login, max, max_reg, a);
fclose(fp);
}
}
- }
- else
+ } else
fclose(fp);
}
ptime = localtime(&now);
- if (ptime->tm_hour)
- {
+ if (ptime->tm_hour) {
/* rotate one line in today_is */
puts("多個節日處理");
- if((fp1 = fopen("etc/today_is", "r"))) {
- char tod[100][20];
-
+ if ((fp1 = fopen("etc/today_is", "r"))) {
+ char tod[100][20];
+
i = 0;
- while(i < 100 && fgets(tod[i], sizeof(tod[0]), fp1))
+ 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++)
+ for (j = 0; j < i; j++)
fputs(tod[j + 1 < i ? j + 1 : 0], fp1);
fclose(fp1);
}
}
-
-
- if (!ptime->tm_hour)
- {
+ if (!ptime->tm_hour) {
keeplog(".note", "Record", "心情留言版");
system("/bin/cp etc/today etc/yesterday");
-/* system("rm -f note.dat"); */
-/* Ptt */
+ /* system("rm -f note.dat"); */
+ /* Ptt */
sprintf(buf1, "[公安報告] 使用者上線監控 [%02d/%02d:%02d]"
,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour);
keeplog("usies", "Security", buf1);
printf("[公安報告] 使用者上線監控\n");
gzip(log_file, "usies", buf);
printf("壓縮使用者上線監控\n");
-/* Ptt 歷史事件處理 */
+ /* Ptt 歷史事件處理 */
now = time(NULL) - ADJUST_M * 60; /* back to ancent */
ptime = localtime(&now);
attach_SHM();
- if((fp = fopen("etc/history.data", "r")))
- { /* 單日最多次人次,同時上線,註冊 */
- if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k))
- {
+ if ((fp = fopen("etc/history.data", "r"))) { /* 單日最多次人次,同時上線
+ * ,註冊 */
+ if (fscanf(fp, "%d %d %d %d", &max_login, &max, &max_reg, &k)) {
fp1 = fopen("etc/history", "r+");
fseek(fp1, 0, 2);
- if (max_user > max)
- {
+ if (max_user > max) {
fprintf(fp1, "◇ 【%02d/%02d/%02d %02d】 "
- "單一小時上線人次首次達到 %d 人次 \n"
+ "單一小時上線人次首次達到 %d 人次 \n"
,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, mahour, max_user);
max = max_user;
}
- if (total > max_login)
- {
+ if (total > max_login) {
fprintf(fp1, "◆ 【%02d/%02d/%02d】 "
- "單日上線人次首次達到 %d 人次 \n"
+ "單日上線人次首次達到 %d 人次 \n"
,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, total);
max_login = total;
}
-
- if (SHM->number > max_reg + max_reg / 10)
- {
+ if (SHM->number > max_reg + max_reg / 10) {
fprintf(fp1, "★ 【%02d/%02d/%02d】 "
"總註冊人數提升到 %d 人 \n"
,ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_year % 100, SHM->number);
max_reg = SHM->number;
}
-
fclose(fp1);
}
fclose(fp);
@@ -325,43 +290,42 @@ int main(int argc, char **argv)
/* Ptt 節日處理 */
printf("節日處理\n");
- if((fp1 = fopen("etc/today_is", "w"))) {
+ if ((fp1 = fopen("etc/today_is", "w"))) {
i = 0;
- if((fp = fopen("etc/feast", "r"))) {
- while(fgets(buf1, sizeof(buf1), fp)) {
- if(buf[0] != '#' &&
- sscanf(buf1, "%d %c%c", &mo, buf, buf+1) == 3) {
- if (isdigit(buf[0])) {
- if (isdigit(buf[1])) {
- da = 10 * (buf[0] - '0') + (buf[1] - '0');
- if(ptime->tm_mday == da && ptime->tm_mon + 1 == mo) {
- i = 1;
- fprintf(fp1, "%-14.14s", &buf1[6]);
- }
- }
- else {
- if (buf[0] - '0' <= 4) {
- wday = 0;
- buf[1] = toupper(buf[1]);
- while(wday < 7 && buf[1] != *(wday_str + wday))
- wday++;
- if (ptime->tm_mon + 1 == mo && ptime->tm_wday == wday &&
- (ptime->tm_mday - 1)/7 + 1 == (buf[0] - '0')) {
- i = 1;
- fprintf(fp1, "%-14.14s", &buf1[6]);
- }
- }
- }
- }
+ if ((fp = fopen("etc/feast", "r"))) {
+ while (fgets(buf1, sizeof(buf1), fp)) {
+ if (buf[0] != '#' &&
+ sscanf(buf1, "%d %c%c", &mo, buf, buf + 1) == 3) {
+ if (isdigit(buf[0])) {
+ if (isdigit(buf[1])) {
+ da = 10 * (buf[0] - '0') + (buf[1] - '0');
+ if (ptime->tm_mday == da && ptime->tm_mon + 1 == mo) {
+ i = 1;
+ fprintf(fp1, "%-14.14s", &buf1[6]);
+ }
+ } else {
+ if (buf[0] - '0' <= 4) {
+ wday = 0;
+ buf[1] = toupper(buf[1]);
+ while (wday < 7 && buf[1] != *(wday_str + wday))
+ wday++;
+ if (ptime->tm_mon + 1 == mo && ptime->tm_wday == wday &&
+ (ptime->tm_mday - 1) / 7 + 1 == (buf[0] - '0')) {
+ i = 1;
+ fprintf(fp1, "%-14.14s", &buf1[6]);
+ }
+ }
+ }
+ }
}
}
fclose(fp);
}
printf("節日處理1\n");
- if(i == 0) {
- if((fp = fopen("etc/today_boring", "r"))) {
- while(fgets(buf1, sizeof(buf1), fp))
- if(strlen(buf1) > 3)
+ if (i == 0) {
+ if ((fp = fopen("etc/today_boring", "r"))) {
+ while (fgets(buf1, sizeof(buf1), fp))
+ if (strlen(buf1) > 3)
fprintf(fp1, "%s", buf1);
fclose(fp);
} else
@@ -369,17 +333,13 @@ int main(int argc, char **argv)
}
fclose(fp1);
}
-
/* Ptt 歡迎畫面處理 */
printf("歡迎畫面處理\n");
- if((fp = fopen("etc/Welcome.date", "r")))
- {
- char temp[50];
- while (fscanf(fp, "%d %d %s\n", &mo, &da, buf1) != EOF)
- {
- if (ptime->tm_mday == da && ptime->tm_mon + 1 == mo)
- {
+ if ((fp = fopen("etc/Welcome.date", "r"))) {
+ char temp[50];
+ while (fscanf(fp, "%d %d %s\n", &mo, &da, buf1) != EOF) {
+ if (ptime->tm_mday == da && ptime->tm_mon + 1 == mo) {
strcpy(temp, buf1);
sprintf(buf1, "cp -f etc/Welcomes/%s etc/Welcome", temp);
system(buf1);
@@ -389,34 +349,30 @@ int main(int argc, char **argv)
fclose(fp);
}
printf("歡迎畫面處理\n");
- if (ptime->tm_wday == 0)
- {
+ if (ptime->tm_wday == 0) {
keeplog("etc/week", "Record", "本週熱門話題");
gzip("bbslog", "bntplink", buf);
gzip("innd/bbslog", "innbbsd", buf);
gzip("etc/mailog", "mailog", buf);
}
-
if (ptime->tm_mday == 1)
keeplog("etc/month", "Record", "本月熱門話題");
if (ptime->tm_yday == 1)
keeplog("etc/year", "Record", "年度熱門話題");
- }
- else if (ptime->tm_hour == 3 && ptime->tm_wday == 6)
- {
- char *fn1 = "tmp";
- char *fn2 = "suicide";
+ } else if (ptime->tm_hour == 3 && ptime->tm_wday == 6) {
+ char *fn1 = "tmp";
+ char *fn2 = "suicide";
rename(fn1, fn2);
mkdir(fn1, 0755);
sprintf(buf, "tar cfz adm/%s-%02d%02d%02d.tgz %s",
- fn2, ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, fn2);
+ fn2, ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, fn2);
system(buf);
sprintf(buf, "/bin/rm -fr %s", fn2);
system(buf);
}
-/* Ptt reset Ptt's share memory */
+ /* Ptt reset Ptt's share memory */
printf("重設Pttcache 與fcache\n");
SHM->Puptime = 0;
@@ -424,9 +380,9 @@ int main(int argc, char **argv)
reset_garbage();
printf("計算進站畫面數: ");
- for( i = 0 ; i < 5 ; ++i ){
+ for (i = 0; i < 5; ++i) {
sprintf(buf, "etc/Welcome_login.%d", i);
- if( access(buf, 0) < 0 )
+ if (access(buf, 0) < 0)
break;
}
printf("%d\n", SHM->GV2.e.nWelcomes = i);