diff options
-rw-r--r-- | include/pttstruct.h | 12 | ||||
-rw-r--r-- | mbbsd/bbs.c | 4 | ||||
-rw-r--r-- | mbbsd/board.c | 63 | ||||
-rw-r--r-- | mbbsd/cache.c | 74 | ||||
-rw-r--r-- | mbbsd/name.c | 16 | ||||
-rw-r--r-- | mbbsd/talk.c | 34 | ||||
-rw-r--r-- | util/boardlist.c | 54 | ||||
-rw-r--r-- | util/shmctl.c | 84 |
8 files changed, 154 insertions, 187 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h index 0fdc8921..23979723 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -175,9 +175,9 @@ typedef struct boardheader_t { unsigned int level; /* �i�H�ݦ��O���v�� */ int unused; /* �٨S�Ψ� */ int gid; /* �ݪO���ݪ����O ID */ - int next[2]; /* �b�P�@��gid�U�@�ӬݪO �ʺA����*/ - int firstchild[2]; /* �ݩ�o�ӬݪO���Ĥ@�Ӥl�ݪO */ - int parent; + void *next[2]; /* �b�P�@��gid�U�@�ӬݪO �ʺA����*/ + void *firstchild[2]; /* �ݩ�o�ӬݪO���Ĥ@�Ӥl�ݪO */ + void *parent; int childcount; /* ���h�֭�child */ int nuser; /* �h�֤H�b�o�O */ int postexpire; /* postexpire */ @@ -449,7 +449,7 @@ typedef struct { /* utmpshm */ userinfo_t uinfo[USHM_SIZE]; - int sorted[2][8][USHM_SIZE]; + userinfo_t *sorted[2][8][USHM_SIZE]; /* �Ĥ@��double buffer ��currsorted���V�ثe�ϥΪ� �ĤG��sort type */ int currsorted; @@ -461,10 +461,10 @@ typedef struct { /* brdshm */ int BMcache[MAX_BOARD][MAX_BMs]; boardheader_t bcache[MAX_BOARD]; - int bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ #if HOTBOARDCACHE unsigned char nHOTs; - int HBcache[HOTBOARDCACHE]; + boardheader_t *HBcache[HOTBOARDCACHE]; #endif time_t busystate_b[MAX_BOARD]; int total[MAX_BOARD]; diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 0a05f3f9..e1c274d7 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -263,8 +263,8 @@ whereami(int ent, fileheader_t * fhdr, char *direct) bh = getbcache(currutmp->brc_id); root = getbcache(1); p[0] = bh; - for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent>1; i++) - p[i + 1] = getbcache(p[i]->parent); + for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent != root && p[i]->parent; i++) + p[i + 1] = p[i]->parent; j = i; prints("�ڦb��?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM); for (j--; j >= 0; j--) diff --git a/mbbsd/board.c b/mbbsd/board.c index b798434a..17a36e6f 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -40,13 +40,6 @@ inline int getbid(boardheader_t *fh) { return (fh - bcache); } -inline boardheader_t *getparent(boardheader_t *fh) -{ - if(fh->parent>0) - return &bcache[fh->parent-1]; - else - return NULL; -} void imovefav(int old) { @@ -142,30 +135,28 @@ check_newpost(boardstat_t * ptr) 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; } static boardstat_t * @@ -202,12 +193,12 @@ load_boards(char *key) { boardheader_t *bptr = NULL; int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0; - int i, n, bid; + int i, n; int state; if (class_bid > 0) { bptr = getbcache(class_bid); - if (bptr->firstchild[type] == 0 ) + if (bptr->firstchild[type] == NULL || bptr->childcount <= 0) load_uidofgid(class_bid, type); } brdnum = 0; @@ -276,17 +267,16 @@ load_boards(char *key) else if( class_bid == -1 ){ nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * SHM->nHOTs); for( i = 0 ; i < SHM->nHOTs ; ++i ) - if(SHM->HBcache[i]==-1) continue; - addnewbrdstat(SHM->HBcache[i], - HasPerm(bcache[SHM->HBcache[i]])); + addnewbrdstat(SHM->HBcache[i] - SHM->bcache, + HasPerm(SHM->HBcache[i])); } #endif else { // general case nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards); for (i = 0; i < numboards; i++) { - n = SHM->bsorted[type][i]+1; - if (n<0 || (bptr = &bcache[n]) == NULL) + if ((bptr = SHM->bsorted[type][i]) == NULL) continue; + n = getbid(bptr); if (!bptr->brdname[0] || (bptr->brdattr & (BRD_GROUPBOARD | BRD_SYMBOLIC)) || !((state = HasPerm(bptr)) || GROUPOP()) || @@ -304,12 +294,12 @@ load_boards(char *key) qsort(nbrd, brdnum, sizeof(boardstat_t), cmpboardfriends); #endif } else { /* load boards of a subclass */ - int childcount = bptr->childcount; + int childcount = bptr->childcount; nbrd = (boardstat_t *) malloc((childcount+2) * sizeof(boardstat_t)); // �w�d��ӥH�K�j�q�}���ɱ��� - for (bid = bptr->firstchild[type]; bid > 0 && - brdnum < childcount+2; bid = bptr->next[type]) { - bptr = getbcache(bid); + for (bptr = bptr->firstchild[type]; bptr != NULL && + brdnum < childcount+2; bptr = bptr->next[type]) { + n = getbid(bptr); state = HasPerm(bptr); if ( !(state || GROUPOP()) || TITLE_MATCH(bptr, key) ) continue; @@ -320,9 +310,9 @@ load_boards(char *key) if (HAS_PERM(PERM_SYSOP)) state |= NBRD_SYMBOLIC; else - bid = BRD_LINK_TARGET(bptr); + n = BRD_LINK_TARGET(bptr) - 1; } - addnewbrdstat(bid-1, state); + addnewbrdstat(n, state); } if(childcount < brdnum) //Ptt: dirty fix fix soon getbcache(class_bid)->childcount = 0; @@ -776,7 +766,8 @@ choose_board(int newflag) case 'F': case 'f': if (class_bid>0 && HAS_PERM(PERM_SYSOP)) { - getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0; + getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] + = NULL; brdnum = -1; } break; diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 09b3feac..32cc4a95 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -318,16 +318,14 @@ userinfo_t * search_ulist_pid(int pid) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - int *ulist; - register userinfo_t *u; + register userinfo_t **ulist; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][7]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - u = &SHM->uinfo[ulist[i]]; - j = pid - u->pid; + j = pid - ulist[i]->pid; if (!j) { - return u; + return (userinfo_t *) (ulist[i]); } if (end == start) { break; @@ -346,21 +344,19 @@ userinfo_t * search_ulistn(int uid, int unum) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - int *ulist; - register userinfo_t *u; + register userinfo_t **ulist; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][6]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - u = &SHM->uinfo[ulist[i]]; - j = uid - u->uid; + j = uid - ulist[i]->uid; if (j == 0) { - for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; --i) + for (; i > 0 && uid == ulist[i - 1]->uid; --i) ;/* ����Ĥ@�� */ if ( i + unum - 1 >= 0 && - (ulist[i + unum - 1] >= 0 && - uid == SHM->uinfo[ulist[i + unum - 1]].uid ) ) - return &SHM->uinfo[ulist[i + unum - 1]]; + (ulist[i + unum - 1] != NULL && + uid == ulist[i + unum - 1]->uid) ) + return (userinfo_t *) (ulist[i + unum - 1]); break; /* �W�L�d�� */ } if (end == start) { @@ -380,16 +376,14 @@ userinfo_t * search_ulist_userid(char *userid) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1; - int *ulist; - register userinfo_t * u; + register userinfo_t **ulist; if (end == -1) return NULL; ulist = SHM->sorted[SHM->currsorted][0]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - u = &SHM->uinfo[ulist[i]]; - j = strcasecmp(userid, u->userid); + j = strcasecmp(userid, ulist[i]->userid); if (!j) { - return u; + return (userinfo_t *) (ulist[i]); } if (end == start) { break; @@ -409,24 +403,20 @@ int count_logins(int uid, int show) { register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count; - int *ulist; - userinfo_t *u; + register userinfo_t **ulist; if (end == -1) return 0; ulist = SHM->sorted[SHM->currsorted][6]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - u = &SHM->uinfo[ulist[i]]; - j = uid - u->uid; + j = uid - ulist[i]->uid; if (!j) { - for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; i--); - /* ����Ĥ@�� */ + for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* ����Ĥ@�� */ for (count = 0; (ulist[i + count] && - (u = &SHM->uinfo[ulist[i + count]]) && - uid == u->uid); count++) { + uid == ulist[i + count]->uid); count++) { if (show) prints("(%d) �ثe���A��: %-17.16s(�Ӧ� %s)\n", - count + 1, modestring(u, 0), - u->from); + count + 1, modestring(ulist[i + count], 0), + ulist[i + count]->from); } return count; } @@ -498,16 +488,16 @@ void touchbtotal(int bid) { static int -cmpboardname(const void * i, const void * j) +cmpboardname(boardheader_t ** brd, boardheader_t ** tmp) { - return strcasecmp(bcache[*(int*)i].brdname, bcache[*(int*)j].brdname); + return strcasecmp((*brd)->brdname, (*tmp)->brdname); } static int -cmpboardclass(const void * i, const void * j) +cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) { - boardheader_t *brd1 = &bcache[*(int*)i], *brd2 = &bcache[*(int*)j]; - return (strncmp(brd1->title, brd2->title, 4)); + return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) + + strcasecmp((*brd)->brdname, (*tmp)->brdname); } void @@ -520,17 +510,16 @@ sort_bcache(void) { sleep(1); return; } SHM->Bbusystate = 1; for (i = 0; i < SHM->Bnumber; i++) { - SHM->bsorted[0][i] = i; + SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; } - qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int), + qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardname); - memcpy(SHM->bsorted[1], SHM->bsorted[0], sizeof(int)*SHM->Bnumber); - qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(int), + qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardclass); for (i = 0; i < SHM->Bnumber; i++) { - bcache[i].firstchild[0] = 0; - bcache[i].firstchild[1] = 0; + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; } SHM->Bbusystate = 0; } @@ -690,10 +679,11 @@ int getbnum(const char *bname) { register int i = 0, j, start = 0, end = SHM->Bnumber - 1; - int *blist = SHM->bsorted[0]; + register boardheader_t **bhdr; + bhdr = SHM->bsorted[0]; for (i = ((start + end) / 2);; i = (start + end) / 2) { - if (!(j = strcasecmp(bname, bcache[blist[i]].brdname))) - return (int)(blist[i] + 1); + if (!(j = strcasecmp(bname, bhdr[i]->brdname))) + return (int)(bhdr[i] - bcache + 1); if (end == start) { break; } else if (i == start) { diff --git a/mbbsd/name.c b/mbbsd/name.c index 0c9009e8..9253a843 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -661,14 +661,13 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, int completeboard_compar(int where, char *str, int len) { - boardheader_t *bh = &bcache[SHM->bsorted[0][where]]; - return strncasecmp(bh->brdname, str, len); + return strncasecmp(SHM->bsorted[0][where]->brdname, str, len); } int completeboard_permission(int where) { - boardheader_t *bptr = &bcache[SHM->bsorted[0][where]]; + boardheader_t *bptr = SHM->bsorted[0][where]; return (!(bptr->brdattr & BRD_SYMBOLIC) && (GROUPOP() || HasPerm(bptr)) && !(bptr->brdattr & BRD_GROUPBOARD)); @@ -677,29 +676,28 @@ completeboard_permission(int where) char * completeboard_getname(int where) { - return bcache[SHM->bsorted[0][where]].brdname; + return SHM->bsorted[0][where]->brdname; } /* general complete functions (utmpshm) */ int completeutmp_compar(int where, char *str, int len) { - userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]]; - return strncasecmp(u->userid, str, len); + return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid, + str, len); } int completeutmp_permission(int where) { - userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]]; return (unlikely(HAS_PERM(PERM_SYSOP)) || unlikely(HAS_PERM(PERM_SEECLOAK)) || // !SHM->sorted[SHM->currsorted][0][where]->invisible); - isvisible(currutmp, u)); + isvisible(currutmp, SHM->sorted[SHM->currsorted][0][where])); } char * completeutmp_getname(int where) { - return SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]].userid; + return SHM->sorted[SHM->currsorted][0][where]->userid; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index d67d8c16..6ed035af 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -243,7 +243,7 @@ void login_friend_online(void) } #endif for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) { - uentp = (&SHM->uinfo[SHM->sorted[SHM->currsorted][0][i]]); + uentp = (SHM->sorted[SHM->currsorted][0][i]); if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) { stat1 = reverse_friend_stat(stat); stat <<= 24; @@ -1785,7 +1785,7 @@ pickup_bfriend(pickup_t * friends, int base) int currsorted = SHM->currsorted, number = SHM->UTMPnumber; friends = friends + base; for (i = 0; i < number && ngets < MAX_FRIEND - base; ++i) { - uentp = &SHM->uinfo[SHM->sorted[currsorted][0][i]]; + uentp = SHM->sorted[currsorted][0][i]; /* TODO isvisible() ���ƥΨ�F friend_stat() */ if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id && currutmp != uentp && isvisible(currutmp, uentp) && @@ -1806,8 +1806,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, int utmpnumber = SHM->UTMPnumber; int friendtotal = currutmp->friendtotal; - int *ulist; - userinfo_t *u; + userinfo_t **utmp; int which, sorted_way, size = 0, friend; if (friendtotal == 0) @@ -1851,18 +1850,17 @@ pickup(pickup_t * currpickup, int pickup_way, int *page, if (!(cuser.uflag & FRIEND_FLAG) && size < nPickups) { sorted_way = ((pickup_way == 0) ? 0 : (pickup_way - 1)); - ulist = SHM->sorted[currsorted][sorted_way]; + utmp = SHM->sorted[currsorted][sorted_way]; which = *page * nPickups - *nfriend; if (which < 0) which = 0; for (; which < utmpnumber && size < nPickups; which++) { - u = &SHM->uinfo[ulist[which]]; - friend = friend_stat(currutmp, u); + friend = friend_stat(currutmp, utmp[which]); /* TODO isvisible() ���ƥΨ�F friend_stat() */ if ((pickup_way || - (currutmp != u && !(friend & ST_FRIEND))) && - isvisible(currutmp, u)) { - currpickup[size].ui = u; + (currutmp != utmp[which] && !(friend & ST_FRIEND))) && + isvisible(currutmp, utmp[which])) { + currpickup[size].ui = utmp[which]; currpickup[size++].friend = friend; } } @@ -2269,11 +2267,12 @@ userlist(void) if (si >= 0) { pickup_t friends[MAX_FRIEND + 1]; int nGots, i; - int *ulist = + userinfo_t **utmp = SHM->sorted[SHM->currsorted] [((pickup_way == 0) ? 0 : (pickup_way - 1))]; - fi = ulist[si]; + fi = utmp[si] - &SHM->uinfo[0]; + nGots = pickup_myfriend(friends, &myfriend, &friendme, &badfriend); for (i = 0; i < nGots; ++i) @@ -2295,14 +2294,10 @@ userlist(void) } for( ; fi < nPickups && i < SHM->UTMPnumber ; ++i ) - { - userinfo_t *u; - u = &SHM->uinfo[ulist[i]]; - if( isvisible(currutmp, u) ){ - currpickup[fi].ui = u; + if( isvisible(currutmp, utmp[i]) ){ + currpickup[fi].ui = utmp[i]; currpickup[fi++].friend = 0; } - } skippickup = 1; } redrawall = redraw = 1; @@ -2391,8 +2386,7 @@ userlist(void) snprintf(msg.last_call_in, sizeof(msg.last_call_in), "[�s��]%s", genbuf); for (i = 0; i < SHM->UTMPnumber; ++i) { - uentp = &SHM->uinfo[ - SHM->sorted[SHM->currsorted][0][i]]; + uentp = SHM->sorted[SHM->currsorted][0][i]; if (uentp->pid && kill(uentp->pid, 0) != -1){ int write_pos = uentp->msgcount; if( write_pos < (MAX_MSGS - 1) ){ 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); /* �]���o�� bid�q 0�}�l, �ҥH�A +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 } |