//根据 /etc/bmat 显示各版主的上任时间和任职版面
// “用户代号”, “任职版面”, “上任时间”, “距今天数”
#include
#include
#include
#if !defined __LINUX__ && !defined FREEBSD
#include
#include
#endif
#include “bbs.h”
#define MAXCHECK MAXBOARD*3
typedef int cmpfunc(const void *, const void *);
typedef struct {
char uname[IDLEN + 2];
char board[STRLEN];
time_t inday;
} BMInfo;
static BMInfo *pBMInfo;
static nBMCount = 0;
//比较版主登录时间先后
int cmpBMLogin(BMInfo * fst, BMInfo * snd)
{
return (fst->inday – snd->inday);
}
//判断是否是普通版
int isNormalBoard(struct boardheader *brd)
{
if (brd->level & PERM_NOZAP)
return 1;
else if (brd->level & PERM_LOGINOK)
return 1;
return (brd->level == 0);
}
void checkBMs(void)
{
char lbuf[256], tbuf[80], mdate[80];
char *fmt = ” 33[%2d;%2dm%-14.14s%-32.32s%-24.24s%8.8s33[m";
char *timefmt = "%Y年%m月%d日 %T";
char *nulstr = "";
int i, j, uid, brd, dftime, warningBM = 0;
int fgc = 37, bgc = 44;
time_t now;
BMInfo *pBM;
now = time(NULL); /* current time stamp */
sprintf(lbuf, fmt, fgc, bgc, "用户代号", "任职版面", "上任时间", "距今天数");
fprintf(stdout, "33[m
%s
", lbuf);
for (i = 0; i inday) / 86400;
strftime(mdate, 30, timefmt, localtime(&(pBM->inday)));
sprintf(tbuf, "%d", dftime);
sprintf(lbuf, fmt, fgc, bgc, pBM->uname, pBM->board, mdate, uid ? tbuf : nulstr);
fprintf(stdout, "%s
", lbuf);
}
strftime(mdate, 30, timefmt, localtime(&now));
fprintf(stdout, "
统计时间∶%s
", mdate);
}
int main(int argc, char **argv)
{
BMInfo bmusr[MAXCHECK];
int i;
char buf[256];
FILE *fp;
char uname[IDLEN + 2];
char board[STRLEN];
time_t inday;
char renming[STRLEN];
struct boardheader *bp;
pBMInfo = bmusr;
chdir(BBSHOME);
resolve_boards(); //get shm
//open etc/bmat for read
if ((fp = fopen(“etc/bmat”, “r”)) == NULL) {
fprintf(stdout, “cannot read bmat file
“);
exit(0);
}
while (fgets(buf, 256, fp)) {
if (sscanf(buf, “%s %s %d %s”, uname, board, &inday, renming) != 4)
continue;
if (!strcasecmp(uname, “SYSOP”) || !isascii(*uname))
continue;
bp = getbcache(board);
if (bp == NULL)
continue;
if (!isNormalBoard(bp))
continue;
if (nBMCount >= MAXCHECK)
continue;
strcpy(pBMInfo[nBMCount].uname, uname);
strcpy(pBMInfo[nBMCount].board, board);
pBMInfo[nBMCount].inday = inday;
nBMCount++;
}
fclose(fp);
//排序? 以上任时间对 pBMInfo 数组排序
qsort(pBMInfo, nBMCount, sizeof(BMInfo), (cmpfunc *) cmpBMLogin);
checkBMs();
pBMInfo = NULL;
return 0;
}