summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-10-21 20:10:26 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-10-21 20:10:26 +0800
commite5be5e3eec947d28807c8ba40fe92ab07e5bb248 (patch)
tree4d66e93def0130ad07811978f547f6e913995436
parent1b3798bd300369ea0c2114a262df961910e5ca6f (diff)
downloadpttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar.gz
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar.bz2
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar.lz
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar.xz
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.tar.zst
pttbbs-e5be5e3eec947d28807c8ba40fe92ab07e5bb248.zip
add hotboard
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1257 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--util/Makefile2
-rw-r--r--util/hotboard.c66
2 files changed, 67 insertions, 1 deletions
diff --git a/util/Makefile b/util/Makefile
index 09f6cc32..543627b0 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -20,7 +20,7 @@ CPROG_WITH_UTIL= \
openvice parse_news openticket topusr \
indexuser yearsold toplazyBM toplazyBBM \
reaper buildAnnounce inndBM shmctl \
- outmail bbsmail
+ outmail bbsmail hotboard
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
diff --git a/util/hotboard.c b/util/hotboard.c
new file mode 100644
index 00000000..ff4c0e88
--- /dev/null
+++ b/util/hotboard.c
@@ -0,0 +1,66 @@
+/* $Id$ */
+#include "bbs.h"
+extern SHM_t *SHM;
+
+void usage(void)
+{
+ fprintf(stderr,
+ "usage: hotbard [-t topn]\n");
+}
+
+struct bs {
+ int nusers;
+ boardheader_t *b;
+} *brd;
+
+int main(int argc, char **argv)
+{
+ int ch, topn = 20, i, nbrds, j, k, nusers;
+
+ chdir(BBSHOME);
+ while( (ch = getopt(argc, argv, "t:h")) != -1 )
+ switch( ch ){
+ case 't':
+ topn = atoi(optarg);
+ if( topn <= 0 ){
+ usage();
+ return 1;
+ }
+ break;
+ case 'h':
+ default:
+ usage();
+ return 1;
+ }
+
+ attach_SHM();
+ brd = (struct bs *)malloc(sizeof(struct bs) * topn);
+ brd[0].b = &SHM->bcache[0];
+ brd[0].nusers = brd[0].b->brdname[0] ? brd[0].b->nuser : 0;
+ nbrds = 1;
+
+ for( i = 1 ; i < MAX_BOARD ; ++i )
+ if( nbrds != topn ||
+ (SHM->bcache[i].brdname[0] &&
+ SHM->bcache[i].nuser > brd[nbrds - 1].nusers) ){
+
+ nusers = SHM->bcache[i].nuser; // no race ?
+ for( k = nbrds - 2 ; k >= 0 ; --k )
+ if( brd[k].nusers > nusers )
+ break;
+
+ if( (k + 1) < nbrds && (k + 2) < topn )
+ for( j = nbrds - 1 ; j >= k + 1 ; --j )
+ brd[j] = brd[j - 1];
+ brd[k + 1].nusers = nusers;
+ brd[k + 1].b = &SHM->bcache[i];
+
+ if( nbrds < topn )
+ ++nbrds;
+ }
+
+ for( i = 0 ; i < nbrds ; ++i )
+ printf("%05d|%-12s|%s\n",
+ brd[i].nusers, brd[i].b->brdname, brd[i].b->title);
+ return 0;
+}