1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* $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;
}
|