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

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

version 1.8, 2013/10/20 00:03:05 version 1.11, 2013/12/31 02:42:29
Line 121  static const struct type types[] = {
Line 121  static const struct type types[] = {
         { 0ULL, NULL }          { 0ULL, NULL }
 };  };
   
   static  char            *buildnames(sqlite3 *, sqlite3_stmt *, 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 145  mansearch(const struct mansearch *search,
Line 146  mansearch(const struct mansearch *search,
         int64_t          id;          int64_t          id;
         char             buf[PATH_MAX];          char             buf[PATH_MAX];
         char            *sql;          char            *sql;
           struct manpage  *mpage;
         struct expr     *e, *ep;          struct expr     *e, *ep;
         sqlite3         *db;          sqlite3         *db;
         sqlite3_stmt    *s;          sqlite3_stmt    *s;
Line 282  mansearch(const struct mansearch *search,
Line 284  mansearch(const struct mansearch *search,
                         fprintf(stderr, "%s\n", sqlite3_errmsg(db));                          fprintf(stderr, "%s\n", sqlite3_errmsg(db));
   
                 sqlite3_finalize(s);                  sqlite3_finalize(s);
                 sqlite3_close(db);  
   
                   c = sqlite3_prepare_v2(db,
                       "SELECT * FROM mlinks WHERE pageid=?",
                       -1, &s, 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 292  mansearch(const struct mansearch *search,
Line 299  mansearch(const struct mansearch *search,
                                 *res = mandoc_realloc                                  *res = mandoc_realloc
                                         (*res, maxres * sizeof(struct manpage));                                          (*res, maxres * sizeof(struct manpage));
                         }                          }
                         strlcpy((*res)[cur].file,                          mpage = *res + cur;
                                 paths->paths[i], PATH_MAX);                          if (-1 == asprintf(&mpage->file, "%s/%s",
                         strlcat((*res)[cur].file, "/", PATH_MAX);                              paths->paths[i], mp->file)) {
                         strlcat((*res)[cur].file, mp->file, PATH_MAX);                                  perror(0);
                         (*res)[cur].desc = mp->desc;                                  exit((int)MANDOCLEVEL_SYSERR);
                         (*res)[cur].form = mp->form;                          }
                           mpage->desc = mp->desc;
                           mpage->form = mp->form;
                           mpage->names = buildnames(db, s, mp->id);
   
                         free(mp->file);                          free(mp->file);
                         free(mp);                          free(mp);
                         cur++;                          cur++;
                 }                  }
   
                   sqlite3_finalize(s);
                   sqlite3_close(db);
                 ohash_delete(&htab);                  ohash_delete(&htab);
         }          }
         rc = 1;          rc = 1;
Line 314  out:
Line 328  out:
         return(rc);          return(rc);
 }  }
   
   static char *
   buildnames(sqlite3 *db, sqlite3_stmt *s, uint64_t id)
   {
           char            *names, *newnames;
           const char      *oldnames, *sep1, *name, *sec, *sep2, *arch;
           size_t           i;
           int              c;
   
           names = NULL;
           i = 1;
           SQL_BIND_INT64(db, s, i, id);
           while (SQLITE_ROW == (c = sqlite3_step(s))) {
                   if (NULL == names) {
                           oldnames = "";
                           sep1 = "";
                   } else {
                           oldnames = names;
                           sep1 = ", ";
                   }
                   sec = sqlite3_column_text(s, 1);
                   arch = sqlite3_column_text(s, 2);
                   name = sqlite3_column_text(s, 3);
                   sep2 = '\0' == *arch ? "" : "/";
                   if (-1 == asprintf(&newnames, "%s%s%s(%s%s%s)",
                       oldnames, sep1, name, sec, sep2, arch)) {
                           perror(0);
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
                   free(names);
                   names = newnames;
           }
           if (SQLITE_DONE != c)
                   fprintf(stderr, "%s\n", sqlite3_errmsg(db));
           sqlite3_reset(s);
           return(names);
   }
   
 /*  /*
  * Implement substring match as an application-defined SQL function.   * Implement substring match as an application-defined SQL function.
  * Using the SQL LIKE or GLOB operators instead would be a bad idea   * Using the SQL LIKE or GLOB operators instead would be a bad idea
Line 363  sql_statement(const struct expr *e, const char *arch, 
Line 414  sql_statement(const struct expr *e, const char *arch, 
         size_t           sz;          size_t           sz;
   
         sql = mandoc_strdup          sql = mandoc_strdup
                 ("SELECT docid,bits,key,file,desc,form,sec,arch "                  ("SELECT pageid,bits,key,file,desc,form,sec,arch "
                  "FROM keys "                   "FROM keys "
                  "INNER JOIN docs ON docs.id=keys.docid "                   "INNER JOIN mpages ON mpages.id=keys.pageid "
                  "WHERE ");                   "WHERE ");
         sz = strlen(sql);          sz = strlen(sql);
         substrsz = strlen(substr);          substrsz = strlen(substr);

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

CVSweb