回精華區
作者itoc, 信區: itoc
標題[修正] board.c 循環搜尋下一個未讀看板
時間04/03/23
作者: itoc (連霸夢碎) 看板: plan
標題: [修正] 循環搜尋下一個未讀看板
時間: 2004/03/23 Tue 10:42:03                           Updated: 2004/03/23

※ 引述《musashi634.bbs@wretch.twbbs.org (六三四)》之銘言:
>   假設站上有 50 個板
>   游標現在在編號 46 的看板前面,如果從編號 46 至 50 都沒有新文章
>   編號 13 的看板有新文章,游標不會移動到 編號 13 的看板
>   得先把游標往上移動,然後重新
>   可以請教一下,有辦法改成可以循環搜尋嗎?

: board.c:class_body()

#ifdef AUTO_JUMPBRD
  nextpos = 0;

  /* itoc.010910: 搜尋下一個未讀看板 */
  if (class_jumpnext)
  {
    class_jumpnext = 0;
    n = xo->pos;
    chp = (short *) xo->xyz + n;

    while (n < max)
    {
      chn = *chp++;
      if (chn >= 0)
      {
        BRD *brd;

        brd = bcache + chn;

#ifdef ENHANCED_VISIT
        /* itoc.010407: 改用最後一篇已讀/未讀來判斷 */
        brh_get(brd->bstamp, chn);
        if (brh_unread(brd->blast))
#else
        if (brd->blast > brd_visit[chn])
#endif
        {
          nextpos = n;
          break;
        }
      }
      n++;
    }

+   /* 如果找到最後一個板都找不到未讀,那麼循環再從頭找 */
+   if (!nextpos)
+   {
+     n = 0;
+     chp = (short *) xo->xyz + n;
+   }
+
+   while (n < xo->pos)
+   {
+     chn = *chp++;
+     if (chn >= 0)
+     {
+       BRD *brd;
+
+       brd = bcache + chn;
+
+#ifdef ENHANCED_VISIT
+       /* itoc.010407: 改用最後一篇已讀/未讀來判斷 */
+       brh_get(brd->bstamp, chn);
+       if (brh_unread(brd->blast))
+#else
+       if (brd->blast > brd_visit[chn])
+#endif
+       {
+         nextpos = n;
+         break;
+       }
+     }
+     n++;
+   }

    /* 下一個未讀板在別頁,要翻過去 */
-   if (nextpos >= cnt + XO_TALL)
+   if (nextpos < cnt || nextpos >= cnt + XO_TALL)
      return nextpos + XO_MOVE;
  }
#endif

--
  寫蠻髒的 :p

--
□ 本文章由 itocitoc.Dorm11.NCTU.edu.tw 發表
精華選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻