回文章列表
作者allen501pc.bbs@bbs.sa.ncyu.edu.tw (加 ~ 油 !!) 看板: itoc
標題[問題]關鍵字搜尋
時間新綠園 (2007/06/18 Mon 14:34:30)
各位大大好,敝站在某些看板使用f關鍵字搜尋功能,搜尋到0/100的時候,就發生斷線的

情形,這是敝站關於執行搜尋的主要程式碼如下,能否請各位大大能夠解答我的疑惑呢?

謝謝。

 進入搜尋內文詢問選項 
int
XoXfull(xo)
  XO *xo;
{
  HDR hdr;
  char *key, ans[8];
  int head, tail;

  if(!HAS_PERM(PERM_ALLADMIN))
  {
     vmsg("只有站長才可使用搜尋內文喔!");
     return XO_FOOT;
  }

#ifdef EVERY_Z
  if (z_status && xz[XZ_XPOST - XO_ZONE].xo)    /* itoc.020308: 不得累積進入二
次
 */
  {
    vmsg(MSG_XYDENY);
    return XO_FOOT;
  }
#endif
  /* input condition */

  key = hdr.title;
  if (!vget(b_lines, 0, "內文關鍵字:", key, 30, DOECHO))
    return XO_FOOT;

  vget(b_lines, 0, "[設定搜尋範圍] 起點:(Enter)從頭開始 ", ans, 6, DOECHO);
  if ((head = atoi(ans)) <= 0)
    head = 1;

  vget(b_lines, 44, "終點:(Enter)找到最後 ", ans, 6, DOECHO);
  if ((tail = atoi(ans)) < head)
    tail = INT_MAX;

  head--;

  sprintf(HintWord, "[全文搜尋] %s", key);
  HintAuthor[0] = '\0';
  str_lowest(key, key);

  search_folder = xo->dir;
  search_fit = 0;
  search_all = 0;


  return XoXpost(xo, &hdr, head, tail, filter_full);  //發動搜尋函式
}


 運行搜尋函式 
static int
XoXpost(xo, hdr, on, off, fchk)         /* Thor: eXtended post : call from
post_
cb */
  XO *xo;
  HDR *hdr;             /* 搜尋的條件 */
  int on, off;          /* 搜尋的範圍 (on~off-1) */
  int (*fchk) ();       /* 搜尋的函式 */
{
  int *list, fsize, max, locus, count, i;
  char *fimage;
  HDR *head;
  XO *xt;
#ifdef HAVE_XYNEWS
  int returnPos;
#endif

  if (xo->max <= 0)     /* Thor.980911: 註解: 以防萬一 */
    return XO_FOOT;

  /* build index according to input condition */

  fimage = f_map(xo->dir, &fsize);


  if (fimage == (char *) -1)
  {
    vmsg("目前無法開啟索引檔");
    return XO_FOOT;
  }

  /* allocate index memory, remember free first */

  /* Thor.990113: 怕問title, author的瞬間又有人post */
  max = xpostIndex ?  xo->max : fsize / sizeof(HDR);
  list = (int *) malloc(sizeof(int) * max);

  count = 0;                    /* 總共有幾篇滿足條件 */

  if (max > off)
    max = off;

  for (i = on; i < max; i++)
  {
    if (xpostIndex)             /* 增加條件再次搜尋時,只需要找在
 xpostIndex[] 腰
怑悸?*/
      locus = xpostIndex[i];
    else                        /* 整個 xo->dir 都掃一次 */

      locus = i;

    head = (HDR *) fimage + locus;

   if (head->xmode & POST_ERASE)
     continue;

#ifdef HAVE_REFUSEMARK
    if ((head->xmode & POST_RESTRICT) &&
      strcmp(head->owner, cuser.userid) && !(bbstate & STAT_BM))
      continue;
#endif

    /* check condition */
    if (!(* fchk) (head, hdr))
      continue;

    list[count++] = locus;
  }

  munmap(fimage, fsize);

  if (count <= 0)
  {
    free(list);
    vmsg(MSG_XY_NONE);
    return XO_FOOT;
  }

  /* 增加條件再次搜尋 */
  if (xpostIndex)
  {
    free(xpostIndex);
    xpostIndex = list;

    xo->pos = 0;
    xo->max = count;

    return xpost_init(xo);
  }

  /* 首次搜尋 */
  xpostIndex = list;

  /* build XO for xpost_xo */

  comebackPos = xo->pos;        /* Thor: record pos, future use */
#ifdef HAVE_XYNEWS
  returnPos = comebackPos;
#endif

  xz[XZ_XPOST - XO_ZONE].xo = xt = xo_new(xo->dir);
  xz[XZ_XPOST - XO_ZONE].cb = (xo->dir[0] == 'b') ? xpost_cb : xmbox_cb;
  xt->pos = 0;
  xt->max = count;
  xt->xyz = xo->xyz;
  xt->key = XZ_XPOST;

  xover(XZ_XPOST);

  /* set xo->pos for new location */

#ifdef HAVE_XYNEWS
  if (xz[XZ_NEWS - XO_ZONE].xo)
    xo->pos = returnPos;        /* 從 XZ_XPOST 回到 XZ_NEWS 游標移去原來的地方
 *
/
  else
#endif

    xo->pos = comebackPos;      /* 從 XZ_XPOST 回到 XZ_POST 游標移去原來的地方
或
所閱讀文章的真正位置 */

  /* free xpost_xo */

  if (xt = xz[XZ_XPOST - XO_ZONE].xo)
  {
    free(xt);
    xz[XZ_XPOST - XO_ZONE].xo = NULL;
  }

  /* free index memory, remember check free pointer */

  if (xpostIndex)
  {
    free(xpostIndex);
    xpostIndex = NULL;
  }

  return XO_INIT;
}


--
  ╒═╕
  ║  ║║║           過方知
  ╠═╣║║╓═┐╭─╮
  ║  ║║║╠═╜║  ║    過方知
    ║║║╰─╯│  

--
    ╭─ Origin ─╗ 新綠園  bbs.sa.ncyu.edu.tw  ~ κλμ ─┤
    ├   Author   ╡ 220-129-182-195.dynamic.hinet.net     
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻