summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-06 18:26:03 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-06 18:26:03 +0800
commit2178431a36c1d444ee05aaeb4fd9ca91c7571a2b (patch)
tree11c191277b0578af603afb4e877afb96e0eb4b61 /util
parentc876b5327229175e098c2c6490d01c28c71a08b3 (diff)
downloadpttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar.gz
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar.bz2
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar.lz
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar.xz
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.tar.zst
pttbbs-2178431a36c1d444ee05aaeb4fd9ca91c7571a2b.zip
discard r2368 due to compilation failure
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2371 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r--util/boardlist.c54
-rw-r--r--util/shmctl.c84
2 files changed, 66 insertions, 72 deletions
diff --git a/util/boardlist.c b/util/boardlist.c
index eae2d8ae..606a0192 100644
--- a/util/boardlist.c
+++ b/util/boardlist.c
@@ -5,30 +5,28 @@
static void
load_uidofgid(const int gid, const int type)
{
- boardheader_t *bptr, *currbptr, *parent;
- int bid, n, childcount = 0;
- currbptr = parent = &bcache[gid - 1];
+ boardheader_t *bptr, *currbptr;
+ int n, childcount = 0;
+ currbptr = &bcache[gid - 1];
for (n = 0; n < numboards; ++n) {
- bid = SHM->bsorted[type][n]+1;
- if( bid<=0 || !(bptr = &bcache[bid-1])
- || bptr->brdname[0] == '\0' )
+ if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' )
continue;
if (bptr->gid == gid) {
- if (currbptr == parent)
- currbptr->firstchild[type] = bid;
+ if (currbptr == &bcache[gid - 1])
+ currbptr->firstchild[type] = bptr;
else {
- currbptr->next[type] = bid;
- currbptr->parent = gid;
+ currbptr->next[type] = bptr;
+ currbptr->parent = &bcache[gid - 1];
}
childcount++;
currbptr = bptr;
}
}
- parent->childcount = childcount;
- if (currbptr == parent) // no child
- currbptr->firstchild[type] = -1;
- else // the last child
- currbptr->next[type] = -1;
+ bcache[gid - 1].childcount = childcount;
+ if (currbptr == &bcache[gid - 1])
+ currbptr->firstchild[type] = NULL;
+ else
+ currbptr->next[type] = NULL;
}
char *skipEscape(char *s)
@@ -83,36 +81,34 @@ void dumpdetail(void)
}
}
-void dumpclass(int gid)
+void dumpclass(int bid)
{
boardheader_t *bptr;
- int bid;
- bptr = getbcache(gid);
- if (bptr->firstchild[0] == 0 || bptr->childcount <= 0)
- load_uidofgid(gid, 0);
- printf("$db{'class.%d'} = $serializer->serialize([", gid);
- for (bid = bptr->firstchild[0]>0; bid >0 ; bid =bptr->next[0]) {
- bptr = getbcache(bid);
+ bptr = &bcache[bid];
+ if (bptr->firstchild[0] == NULL || bptr->childcount <= 0)
+ load_uidofgid(bid + 1, 0); /* 因為這邊 bid從 0開始, 所以再 +1 回來 */
+ printf("$db{'class.%d'} = $serializer->serialize([", bid);
+ for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) {
if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) ||
(bptr->level && !(bptr->brdattr & BRD_POSTMASK) &&
(bptr->level &
~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) )
continue;
- printf("%5d,\t", bid);
+ printf("%5d,\t", bptr - bcache);
}
printf("]);\n");
- bptr = getbcache(gid);
- for (bid = bptr->firstchild[0]>0; bid >0 ; bid =bptr->next[0]) {
- bptr = getbcache(bid);
+ bptr = &bcache[bid];
+ for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) {
if( (bptr->brdattr & (BRD_HIDE | BRD_TOP)) ||
(bptr->level && !(bptr->brdattr & BRD_POSTMASK) &&
(bptr->level &
~(PERM_BASIC|PERM_CHAT|PERM_PAGE|PERM_POST|PERM_LOGINOK))) )
continue;
+
if( bptr->brdattr & BRD_GROUPBOARD )
- dumpclass(bid);
+ dumpclass(bptr - bcache);
}
}
@@ -155,7 +151,7 @@ int main(int argc, char **argv)
"$serializer = Data::Serializer->new(serializer => 'Storable', digester => 'MD5',compress => 0,);\n"
"tie %%db, 'DB_File', 'boardlist.db', (O_RDWR | O_CREAT), 0666, $DB_HASH;\n"
);
- dumpclass(1);
+ dumpclass(0);
dumpdetail();
dumpallbrdname();
printf("untie %%db;\n");
diff --git a/util/shmctl.c b/util/shmctl.c
index d329c748..493e7c35 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -42,7 +42,7 @@ int logout_friend_online(userinfo_t *utmp)
void purge_utmp(userinfo_t *uentp)
{
logout_friend_online(uentp);
- //memset(uentp, 0, sizeof(int));
+ //memset(uentp, 0, sizeof(userinfo_t));
}
typedef struct {
@@ -203,7 +203,7 @@ int utmpfix(int argc, char **argv)
if( clean ){
printf("clean %06d(%s), userid: %s\n",
i, clean, SHM->uinfo[which].userid);
- memset(&SHM->uinfo[which], 0, sizeof(int));
+ memset(&SHM->uinfo[which], 0, sizeof(userinfo_t));
--nownum;
changeflag = 1;
}
@@ -224,33 +224,33 @@ int utmpfix(int argc, char **argv)
/* utmpsortd --------------------------------------------------------------- */
static int
-cmputmpuserid(const void * i, const void * j)
+cmputmpuserid(const void *i, const void *j)
{
- return strcasecmp(SHM->uinfo[*(int*)i].userid, SHM->uinfo[*(int*)j].userid);
+ return strcasecmp((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid);
}
static int
-cmputmpmode(const void * i, const void * j)
+cmputmpmode(const void *i, const void *j)
{
- return SHM->uinfo[*(int*)i].mode - SHM->uinfo[*(int*)j].mode;
+ return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode;
}
static int
-cmputmpidle(const void * i, const void * j)
+cmputmpidle(const void *i, const void *j)
{
- return SHM->uinfo[*(int*)i].lastact - SHM->uinfo[*(int*)j].lastact;
+ return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact;
}
static int
-cmputmpfrom(const void * i, const void * j)
+cmputmpfrom(const void *i, const void *j)
{
- return strcmp(SHM->uinfo[*(int*)i].from, SHM->uinfo[*(int*)j].from);
+ return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from);
}
static int
-cmputmpfive(const void * i, const void * j)
+cmputmpfive(const void *i, const void *j)
{
- userinfo_t *a=&SHM->uinfo[*(int*)i],*b=&SHM->uinfo[*(int*)j];
+ userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j));
int played_a=(a->five_win+a->five_lose+a->five_lose)!=0;
int played_b=(b->five_win+b->five_lose+b->five_lose)!=0;
int type;
@@ -267,9 +267,9 @@ cmputmpfive(const void * i, const void * j)
}
static int
-cmputmpchc(const void * i, const void * j)
+cmputmpchc(const void *i, const void *j)
{
- userinfo_t *a=&SHM->uinfo[*(int*)i],*b=&SHM->uinfo[*(int*)j];
+ userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j));
int total_a=a->chc_win+a->chc_lose+a->chc_lose;
int total_b=b->chc_win+b->chc_lose+b->chc_lose;
int played_a=(total_a!=0);
@@ -303,15 +303,15 @@ cmputmpchc(const void * i, const void * j)
}
static int
-cmputmppid(const void * i, const void * j)
+cmputmppid(const void *i, const void *j)
{
- return SHM->uinfo[*(int*)i].pid - SHM->uinfo[*(int*)j].pid;
+ return (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid;
}
static int
-cmputmpuid(const void * i, const void * j)
+cmputmpuid(const void *i, const void *j)
{
- return SHM->uinfo[*(int*)i].uid - SHM->uinfo[*(int*)j].uid;
+ return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid;
}
inline void utmpsort(int sortall)
@@ -336,36 +336,36 @@ inline void utmpsort(int sortall)
if (uentp->sex < 0 || uentp->sex > 7)
purge_utmp(uentp);
else
- SHM->sorted[ns][0][count++] = i;
+ SHM->sorted[ns][0][count++] = uentp;
}
}
SHM->UTMPnumber = count;
- qsort(SHM->sorted[ns][0], count, sizeof(int), cmputmpuserid);
+ qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid);
memcpy(SHM->sorted[ns][6],
- SHM->sorted[ns][0], sizeof(int) * count);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
memcpy(SHM->sorted[ns][7],
- SHM->sorted[ns][0], sizeof(int) * count);
- qsort(SHM->sorted[ns][6], count, sizeof(int), cmputmpuid);
- qsort(SHM->sorted[ns][7], count, sizeof(int), cmputmppid);
- if( sortall !=-1){
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ qsort(SHM->sorted[ns][6], count, sizeof(userinfo_t *), cmputmpuid);
+ qsort(SHM->sorted[ns][7], count, sizeof(userinfo_t *), cmputmppid);
+ if( sortall ){
memcpy(SHM->sorted[ns][1],
- SHM->sorted[ns][0], sizeof(int) * count);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
memcpy(SHM->sorted[ns][2],
- SHM->sorted[ns][0], sizeof(int) * count);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
memcpy(SHM->sorted[ns][3],
- SHM->sorted[ns][0], sizeof(int) * count);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
memcpy(SHM->sorted[ns][4],
- SHM->sorted[ns][0], sizeof(int) * count);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
memcpy(SHM->sorted[ns][5],
- SHM->sorted[ns][0], sizeof(int) * count);
- qsort(SHM->sorted[ns][1], count, sizeof(int), cmputmpmode);
- qsort(SHM->sorted[ns][2], count, sizeof(int), cmputmpidle);
- qsort(SHM->sorted[ns][3], count, sizeof(int), cmputmpfrom);
- qsort(SHM->sorted[ns][4], count, sizeof(int), cmputmpfive);
- qsort(SHM->sorted[ns][5], count, sizeof(int), cmputmpchc);
+ SHM->sorted[ns][0], sizeof(userinfo_t *) * count);
+ qsort(SHM->sorted[ns][1], count, sizeof(userinfo_t *), cmputmpmode);
+ qsort(SHM->sorted[ns][2], count, sizeof(userinfo_t *), cmputmpidle);
+ qsort(SHM->sorted[ns][3], count, sizeof(userinfo_t *), cmputmpfrom);
+ qsort(SHM->sorted[ns][4], count, sizeof(userinfo_t *), cmputmpfive);
+ qsort(SHM->sorted[ns][5], count, sizeof(userinfo_t *), cmputmpchc);
memset(nusers, 0, sizeof(nusers));
for (i = 0; i < count; ++i) {
- uentp = &SHM->uinfo[SHM->sorted[ns][0][i]];
+ uentp = SHM->sorted[ns][0][i];
if (uentp && uentp->pid &&
0 < uentp->brc_id && uentp->brc_id < MAX_BOARD)
++nusers[uentp->brc_id - 1];
@@ -373,10 +373,9 @@ inline void utmpsort(int sortall)
{
#if HOTBOARDCACHE
int k, r, last = 0, top = 0;
- int HBcache[HOTBOARDCACHE];
- for (i = 0; i < HOTBOARDCACHE; i++) HBcache[i]=-1;
+ boardheader_t *HBcache[HOTBOARDCACHE];
#endif
- for (i = 0; i < SHM->Bnumber; i++)
+ for (i = 0; i < SHM->Bnumber; ++i)
if (SHM->bcache[i].brdname[0] != 0){
SHM->bcache[i].nuser = nusers[i];
#if HOTBOARDCACHE
@@ -385,15 +384,14 @@ inline void utmpsort(int sortall)
IS_BOARD(&SHM->bcache[i]) &&
IS_OPENBRD(&SHM->bcache[i]) ){
for( k = top - 1 ; k >= 0 ; --k )
- if(HBcache[k]>=0 &&
- nusers[i] < SHM->bcache[HBcache[k]].nuser )
+ if( nusers[i] < HBcache[k]->nuser )
break;
if( top < HOTBOARDCACHE )
++top;
for( r = top - 1 ; r > (k + 1) ; --r )
HBcache[r] = HBcache[r - 1];
- HBcache[k + 1] = i;
- last = nusers[HBcache[top - 1]];
+ HBcache[k + 1] = &SHM->bcache[i];
+ last = nusers[(HBcache[top - 1] - SHM->bcache)];
}
#endif
}