summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-10-23 14:36:53 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2003-10-23 14:36:53 +0800
commit96d78c8fa46d2464eaa2cd309e7415b9f159f92d (patch)
tree33f0c07b1b2962a2e7bb99fb0ff71d8079b73bb5 /util
parent2545c7ee4644116d570339bf462c4fba4e5ec15f (diff)
downloadpttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar.gz
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar.bz2
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar.lz
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar.xz
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.tar.zst
pttbbs-96d78c8fa46d2464eaa2cd309e7415b9f159f92d.zip
merge hotboard into shmctl
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1260 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r--util/Makefile2
-rw-r--r--util/hotboard.c74
-rw-r--r--util/shmctl.c64
3 files changed, 65 insertions, 75 deletions
diff --git a/util/Makefile b/util/Makefile
index 543627b0..09f6cc32 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 hotboard
+ outmail bbsmail
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
diff --git a/util/hotboard.c b/util/hotboard.c
deleted file mode 100644
index 584324ee..00000000
--- a/util/hotboard.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* $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;
-
-#define isvisiableboard(bptr) \
- ((bptr)->brdname[0] && \
- !((bptr)->brdattr & BRD_GROUPBOARD) && \
- !(((bptr)->brdattr & (BRD_HIDE | BRD_TOP)) || \
- ((bptr)->level && !((bptr)->brdattr & BRD_POSTMASK) && \
- ((bptr)->level & \
- ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK)))))
-
-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( (isvisiableboard(&SHM->bcache[i])) &&
- (nbrds != topn ||
- 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;
-}
diff --git a/util/shmctl.c b/util/shmctl.c
index 92a220e4..9f656f17 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -537,6 +537,69 @@ int SHMinit(int argc, char **argv)
return 0;
}
+int hotboard(int argc, char **argv)
+{
+#define isvisiableboard(bptr) \
+ ((bptr)->brdname[0] && \
+ !((bptr)->brdattr & BRD_GROUPBOARD) && \
+ !(((bptr)->brdattr & (BRD_HIDE | BRD_TOP)) || \
+ ((bptr)->level && !((bptr)->brdattr & BRD_POSTMASK) && \
+ ((bptr)->level & \
+ ~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK)))))
+
+ int ch, topn = 20, i, nbrds, j, k, nusers;
+ struct bs {
+ int nusers;
+ boardheader_t *b;
+ } *brd;
+
+ while( (ch = getopt(argc, argv, "t:h")) != -1 )
+ switch( ch ){
+ case 't':
+ topn = atoi(optarg);
+ if( topn <= 0 ){
+ goto hotboardusage;
+ return 1;
+ }
+ break;
+ case 'h':
+ default:
+ hotboardusage:
+ fprintf(stderr, "usage: shmctl hotboard [-t topn]\n");
+ return 1;
+ }
+
+ 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( (isvisiableboard(&SHM->bcache[i])) &&
+ (nbrds != topn ||
+ 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;
+}
+
struct {
int (*func)(int, char **);
char *cmd, *descript;
@@ -556,6 +619,7 @@ struct {
#endif
{bBMC, "bBMC", "build BM cache"},
{SHMinit, "SHMinit", "initialize SHM (including uhash_loader)"},
+ {hotboard, "hotboard", "list boards of most bfriends"},
{NULL, NULL, NULL} };
extern char ** environ;