作者itoc, 信區: itoc
標題[功能] gem-over.c 找出精華區使用量過大的看板
時間03/12/10
作者: itoc (核心動力) 看板: itoc
標題: Re: [問題]找出精華區容量過大的看板
時間: Wed Dec 10 19:15:36 2003 Updated: 2003/12/11
※ 引述《chwaian (無言)》之銘言:
> 我參考brdir寫了一支 找精華區容量超過5000KB大小的看板
: src/util/Makefile
EXE = .... gem-over
: src/util/gem-over.c 新增此程式
/*-------------------------------------------------------*/
/* util/gem-over.c ( NTHU CS MapleBBS Ver 3.10 ) */
/*-------------------------------------------------------*/
/* target : 統計精華區過大的看板 */
/* create : 03/12/10 */
/* update : / / */
/* author : itoc.bbs@bbs.tnfsh.tn.edu.tw */
/*-------------------------------------------------------*/
#include "bbs.h"
static int total_n; /* 篇數 */
static int total_k; /* byte 數 */
static void
gem_checksize(fpath)
char *fpath;
{
int i;
char *ptr, *str;
struct stat st;
struct dirent *de;
DIR *dirp;
total_n = 0;
total_k = 0;
if (stat(fpath, &st))
return;
total_n = st.st_size;
ptr = (char *) strchr(fpath, '.');
for (i = 0; i < 32; i++)
{
*ptr = radix32[i];
*(ptr + 1) = '\0';
if (!(dirp = opendir(fpath)))
continue;
*(ptr + 1) = '/';
while (de = readdir(dirp))
{
str = de->d_name;
if (*str <= ' ' || *str == '.')
continue;
strcpy(ptr + 2, str);
if (!stat(fpath, &st))
{
if (*str == 'F')
total_n += st.st_size;
else if (*str == 'A')
total_k += st.st_size;
}
}
closedir(dirp);
}
total_n /= sizeof(HDR);
total_k /= 1024;
}
int
main()
{
FILE *fp;
BRD brd;
char fpath[64];
chdir(BBSHOME);
if (!(fp = fopen(FN_BRD, "r")))
return -1;
while (fread(&brd, sizeof(BRD), 1, fp) == 1)
{
if (!*brd.brdname) /* 此板已被刪除 */
continue;
sprintf(fpath, "gem/brd/%s/%s", brd.brdname, FN_DIR);
gem_checksize(fpath);
if (total_n > 1000 || total_k > 5000) /* 1000篇、5000KB */
printf("%s 板 %d 篇 %d bytes\n", brd.brdname, total_n, total_k);
}
fclose(fp);
return 0;
}
--
┌┼ Origin: Maple-itoc˙動力核心 processor.tfcis.org
└┘ Author: itoc 從 itoc.dorm11.nctu.edu.tw 發表