summaryrefslogtreecommitdiffstats
path: root/mbbsd
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 /mbbsd
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 'mbbsd')
-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
5 files changed, 82 insertions, 109 deletions
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("我在哪?\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));
// 預留兩個以免大量開版時掛調
- 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; /* 超過範圍 */
}
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) 目前狀態為: %-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() 重複用到了 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() 重複用到了 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", 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) ){