diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/boardlist.c | 54 | ||||
-rw-r--r-- | util/shmctl.c | 84 |
2 files changed, 72 insertions, 66 deletions
diff --git a/util/boardlist.c b/util/boardlist.c index 606a0192..eae2d8ae 100644 --- a/util/boardlist.c +++ b/util/boardlist.c @@ -5,28 +5,30 @@ static void load_uidofgid(const int gid, const int type) { - boardheader_t *bptr, *currbptr; - int n, childcount = 0; - currbptr = &bcache[gid - 1]; + boardheader_t *bptr, *currbptr, *parent; + int bid, n, childcount = 0; + currbptr = parent = &bcache[gid - 1]; for (n = 0; n < numboards; ++n) { - if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' ) + bid = SHM->bsorted[type][n]+1; + if( bid<=0 || !(bptr = &bcache[bid-1]) + || bptr->brdname[0] == '\0' ) continue; if (bptr->gid == gid) { - if (currbptr == &bcache[gid - 1]) - currbptr->firstchild[type] = bptr; + if (currbptr == parent) + currbptr->firstchild[type] = bid; else { - currbptr->next[type] = bptr; - currbptr->parent = &bcache[gid - 1]; + currbptr->next[type] = bid; + currbptr->parent = gid; } childcount++; currbptr = bptr; } } - bcache[gid - 1].childcount = childcount; - if (currbptr == &bcache[gid - 1]) - currbptr->firstchild[type] = NULL; - else - currbptr->next[type] = NULL; + parent->childcount = childcount; + if (currbptr == parent) // no child + currbptr->firstchild[type] = -1; + else // the last child + currbptr->next[type] = -1; } char *skipEscape(char *s) @@ -81,34 +83,36 @@ void dumpdetail(void) } } -void dumpclass(int bid) +void dumpclass(int gid) { boardheader_t *bptr; - 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]) { + 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); 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", bptr - bcache); + printf("%5d,\t", bid); } printf("]);\n"); - bptr = &bcache[bid]; - for (bptr = bptr->firstchild[0]; bptr != NULL ; bptr = bptr->next[0]) { + bptr = getbcache(gid); + for (bid = bptr->firstchild[0]>0; bid >0 ; bid =bptr->next[0]) { + bptr = getbcache(bid); 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(bptr - bcache); + dumpclass(bid); } } @@ -151,7 +155,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(0); + dumpclass(1); dumpdetail(); dumpallbrdname(); printf("untie %%db;\n"); diff --git a/util/shmctl.c b/util/shmctl.c index 493e7c35..d329c748 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(userinfo_t)); + //memset(uentp, 0, sizeof(int)); } 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(userinfo_t)); + memset(&SHM->uinfo[which], 0, sizeof(int)); --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((*((userinfo_t **) i))->userid, (*((userinfo_t **) j))->userid); + return strcasecmp(SHM->uinfo[*(int*)i].userid, SHM->uinfo[*(int*)j].userid); } static int -cmputmpmode(const void *i, const void *j) +cmputmpmode(const void * i, const void * j) { - return (*((userinfo_t **) i))->mode - (*((userinfo_t **) j))->mode; + return SHM->uinfo[*(int*)i].mode - SHM->uinfo[*(int*)j].mode; } static int -cmputmpidle(const void *i, const void *j) +cmputmpidle(const void * i, const void * j) { - return (*((userinfo_t **) i))->lastact - (*((userinfo_t **) j))->lastact; + return SHM->uinfo[*(int*)i].lastact - SHM->uinfo[*(int*)j].lastact; } static int -cmputmpfrom(const void *i, const void *j) +cmputmpfrom(const void * i, const void * j) { - return strcasecmp((*((userinfo_t **) i))->from, (*((userinfo_t **) j))->from); + return strcmp(SHM->uinfo[*(int*)i].from, SHM->uinfo[*(int*)j].from); } static int -cmputmpfive(const void *i, const void *j) +cmputmpfive(const void * i, const void * j) { - userinfo_t *a=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j)); + userinfo_t *a=&SHM->uinfo[*(int*)i],*b=&SHM->uinfo[*(int*)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=(*((userinfo_t **) i)),*b=(*((userinfo_t **) j)); + userinfo_t *a=&SHM->uinfo[*(int*)i],*b=&SHM->uinfo[*(int*)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 (*((userinfo_t **) i))->pid - (*((userinfo_t **) j))->pid; + return SHM->uinfo[*(int*)i].pid - SHM->uinfo[*(int*)j].pid; } static int -cmputmpuid(const void *i, const void *j) +cmputmpuid(const void * i, const void * j) { - return (*((userinfo_t **) i))->uid - (*((userinfo_t **) j))->uid; + return SHM->uinfo[*(int*)i].uid - SHM->uinfo[*(int*)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++] = uentp; + SHM->sorted[ns][0][count++] = i; } } SHM->UTMPnumber = count; - qsort(SHM->sorted[ns][0], count, sizeof(userinfo_t *), cmputmpuserid); + qsort(SHM->sorted[ns][0], count, sizeof(int), cmputmpuserid); memcpy(SHM->sorted[ns][6], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][7], - 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 ){ + 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){ memcpy(SHM->sorted[ns][1], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][2], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][3], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][4], - SHM->sorted[ns][0], sizeof(userinfo_t *) * count); + SHM->sorted[ns][0], sizeof(int) * count); memcpy(SHM->sorted[ns][5], - 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); + 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); memset(nusers, 0, sizeof(nusers)); for (i = 0; i < count; ++i) { - uentp = SHM->sorted[ns][0][i]; + uentp = &SHM->uinfo[SHM->sorted[ns][0][i]]; if (uentp && uentp->pid && 0 < uentp->brc_id && uentp->brc_id < MAX_BOARD) ++nusers[uentp->brc_id - 1]; @@ -373,9 +373,10 @@ inline void utmpsort(int sortall) { #if HOTBOARDCACHE int k, r, last = 0, top = 0; - boardheader_t *HBcache[HOTBOARDCACHE]; + int HBcache[HOTBOARDCACHE]; + for (i = 0; i < HOTBOARDCACHE; i++) HBcache[i]=-1; #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 @@ -384,14 +385,15 @@ inline void utmpsort(int sortall) IS_BOARD(&SHM->bcache[i]) && IS_OPENBRD(&SHM->bcache[i]) ){ for( k = top - 1 ; k >= 0 ; --k ) - if( nusers[i] < HBcache[k]->nuser ) + if(HBcache[k]>=0 && + nusers[i] < SHM->bcache[HBcache[k]].nuser ) break; if( top < HOTBOARDCACHE ) ++top; for( r = top - 1 ; r > (k + 1) ; --r ) HBcache[r] = HBcache[r - 1]; - HBcache[k + 1] = &SHM->bcache[i]; - last = nusers[(HBcache[top - 1] - SHM->bcache)]; + HBcache[k + 1] = i; + last = nusers[HBcache[top - 1]]; } #endif } |