int draw_title(int menu, int now, int old, int again, int mode) { char buf[128]; int i, fd; int page; char fpath[128]; char bname[64]; if (again) { if (hdr_spool) free(hdr_spool); strcpy(bname, news[menu]); bname[IDLEN-1] = '\0'; sprintf(fpath, BRD_NEWS"%s/@/@%s", site_name[site], bname); news_count[menu] = rec_num(fpath, sizeof(HDR)); hdr_spool = (HDR *)malloc(sizeof(HDR) * news_count[menu]); fd = open(fpath, O_RDONLY); read(fd, hdr_spool, (sizeof(HDR) * news_count[menu])); close(fd); memset(buf, 0, sizeof(buf)); page = now / MAX_TITLE; for (i = page * MAX_TITLE ;i < (page + 1) * MAX_TITLE && i < news_count[menu];i++) { move(TITLE_TOP + (i % MAX_TITLE), TITLE_LEFT); clrtoeol(); #if 0 prints("%s%2d) %-5.5s %-53.53s%s", ORG_BAR, i + 1, hdr_spool[i].date + 3, hdr_spool[i].title, ORG_BAR); #else #ifdef HYPER prints("%s[200m[441;1437m\033[508m\033[300m%2d\033[303m) %-59.55s%s[201m", ORG_BAR, i + 1, hdr_spool[i].title, ORG_BAR); #else prints("%s%2d) %-59.55s%s", ORG_BAR, i + 1, hdr_spool[i].title, ORG_BAR); #endif #endif } if (page == news_count[menu] / MAX_TITLE) for (i = news_count[menu] % MAX_TITLE;i < MAX_TITLE;i++) { move(TITLE_TOP + i, TITLE_LEFT); prints("\033[m"); clrtoeol(); } if (news_count[menu] == 0) { move(TITLE_TOP + 4, TITLE_LEFT); prints(" \033[37;41;1m ¥»₪י©|µL·s»D \033[37;40m"); clrtoeol(); } } else { move(TITLE_TOP + (old % MAX_TITLE), TITLE_LEFT); #if 0 prints("%s%2d) %-5.5s %-53.53s%s", ORG_BAR, old + 1, hdr_spool[old].date + 3, hdr_spool[old].title, ORG_BAR); #else #ifdef HYPER prints("%s[200m\033[441;1437m\033[508m\033[300m%2d\033[303m) %-59.58s%s[m[201m", ORG_BAR, old + 1, hdr_spool[old].title, ORG_BAR); #else prints("%s%2d) %-59.55s%s", ORG_BAR, old + 1, hdr_spool[old].title, ORG_BAR); #endif #endif } if (mode == 1) { move(TITLE_TOP + (now % MAX_TITLE), TITLE_LEFT); #if 0 prints("%s%2d) %-5.5s %-53.53s%s", TITLE_BAR, now + 1, hdr_spool[now].date + 3, hdr_spool[now].title, ORG_BAR); #else #ifdef HYPER prints("%s[200m\033[441;1437m\033[508m\033[300m%2d\033[303m) %-59.58s%s[201m", TITLE_BAR, now + 1, hdr_spool[now].title, ORG_BAR); #else prints("%s%2d) %-59.55s%s", TITLE_BAR, now + 1, hdr_spool[now].title, ORG_BAR); #endif #endif } return 0; }
int main() { UCACHE *ushm; COUNTER counter; int num; char *fname, date[20]; FILE *fp; time_t now; struct tm *ptime; chdir(BBSHOME); if (!(fp = fopen(OUTFILE_COUNTER, "a+"))) return -1; fname = FN_RUN_COUNTER; memset(&counter, 0, sizeof(COUNTER)); rec_get(fname, &counter, sizeof(COUNTER), 0); counter.uptime = time(&now); ptime = localtime(&now); sprintf(date, "【%02d/%02d/%02d %02d:%02d】", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, ptime->tm_hour, ptime->tm_min); /* 註冊人數 */ num = rec_num(FN_SCHEMA, sizeof(SCHEMA)); if (break_record(num, counter.total_acct)) { fprintf(fp, "★ %s \033[31m本站註冊人數\033[m狂賀超過 \033[1;31m%d\033[m 人\n", date, num); counter.total_acct = num; } /* 線上人數 */ ushm = shm_new(UTMPSHM_KEY, sizeof(UCACHE)); num = ushm->count; if (break_record(num, counter.online_usr)) { fprintf(fp, "◎ %s \033[32m同時線上人數\033[m首次達到 \033[1;32m%d\033[m 人\n", date, num); counter.online_usr = num; } counter.online_usr_every_hour[ptime->tm_hour] = num; /* 本小時的線上人數,就拿這次 sample 值 */ /* 本日上站人次 */ if (ptime->tm_hour == 23) /* 每天計算一次本日上站人次 */ { int i; /* itoc.註解: 這個值是不正確的,因為只是拿每個小時 sample 的和, 而且還假設每個人平均在站上時間是 60 分鐘 */ num = 0; for (i = 0; i < 24; i++) num += counter.online_usr_every_hour[i]; if (break_record(num, counter.today_usr)) { fprintf(fp, "◆ %s \033[33m單日上站人次\033[m正式突破 \033[1;33m%d\033[m 人\n", date, num); counter.today_usr = num; } } /* 看板個數 */ num = rec_num(FN_BRD, sizeof(BRD)); if (break_record(num, counter.total_brd)) { fprintf(fp, "☆ %s \033[34m本站看板個數\033[m宣佈高達 \033[1;34m%d\033[m 個\n", date, num); counter.total_brd = num; } rec_put(fname, &counter, sizeof(COUNTER), 0, NULL); fclose(fp); return 0; }