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

Diff for /mandoc/mansearch.c between version 1.11 and 1.12

version 1.11, 2013/12/31 02:42:29 version 1.12, 2013/12/31 03:41:14
Line 122  static const struct type types[] = {
Line 122  static const struct type types[] = {
 };  };
   
 static  char            *buildnames(sqlite3 *, sqlite3_stmt *, uint64_t);  static  char            *buildnames(sqlite3 *, sqlite3_stmt *, uint64_t);
   static  char            *buildoutput(sqlite3 *, sqlite3_stmt *,
                                    uint64_t, uint64_t);
 static  void            *hash_alloc(size_t, void *);  static  void            *hash_alloc(size_t, void *);
 static  void             hash_free(void *, size_t, void *);  static  void             hash_free(void *, size_t, void *);
 static  void            *hash_halloc(size_t, void *);  static  void            *hash_halloc(size_t, void *);
Line 138  static char  *sql_statement(const struct expr *,
Line 140  static char  *sql_statement(const struct expr *,
   
 int  int
 mansearch(const struct mansearch *search,  mansearch(const struct mansearch *search,
                 const struct manpaths *paths,                  const struct manpaths *paths,
                 int argc, char *argv[],                  int argc, char *argv[],
                   const char *outkey,
                 struct manpage **res, size_t *sz)                  struct manpage **res, size_t *sz)
 {  {
         int              fd, rc, c;          int              fd, rc, c, ibit;
         int64_t          id;          int64_t          id;
           uint64_t         outbit;
         char             buf[PATH_MAX];          char             buf[PATH_MAX];
         char            *sql;          char            *sql;
         struct manpage  *mpage;          struct manpage  *mpage;
         struct expr     *e, *ep;          struct expr     *e, *ep;
         sqlite3         *db;          sqlite3         *db;
         sqlite3_stmt    *s;          sqlite3_stmt    *s, *s2;
         struct match    *mp;          struct match    *mp;
         struct ohash_info info;          struct ohash_info info;
         struct ohash     htab;          struct ohash     htab;
Line 175  mansearch(const struct mansearch *search,
Line 179  mansearch(const struct mansearch *search,
         if (NULL == (e = exprcomp(search, argc, argv)))          if (NULL == (e = exprcomp(search, argc, argv)))
                 goto out;                  goto out;
   
           outbit = 0;
           if (NULL != outkey) {
                   for (ibit = 0; types[ibit].bits; ibit++) {
                           if (0 == strcasecmp(types[ibit].name, outkey)) {
                                   outbit = types[ibit].bits;
                                   break;
                           }
                   }
           }
   
         /*          /*
          * Save a descriptor to the current working directory.           * Save a descriptor to the current working directory.
          * Since pathnames in the "paths" variable might be relative,           * Since pathnames in the "paths" variable might be relative,
Line 291  mansearch(const struct mansearch *search,
Line 305  mansearch(const struct mansearch *search,
                 if (SQLITE_OK != c)                  if (SQLITE_OK != c)
                         fprintf(stderr, "%s\n", sqlite3_errmsg(db));                          fprintf(stderr, "%s\n", sqlite3_errmsg(db));
   
                   c = sqlite3_prepare_v2(db,
                       "SELECT * FROM keys WHERE pageid=? AND bits & ?",
                       -1, &s2, NULL);
                   if (SQLITE_OK != c)
                           fprintf(stderr, "%s\n", sqlite3_errmsg(db));
   
                 for (mp = ohash_first(&htab, &idx);                  for (mp = ohash_first(&htab, &idx);
                                 NULL != mp;                                  NULL != mp;
                                 mp = ohash_next(&htab, &idx)) {                                  mp = ohash_next(&htab, &idx)) {
Line 308  mansearch(const struct mansearch *search,
Line 328  mansearch(const struct mansearch *search,
                         mpage->desc = mp->desc;                          mpage->desc = mp->desc;
                         mpage->form = mp->form;                          mpage->form = mp->form;
                         mpage->names = buildnames(db, s, mp->id);                          mpage->names = buildnames(db, s, mp->id);
                           mpage->output = outbit ?
                               buildoutput(db, s2, mp->id, outbit) : NULL;
   
                         free(mp->file);                          free(mp->file);
                         free(mp);                          free(mp);
Line 315  mansearch(const struct mansearch *search,
Line 337  mansearch(const struct mansearch *search,
                 }                  }
   
                 sqlite3_finalize(s);                  sqlite3_finalize(s);
                   sqlite3_finalize(s2);
                 sqlite3_close(db);                  sqlite3_close(db);
                 ohash_delete(&htab);                  ohash_delete(&htab);
         }          }
Line 363  buildnames(sqlite3 *db, sqlite3_stmt *s, uint64_t id)
Line 386  buildnames(sqlite3 *db, sqlite3_stmt *s, uint64_t id)
                 fprintf(stderr, "%s\n", sqlite3_errmsg(db));                  fprintf(stderr, "%s\n", sqlite3_errmsg(db));
         sqlite3_reset(s);          sqlite3_reset(s);
         return(names);          return(names);
   }
   
   static char *
   buildoutput(sqlite3 *db, sqlite3_stmt *s, uint64_t id, uint64_t outbit)
   {
           char            *output, *newoutput;
           const char      *oldoutput, *sep1, *data;
           size_t           i;
           int              c;
   
           output = NULL;
           i = 1;
           SQL_BIND_INT64(db, s, i, id);
           SQL_BIND_INT64(db, s, i, outbit);
           while (SQLITE_ROW == (c = sqlite3_step(s))) {
                   if (NULL == output) {
                           oldoutput = "";
                           sep1 = "";
                   } else {
                           oldoutput = output;
                           sep1 = " # ";
                   }
                   data = sqlite3_column_text(s, 1);
                   if (-1 == asprintf(&newoutput, "%s%s%s",
                       oldoutput, sep1, data)) {
                           perror(0);
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
                   free(output);
                   output = newoutput;
           }
           if (SQLITE_DONE != c)
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db));
           sqlite3_reset(s);
           return(output);
 }  }
   
 /*  /*

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

CVSweb