[BACK]Return to apropos.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/Attic/apropos.c between version 1.4 and 1.5

version 1.4, 2011/10/08 12:20:09 version 1.5, 2011/10/09 10:35:12
Line 103  struct res {
Line 103  struct res {
         char            *title; /* manual section */          char            *title; /* manual section */
         char            *uri; /* formatted uri of file */          char            *uri; /* formatted uri of file */
         recno_t          rec; /* unique id of underlying manual */          recno_t          rec; /* unique id of underlying manual */
           /*
            * Maintain a binary tree for checking the uniqueness of `rec'
            * when adding elements to the results array.
            * Since the results array is dynamic, use offset in the array
            * instead of a pointer to the structure.
            */
           int              lhs;
           int              rhs;
 };  };
   
 struct  state {  struct  state {
Line 282  out:
Line 290  out:
 static void  static void
 state_search(struct state *p, const struct opts *opts, char *q)  state_search(struct state *p, const struct opts *opts, char *q)
 {  {
         int              i, len, ch, rflags, dflag;          int              leaf, root, len, ch, rflags, dflag;
         struct mchars   *mc;          struct mchars   *mc;
         char            *buf;          char            *buf;
         size_t           bufsz;          size_t           bufsz;
Line 295  state_search(struct state *p, const struct opts *opts,
Line 303  state_search(struct state *p, const struct opts *opts,
         char             filebuf[10];          char             filebuf[10];
         struct rec       record;          struct rec       record;
   
           root = leaf = -1;
         res = NULL;          res = NULL;
         len = 0;          len = 0;
         buf = NULL;          buf = NULL;
Line 400  state_search(struct state *p, const struct opts *opts,
Line 409  state_search(struct state *p, const struct opts *opts,
                 if (opts->arch && strcasecmp(opts->arch, record.arch))                  if (opts->arch && strcasecmp(opts->arch, record.arch))
                         continue;                          continue;
   
                 /* FIXME: this needs to be changed.  Ugh.  Linear. */                  /*
                    * Do a binary search to dedupe the results tree of the
                    * same record: we don't print the same file.
                    */
   
                 for (i = 0; i < len; i++)                  for (leaf = root; leaf >= 0; )
                         if (res[i].rec == record.rec)                          if (rec > res[leaf].rec && res[leaf].rhs >= 0)
                                   leaf = res[leaf].rhs;
                           else if (rec < res[leaf].rec && res[leaf].lhs >= 0)
                                   leaf = res[leaf].lhs;
                           else
                                 break;                                  break;
   
                 if (i < len)                  if (leaf >= 0 && res[leaf].rec == rec)
                         continue;                          continue;
   
                 res = mandoc_realloc                  res = mandoc_realloc
Line 424  state_search(struct state *p, const struct opts *opts,
Line 440  state_search(struct state *p, const struct opts *opts,
   
                 res[len].rec = record.rec;                  res[len].rec = record.rec;
                 res[len].types = fl;                  res[len].types = fl;
                   res[len].lhs = res[len].rhs = -1;
   
                 buf_dup(mc, &res[len].keyword, buf);                  buf_dup(mc, &res[len].keyword, buf);
                 buf_dup(mc, &res[len].uri, filebuf);                  buf_dup(mc, &res[len].uri, filebuf);
Line 431  state_search(struct state *p, const struct opts *opts,
Line 448  state_search(struct state *p, const struct opts *opts,
                 buf_dup(mc, &res[len].arch, record.arch);                  buf_dup(mc, &res[len].arch, record.arch);
                 buf_dup(mc, &res[len].title, record.title);                  buf_dup(mc, &res[len].title, record.title);
                 buf_dup(mc, &res[len].desc, record.desc);                  buf_dup(mc, &res[len].desc, record.desc);
   
                   if (leaf >= 0) {
                           if (record.rec > res[leaf].rec)
                                   res[leaf].rhs = len;
                           else
                                   res[leaf].lhs = len;
                   } else
                           root = len;
   
                 len++;                  len++;
         }          }
   

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

CVSweb