summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-17 14:22:29 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-11-17 14:22:29 +0800
commit1e4d4c78b043cf336ebd25634f5137a412539c8c (patch)
tree78ccad41cea3e9e5b99eaa1ea0c0ef3f39ccd0e6
parent1f197b3f501e0b9412e7686ec6b26b8cf39f0213 (diff)
downloadpttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar.gz
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar.bz2
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar.lz
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar.xz
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.tar.zst
pttbbs-1e4d4c78b043cf336ebd25634f5137a412539c8c.zip
remove all pointers in SHM_t
git-svn-id: http://opensvn.csie.org/pttbbs/branches/ptt.linux@2336 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/pttstruct.h6
-rw-r--r--mbbsd/bbs.c4
-rw-r--r--mbbsd/board.c57
-rw-r--r--mbbsd/cache.c20
-rw-r--r--util/boardlist.c70
-rw-r--r--util/shmctl.c34
6 files changed, 100 insertions, 91 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 34917ec7..7b09966f 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -173,9 +173,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 */
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index 9c9d0dfc..19e775b8 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -262,8 +262,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; 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 954c7d8f..ee3aa5e7 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -32,6 +32,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)
{
@@ -127,29 +134,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 = &bcache[SHM->bsorted[type][n]])
+ 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 *
@@ -186,12 +194,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;
@@ -268,9 +276,9 @@ load_boards(char *key)
else { // general case
nbrd = (boardstat_t *) MALLOC(sizeof(boardstat_t) * numboards);
for (i = 0; i < numboards; i++) {
- if ((bptr = &bcache[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()) ||
@@ -288,12 +296,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;
@@ -304,9 +312,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;
@@ -784,8 +792,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 c66a5b5b..c1246a52 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -498,17 +498,16 @@ void touchbtotal(int bid) {
static int
-cmpboardname(int i, int j)
+cmpboardname(const void * i, const void * j)
{
- return strcasecmp(bcache[i].brdname, bcache[j].brdname);
+ return strcasecmp(bcache[*(int*)i].brdname, bcache[*(int*)j].brdname);
}
static int
-cmpboardclass(int i, int j)
+cmpboardclass(const void * i, const void * j)
{
- boardheader_t *brd1 = &bcache[i], *brd2 = &bcache[j];
- return (strncmp(brd1->title, brd2->title, 4) << 8) +
- strcasecmp(brd1->brdname, brd2->brdname);
+ boardheader_t *brd1 = &bcache[*(int*)i], *brd2 = &bcache[*(int*)j];
+ return (strncmp(brd1->title, brd2->title, 4));
}
void
@@ -521,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] = i;
+ SHM->bsorted[0][i] = i;
}
qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int),
(QCAST) cmpboardname);
+ 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;
}
@@ -542,7 +542,7 @@ reload_bcache(void)
if (SHM->Bbusystate) {
safe_sleep(1);
}
- else {
+ else {
int fd;
SHM->Bbusystate = 1;
diff --git a/util/boardlist.c b/util/boardlist.c
index b6aae6ee..abc78b24 100644
--- a/util/boardlist.c
+++ b/util/boardlist.c
@@ -5,30 +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(SHM->bsorted[type][n]<0) continue;
- bptr = &SHM->bcache[SHM->bsorted[type][n]];
- if( bptr->brdname[0] == '\0' )
- continue;
- if (bptr->gid == gid) {
- if (currbptr == &bcache[gid - 1])
- currbptr->firstchild[type] = bptr;
- else {
- currbptr->next[type] = bptr;
- currbptr->parent = &bcache[gid - 1];
- }
- childcount++;
- currbptr = bptr;
- }
+ bid = SHM->bsorted[type][n]+1;
+ if( bid<=0 || !(bptr = &bcache[bid-1])
+ || bptr->brdname[0] == '\0' )
+ continue;
+ if (bptr->gid == gid) {
+ if (currbptr == parent)
+ currbptr->firstchild[type] = bid;
+ else {
+ 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)
@@ -83,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);
}
}
@@ -153,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 68e66dbb..5436f09d 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -224,33 +224,33 @@ int utmpfix(int argc, char **argv)
/* utmpsortd --------------------------------------------------------------- */
static int
-cmputmpuserid(int i, int j)
+cmputmpuserid(const void * i, const void * j)
{
- return strcasecmp(SHM->uinfo[i].userid, SHM->uinfo[j].userid);
+ return strcasecmp(SHM->uinfo[*(int*)i].userid, SHM->uinfo[*(int*)j].userid);
}
static int
-cmputmpmode(int i, int j)
+cmputmpmode(const void * i, const void * j)
{
- return SHM->uinfo[i].mode - SHM->uinfo[j].mode;
+ return SHM->uinfo[*(int*)i].mode - SHM->uinfo[*(int*)j].mode;
}
static int
-cmputmpidle(int i, int j)
+cmputmpidle(const void * i, const void * j)
{
- return SHM->uinfo[i].lastact - SHM->uinfo[j].lastact;
+ return SHM->uinfo[*(int*)i].lastact - SHM->uinfo[*(int*)j].lastact;
}
static int
-cmputmpfrom(int i, int j)
+cmputmpfrom(const void * i, const void * j)
{
- return strcmp(SHM->uinfo[i].from, SHM->uinfo[j].from);
+ return strcmp(SHM->uinfo[*(int*)i].from, SHM->uinfo[*(int*)j].from);
}
static int
-cmputmpfive(int i, int j)
+cmputmpfive(const void * i, const void * j)
{
- userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[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(int i, int j)
}
static int
-cmputmpchc(int i, int j)
+cmputmpchc(const void * i, const void * j)
{
- userinfo_t *a=&SHM->uinfo[i],*b=&SHM->uinfo[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(int i, int j)
}
static int
-cmputmppid(int i, int j)
+cmputmppid(const void * i, const void * j)
{
- return SHM->uinfo[i].pid - SHM->uinfo[j].pid;
+ return SHM->uinfo[*(int*)i].pid - SHM->uinfo[*(int*)j].pid;
}
static int
-cmputmpuid(int i, int j)
+cmputmpuid(const void * i, const void * j)
{
- return SHM->uinfo[i].uid - SHM->uinfo[j].uid;
+ return SHM->uinfo[*(int*)i].uid - SHM->uinfo[*(int*)j].uid;
}
inline void utmpsort(int sortall)
@@ -347,7 +347,7 @@ inline void utmpsort(int 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 ){
+ if( sortall !=-1){
memcpy(SHM->sorted[ns][1],
SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][2],