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

Diff for /mandoc/mansearch.c between version 1.31 and 1.32

version 1.31, 2014/04/16 00:33:47 version 1.32, 2014/04/16 21:36:18
Line 74  struct expr {
Line 74  struct expr {
 };  };
   
 struct  match {  struct  match {
         uint64_t         id; /* identifier in database */          uint64_t         pageid; /* identifier in database */
         char            *desc; /* manual page description */          char            *desc; /* manual page description */
         int              form; /* 0 == catpage */          int              form; /* 0 == catpage */
 };  };
Line 156  mansearch(const struct mansearch *search,
Line 156  mansearch(const struct mansearch *search,
                 struct manpage **res, size_t *sz)                  struct manpage **res, size_t *sz)
 {  {
         int              fd, rc, c, indexbit;          int              fd, rc, c, indexbit;
         int64_t          id;          int64_t          pageid;
         uint64_t         outbit, iterbit;          uint64_t         outbit, iterbit;
         char             buf[PATH_MAX];          char             buf[PATH_MAX];
         char            *sql;          char            *sql;
Line 175  mansearch(const struct mansearch *search,
Line 175  mansearch(const struct mansearch *search,
         info.halloc = hash_halloc;          info.halloc = hash_halloc;
         info.alloc = hash_alloc;          info.alloc = hash_alloc;
         info.hfree = hash_free;          info.hfree = hash_free;
         info.key_offset = offsetof(struct match, id);          info.key_offset = offsetof(struct match, pageid);
   
         *sz = cur = maxres = 0;          *sz = cur = maxres = 0;
         sql = NULL;          sql = NULL;
Line 287  mansearch(const struct mansearch *search,
Line 287  mansearch(const struct mansearch *search,
                  * distribution of buckets in the table.                   * distribution of buckets in the table.
                  */                   */
                 while (SQLITE_ROW == (c = sqlite3_step(s))) {                  while (SQLITE_ROW == (c = sqlite3_step(s))) {
                         id = sqlite3_column_int64(s, 2);                          pageid = sqlite3_column_int64(s, 2);
                         idx = ohash_lookup_memory                          idx = ohash_lookup_memory
                                 (&htab, (char *)&id,                                  (&htab, (char *)&pageid,
                                  sizeof(uint64_t), (uint32_t)id);                                   sizeof(uint64_t), (uint32_t)pageid);
   
                         if (NULL != ohash_find(&htab, idx))                          if (NULL != ohash_find(&htab, idx))
                                 continue;                                  continue;
   
                         mp = mandoc_calloc(1, sizeof(struct match));                          mp = mandoc_calloc(1, sizeof(struct match));
                         mp->id = id;                          mp->pageid = pageid;
                         mp->form = sqlite3_column_int(s, 1);                          mp->form = sqlite3_column_int(s, 1);
                         if (TYPE_Nd == outbit)                          if (TYPE_Nd == outbit)
                                 mp->desc = mandoc_strdup(                                  mp->desc = mandoc_strdup(
Line 332  mansearch(const struct mansearch *search,
Line 332  mansearch(const struct mansearch *search,
                         }                          }
                         mpage = *res + cur;                          mpage = *res + cur;
                         mpage->form = mp->form;                          mpage->form = mp->form;
                         buildnames(mpage, db, s, mp->id,                          buildnames(mpage, db, s, mp->pageid,
                             paths->paths[i], mp->form);                              paths->paths[i], mp->form);
                         mpage->output = TYPE_Nd & outbit ?                          mpage->output = TYPE_Nd & outbit ?
                             mp->desc : outbit ?                              mp->desc : outbit ?
                             buildoutput(db, s2, mp->id, outbit) : NULL;                              buildoutput(db, s2, mp->pageid, outbit) : NULL;
   
                         free(mp);                          free(mp);
                         cur++;                          cur++;
Line 362  out:
Line 362  out:
   
 static void  static void
 buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s,  buildnames(struct manpage *mpage, sqlite3 *db, sqlite3_stmt *s,
                 uint64_t id, const char *path, int form)                  uint64_t pageid, const char *path, int form)
 {  {
         char            *newnames, *prevsec, *prevarch;          char            *newnames, *prevsec, *prevarch;
         const char      *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec;          const char      *oldnames, *sep1, *name, *sec, *sep2, *arch, *fsec;
Line 373  buildnames(struct manpage *mpage, sqlite3 *db, sqlite3
Line 373  buildnames(struct manpage *mpage, sqlite3 *db, sqlite3
         mpage->names = NULL;          mpage->names = NULL;
         prevsec = prevarch = NULL;          prevsec = prevarch = NULL;
         i = 1;          i = 1;
         SQL_BIND_INT64(db, s, i, id);          SQL_BIND_INT64(db, s, i, pageid);
         while (SQLITE_ROW == (c = sqlite3_step(s))) {          while (SQLITE_ROW == (c = sqlite3_step(s))) {
   
                 /* Decide whether we already have some names. */                  /* Decide whether we already have some names. */
Line 455  buildnames(struct manpage *mpage, sqlite3 *db, sqlite3
Line 455  buildnames(struct manpage *mpage, sqlite3 *db, sqlite3
 }  }
   
 static char *  static char *
 buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id, uint64_t outbit)  buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t pageid, uint64_t outbit)
 {  {
         char            *output, *newoutput;          char            *output, *newoutput;
         const char      *oldoutput, *sep1, *data;          const char      *oldoutput, *sep1, *data;
Line 464  buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id,
Line 464  buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id,
   
         output = NULL;          output = NULL;
         i = 1;          i = 1;
         SQL_BIND_INT64(db, s, i, id);          SQL_BIND_INT64(db, s, i, pageid);
         SQL_BIND_INT64(db, s, i, outbit);          SQL_BIND_INT64(db, s, i, outbit);
         while (SQLITE_ROW == (c = sqlite3_step(s))) {          while (SQLITE_ROW == (c = sqlite3_step(s))) {
                 if (NULL == output) {                  if (NULL == output) {
Line 559  sql_statement(const struct expr *e)
Line 559  sql_statement(const struct expr *e)
                         : "desc MATCH ?")                          : "desc MATCH ?")
                     : TYPE_Nm == e->bits                      : TYPE_Nm == e->bits
                     ? (NULL == e->substr                      ? (NULL == e->substr
                         ? "id IN (SELECT pageid FROM names "                          ? "pageid IN (SELECT pageid FROM names "
                           "WHERE name REGEXP ?)"                            "WHERE name REGEXP ?)"
                         : "id IN (SELECT pageid FROM names "                          : "pageid IN (SELECT pageid FROM names "
                           "WHERE name MATCH ?)")                            "WHERE name MATCH ?)")
                     : (NULL == e->substr                      : (NULL == e->substr
                         ? "id IN (SELECT pageid FROM keys "                          ? "pageid IN (SELECT pageid FROM keys "
                           "WHERE key REGEXP ? AND bits & ?)"                            "WHERE key REGEXP ? AND bits & ?)"
                         : "id IN (SELECT pageid FROM keys "                          : "pageid IN (SELECT pageid FROM keys "
                           "WHERE key MATCH ? AND bits & ?)"), 1);                            "WHERE key MATCH ? AND bits & ?)"), 1);
                 if (e->close)                  if (e->close)
                         sql_append(&sql, &sz, ")", e->close);                          sql_append(&sql, &sz, ")", e->close);

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.32

CVSweb