summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-13 00:34:44 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-12-13 00:34:44 +0800
commitbe771c6ff954bbd39047db21294520c3b7dacd67 (patch)
tree82ab6cfb4a92aff8bd3ac190ba251fbdbfb71111 /mbbsd
parentd46073139b3b70c1e06e6236ba59ad4901950e8f (diff)
downloadpttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar.gz
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar.bz2
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar.lz
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar.xz
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.tar.zst
pttbbs-be771c6ff954bbd39047db21294520c3b7dacd67.zip
fix sorting problem
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2376 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/cache.c31
-rw-r--r--mbbsd/talk.c2
2 files changed, 21 insertions, 12 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index 09b3feac..6c81ce00 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -497,41 +497,48 @@ void touchbtotal(int bid) {
}
+/**
+ * qsort comparison function - 照板名排序
+ */
static int
cmpboardname(const void * i, const void * j)
{
return strcasecmp(bcache[*(int*)i].brdname, bcache[*(int*)j].brdname);
}
+/**
+ * qsort comparison function - 先照群組排序、同一個群組內依板名排
+ */
static int
cmpboardclass(const void * i, const void * j)
{
boardheader_t *brd1 = &bcache[*(int*)i], *brd2 = &bcache[*(int*)j];
- return (strncmp(brd1->title, brd2->title, 4));
+ return (strncmp(brd1->title, brd2->title, 4) << 8) +
+ strcasecmp(brd1->brdname, brd2->brdname);
}
+
void
sort_bcache(void)
{
int i;
/* critical section 盡量不要呼叫 */
/* 只有新增 或移除看板 需要呼叫到 */
- if(SHM->Bbusystate)
- { sleep(1); return; }
+ if(SHM->Bbusystate) {
+ sleep(1);
+ return;
+ }
SHM->Bbusystate = 1;
for (i = 0; i < SHM->Bnumber; i++) {
- SHM->bsorted[0][i] = i;
+ SHM->bsorted[0][i] = SHM->bsorted[1][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);
+ qsort(SHM->bsorted[0], SHM->Bnumber, sizeof(int), cmpboardname);
+ qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(int), cmpboardclass);
for (i = 0; i < SHM->Bnumber; i++) {
- bcache[i].firstchild[0] = 0;
- bcache[i].firstchild[1] = 0;
- }
+ bcache[i].firstchild[0] = 0;
+ bcache[i].firstchild[1] = 0;
+ }
SHM->Bbusystate = 0;
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index 374c3e28..8637f77c 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -2391,6 +2391,8 @@ userlist(void)
snprintf(msg.last_call_in, sizeof(msg.last_call_in),
"[廣播]%s", genbuf);
for (i = 0; i < SHM->UTMPnumber; ++i) {
+ // XXX why use sorted list?
+ // can we just scan uinfo with proper checking?
uentp = &SHM->uinfo[
SHM->sorted[SHM->currsorted][0][i]];
if (uentp->pid && kill(uentp->pid, 0) != -1){