summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-05 11:17:32 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-05 11:17:32 +0800
commita95201ad4d7b597ec13650c28251af838892bef7 (patch)
tree83bdc62dcfd5dab3690b3fe0c96bc3eb6fabddfc
parentf3cd768750fb89b3ab1e26d5b0dd42738af0a714 (diff)
downloadpttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar.gz
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar.bz2
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar.lz
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar.xz
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.tar.zst
pttbbs-a95201ad4d7b597ec13650c28251af838892bef7.zip
merge ptt.linux
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2368 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/pttstruct.h12
-rw-r--r--mbbsd/bbs.c4
-rw-r--r--mbbsd/board.c63
-rw-r--r--mbbsd/cache.c74
-rw-r--r--mbbsd/name.c16
-rw-r--r--mbbsd/talk.c34
-rw-r--r--util/boardlist.c54
-rw-r--r--util/shmctl.c84
8 files changed, 187 insertions, 154 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 23979723..0fdc8921 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -175,9 +175,9 @@ typedef struct boardheader_t {
unsigned int level; /* 可以看此板的權限 */
int unused; /* 還沒用到 */
int gid; /* 看板所屬的類別 ID */
- void *next[2]; /* 在同一個gid下一個看板 動態產生*/
- void *firstchild[2]; /* 屬於這個看板的第一個子看板 */
- void *parent;
+ int next[2]; /* 在同一個gid下一個看板 動態產生*/
+ int firstchild[2]; /* 屬於這個看板的第一個子看板 */
+ int parent;
int childcount; /* 有多少個child */
int nuser; /* 多少人在這板 */
int postexpire; /* postexpire */
@@ -449,7 +449,7 @@ typedef struct {
/* utmpshm */
userinfo_t uinfo[USHM_SIZE];
- userinfo_t *sorted[2][8][USHM_SIZE];
+ int sorted[2][8][USHM_SIZE];
/* 第一維double buffer 由currsorted指向目前使用的
第二維sort type */
int currsorted;
@@ -461,10 +461,10 @@ typedef struct {
/* brdshm */
int BMcache[MAX_BOARD][MAX_BMs];
boardheader_t bcache[MAX_BOARD];
- boardheader_t *bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */
+ int bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */
#if HOTBOARDCACHE
unsigned char nHOTs;
- boardheader_t *HBcache[HOTBOARDCACHE];
+ int HBcache[HOTBOARDCACHE];
#endif
time_t busystate_b[MAX_BOARD];
int total[MAX_BOARD];
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 832c6182..a4223151 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 != root && p[i]->parent; i++)
- p[i + 1] = p[i]->parent;
+ for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent>1; i++)
+ p[i + 1] = getbcache(p[i]->parent);
j = i;
prints("我在哪?\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 17a36e6f..b798434a 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -40,6 +40,13 @@ 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)
{
@@ -135,28 +142,30 @@ check_newpost(boardstat_t * ptr)
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;
}
static boardstat_t *
@@ -193,12 +202,12 @@ load_boards(char *key)
{
boardheader_t *bptr = NULL;
int type = cuser.uflag & BRDSORT_FLAG ? 1 : 0;
- int i, n;
+ int i, n, bid;
int state;
if (class_bid > 0) {
bptr = getbcache(class_bid);
- if (bptr->firstchild[type] == NULL || bptr->childcount <= 0)
+ if (bptr->firstchild[type] == 0 )
load_uidofgid(class_bid, type);
}
brdnum = 0;
@@ -267,16 +276,17 @@ 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 )
- addnewbrdstat(SHM->HBcache[i] - SHM->bcache,
- HasPerm(SHM->HBcache[i]));
+ if(SHM->HBcache[i]==-1) continue;
+ addnewbrdstat(SHM->HBcache[i],
+ HasPerm(bcache[SHM->HBcache[i]]));
}
#endif
else { // general case
nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards);
for (i = 0; i < numboards; i++) {
- if ((bptr = SHM->bsorted[type][i]) == NULL)
+ n = SHM->bsorted[type][i]+1;
+ if (n<0 || (bptr = &bcache[n]) == NULL)
continue;
- n = getbid(bptr);
if (!bptr->brdname[0] ||
(bptr->brdattr & (BRD_GROUPBOARD | BRD_SYMBOLIC)) ||
!((state = HasPerm(bptr)) || GROUPOP()) ||
@@ -294,12 +304,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));
// 預留兩個以免大量開版時掛調
- for (bptr = bptr->firstchild[type]; bptr != NULL &&
- brdnum < childcount+2; bptr = bptr->next[type]) {
- n = getbid(bptr);
+ for (bid = bptr->firstchild[type]; bid > 0 &&
+ brdnum < childcount+2; bid = bptr->next[type]) {
+ bptr = getbcache(bid);
state = HasPerm(bptr);
if ( !(state || GROUPOP()) || TITLE_MATCH(bptr, key) )
continue;
@@ -310,9 +320,9 @@ load_boards(char *key)
if (HAS_PERM(PERM_SYSOP))
state |= NBRD_SYMBOLIC;
else
- n = BRD_LINK_TARGET(bptr) - 1;
+ bid = BRD_LINK_TARGET(bptr);
}
- addnewbrdstat(n, state);
+ addnewbrdstat(bid-1, state);
}
if(childcount < brdnum) //Ptt: dirty fix fix soon
getbcache(class_bid)->childcount = 0;
@@ -766,8 +776,7 @@ 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]
- = NULL;
+ getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0;
brdnum = -1;
}
break;
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 32cc4a95..09b3feac 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -318,14 +318,16 @@ userinfo_t *
search_ulist_pid(int pid)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t *u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][7];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = pid - ulist[i]->pid;
+ u = &SHM->uinfo[ulist[i]];
+ j = pid - u->pid;
if (!j) {
- return (userinfo_t *) (ulist[i]);
+ return u;
}
if (end == start) {
break;
@@ -344,19 +346,21 @@ userinfo_t *
search_ulistn(int uid, int unum)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t *u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][6];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = uid - ulist[i]->uid;
+ u = &SHM->uinfo[ulist[i]];
+ j = uid - u->uid;
if (j == 0) {
- for (; i > 0 && uid == ulist[i - 1]->uid; --i)
+ for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; --i)
;/* 指到第一筆 */
if ( i + unum - 1 >= 0 &&
- (ulist[i + unum - 1] != NULL &&
- uid == ulist[i + unum - 1]->uid) )
- return (userinfo_t *) (ulist[i + unum - 1]);
+ (ulist[i + unum - 1] >= 0 &&
+ uid == SHM->uinfo[ulist[i + unum - 1]].uid ) )
+ return &SHM->uinfo[ulist[i + unum - 1]];
break; /* 超過範圍 */
}
if (end == start) {
@@ -376,14 +380,16 @@ userinfo_t *
search_ulist_userid(char *userid)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1;
- register userinfo_t **ulist;
+ int *ulist;
+ register userinfo_t * u;
if (end == -1)
return NULL;
ulist = SHM->sorted[SHM->currsorted][0];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = strcasecmp(userid, ulist[i]->userid);
+ u = &SHM->uinfo[ulist[i]];
+ j = strcasecmp(userid, u->userid);
if (!j) {
- return (userinfo_t *) (ulist[i]);
+ return u;
}
if (end == start) {
break;
@@ -403,20 +409,24 @@ int
count_logins(int uid, int show)
{
register int i = 0, j, start = 0, end = SHM->UTMPnumber - 1, count;
- register userinfo_t **ulist;
+ int *ulist;
+ userinfo_t *u;
if (end == -1)
return 0;
ulist = SHM->sorted[SHM->currsorted][6];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- j = uid - ulist[i]->uid;
+ u = &SHM->uinfo[ulist[i]];
+ j = uid - u->uid;
if (!j) {
- for (; i > 0 && uid == ulist[i - 1]->uid; i--); /* 指到第一筆 */
+ for (; i > 0 && uid == SHM->uinfo[ulist[i - 1]].uid; i--);
+ /* 指到第一筆 */
for (count = 0; (ulist[i + count] &&
- uid == ulist[i + count]->uid); count++) {
+ (u = &SHM->uinfo[ulist[i + count]]) &&
+ uid == u->uid); count++) {
if (show)
prints("(%d) 目前狀態為: %-17.16s(來自 %s)\n",
- count + 1, modestring(ulist[i + count], 0),
- ulist[i + count]->from);
+ count + 1, modestring(u, 0),
+ u->from);
}
return count;
}
@@ -488,16 +498,16 @@ void touchbtotal(int bid) {
static int
-cmpboardname(boardheader_t ** brd, boardheader_t ** tmp)
+cmpboardname(const void * i, const void * j)
{
- return strcasecmp((*brd)->brdname, (*tmp)->brdname);
+ return strcasecmp(bcache[*(int*)i].brdname, bcache[*(int*)j].brdname);
}
static int
-cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp)
+cmpboardclass(const void * i, const void * j)
{
- return (strncmp((*brd)->title, (*tmp)->title, 4) << 8) +
- strcasecmp((*brd)->brdname, (*tmp)->brdname);
+ boardheader_t *brd1 = &bcache[*(int*)i], *brd2 = &bcache[*(int*)j];
+ return (strncmp(brd1->title, brd2->title, 4));
}
void
@@ -510,16 +520,17 @@ sort_bcache(void)
{ sleep(1); return; }
SHM->Bbusystate = 1;
for (i = 0; i < SHM->Bnumber; i++) {
- SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i];
+ SHM->bsorted[0][i] = i;
}
- qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(boardheader_t *),
+ qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int),
(QCAST) cmpboardname);
- qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *),
+ memcpy(SHM->bsorted[1], SHM->bsorted[0], sizeof(int)*SHM->Bnumber);
+ qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(int),
(QCAST) cmpboardclass);
for (i = 0; i < SHM->Bnumber; i++) {
- bcache[i].firstchild[0] = NULL;
- bcache[i].firstchild[1] = NULL;
+ bcache[i].firstchild[0] = 0;
+ bcache[i].firstchild[1] = 0;
}
SHM->Bbusystate = 0;
}
@@ -679,11 +690,10 @@ int
getbnum(const char *bname)
{
register int i = 0, j, start = 0, end = SHM->Bnumber - 1;
- register boardheader_t **bhdr;
- bhdr = SHM->bsorted[0];
+ int *blist = SHM->bsorted[0];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
- if (!(j = strcasecmp(bname, bhdr[i]->brdname)))
- return (int)(bhdr[i] - bcache + 1);
+ if (!(j = strcasecmp(bname, bcache[blist[i]].brdname)))
+ return (int)(blist[i] + 1);
if (end == start) {
break;
} else if (i == start) {
diff --git a/mbbsd/name.c b/mbbsd/name.c
index 9253a843..0c9009e8 100644
--- a/mbbsd/name.c
+++ b/mbbsd/name.c
@@ -661,13 +661,14 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb,
int
completeboard_compar(int where, char *str, int len)
{
- return strncasecmp(SHM->bsorted[0][where]->brdname, str, len);
+ boardheader_t *bh = &bcache[SHM->bsorted[0][where]];
+ return strncasecmp(bh->brdname, str, len);
}
int
completeboard_permission(int where)
{
- boardheader_t *bptr = SHM->bsorted[0][where];
+ boardheader_t *bptr = &bcache[SHM->bsorted[0][where]];
return (!(bptr->brdattr & BRD_SYMBOLIC) &&
(GROUPOP() || HasPerm(bptr)) &&
!(bptr->brdattr & BRD_GROUPBOARD));
@@ -676,28 +677,29 @@ completeboard_permission(int where)
char *
completeboard_getname(int where)
{
- return SHM->bsorted[0][where]->brdname;
+ return bcache[SHM->bsorted[0][where]].brdname;
}
/* general complete functions (utmpshm) */
int
completeutmp_compar(int where, char *str, int len)
{
- return strncasecmp(SHM->sorted[SHM->currsorted][0][where]->userid,
- str, len);
+ userinfo_t *u = &SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]];
+ return strncasecmp(u->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, SHM->sorted[SHM->currsorted][0][where]));
+ isvisible(currutmp, u));
}
char *
completeutmp_getname(int where)
{
- return SHM->sorted[SHM->currsorted][0][where]->userid;
+ return SHM->uinfo[SHM->sorted[SHM->currsorted][0][where]].userid;
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index c8bb5d50..dd1fd3d5 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->sorted[SHM->currsorted][0][i]);
+ uentp = (&SHM->uinfo[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->sorted[currsorted][0][i];
+ uentp = &SHM->uinfo[SHM->sorted[currsorted][0][i]];
/* TODO isvisible() 重複用到了 friend_stat() */
if (uentp && uentp->pid && uentp->brc_id == currutmp->brc_id &&
currutmp != uentp && isvisible(currutmp, uentp) &&
@@ -1806,7 +1806,8 @@ pickup(pickup_t * currpickup, int pickup_way, int *page,
int utmpnumber = SHM->UTMPnumber;
int friendtotal = currutmp->friendtotal;
- userinfo_t **utmp;
+ int *ulist;
+ userinfo_t *u;
int which, sorted_way, size = 0, friend;
if (friendtotal == 0)
@@ -1850,17 +1851,18 @@ 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));
- utmp = SHM->sorted[currsorted][sorted_way];
+ ulist = SHM->sorted[currsorted][sorted_way];
which = *page * nPickups - *nfriend;
if (which < 0)
which = 0;
for (; which < utmpnumber && size < nPickups; which++) {
- friend = friend_stat(currutmp, utmp[which]);
+ u = &SHM->uinfo[ulist[which]];
+ friend = friend_stat(currutmp, u);
/* TODO isvisible() 重複用到了 friend_stat() */
if ((pickup_way ||
- (currutmp != utmp[which] && !(friend & ST_FRIEND))) &&
- isvisible(currutmp, utmp[which])) {
- currpickup[size].ui = utmp[which];
+ (currutmp != u && !(friend & ST_FRIEND))) &&
+ isvisible(currutmp, u)) {
+ currpickup[size].ui = u;
currpickup[size++].friend = friend;
}
}
@@ -2267,12 +2269,11 @@ userlist(void)
if (si >= 0) {
pickup_t friends[MAX_FRIEND + 1];
int nGots, i;
- userinfo_t **utmp =
+ int *ulist =
SHM->sorted[SHM->currsorted]
[((pickup_way == 0) ? 0 : (pickup_way - 1))];
- fi = utmp[si] - &SHM->uinfo[0];
-
+ fi = ulist[si];
nGots = pickup_myfriend(friends, &myfriend,
&friendme, &badfriend);
for (i = 0; i < nGots; ++i)
@@ -2294,10 +2295,14 @@ userlist(void)
}
for( ; fi < nPickups && i < SHM->UTMPnumber ; ++i )
- if( isvisible(currutmp, utmp[i]) ){
- currpickup[fi].ui = utmp[i];
+ {
+ userinfo_t *u;
+ u = &SHM->uinfo[ulist[i]];
+ if( isvisible(currutmp, u) ){
+ currpickup[fi].ui = u;
currpickup[fi++].friend = 0;
}
+ }
skippickup = 1;
}
redrawall = redraw = 1;
@@ -2380,7 +2385,8 @@ userlist(void)
break;
}
for (i = 0; i < SHM->UTMPnumber; ++i) {
- uentp = SHM->sorted[SHM->currsorted][0][i];
+ uentp = &SHM->uinfo[
+ SHM->sorted[SHM->currsorted][0][i]];
if (uentp->pid && kill(uentp->pid, 0) != -1)
my_write(uentp->pid, genbuf,
uentp->userid, WATERBALL_PREEDIT, NULL);
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
}