=================================================================== RCS file: /cvs/mandoc/mansearch.c,v retrieving revision 1.33 retrieving revision 1.37 diff -u -p -r1.33 -r1.37 --- mandoc/mansearch.c 2014/04/17 19:20:01 1.33 +++ mandoc/mansearch.c 2014/06/20 02:24:40 1.37 @@ -1,4 +1,4 @@ -/* $Id: mansearch.c,v 1.33 2014/04/17 19:20:01 schwarze Exp $ */ +/* $Id: mansearch.c,v 1.37 2014/06/20 02:24:40 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -64,7 +64,7 @@ extern const char *const mansearch_keynames[]; } while (0) struct expr { - uint64_t bits; /* type-mask */ + uint64_t bits; /* type-mask */ const char *substr; /* to search for, if applicable */ regex_t regexp; /* compiled regexp, if applicable */ int open; /* opening parentheses before */ @@ -85,9 +85,9 @@ static void buildnames(struct manpage *, sqlite3 *, static char *buildoutput(sqlite3 *, sqlite3_stmt *, uint64_t, uint64_t); static void *hash_alloc(size_t, void *); -static void hash_free(void *, size_t, void *); -static void *hash_halloc(size_t, void *); -static struct expr *exprcomp(const struct mansearch *, +static void hash_free(void *, void *); +static void *hash_calloc(size_t, size_t, void *); +static struct expr *exprcomp(const struct mansearch *, int, char *[]); static void exprfree(struct expr *); static struct expr *exprspec(struct expr *, uint64_t, @@ -101,6 +101,7 @@ static void sql_regexp(sqlite3_context *context, int argc, sqlite3_value **argv); static char *sql_statement(const struct expr *); + int mansearch_setup(int start) { @@ -170,11 +171,9 @@ mansearch(const struct mansearch *search, unsigned int idx; size_t i, j, cur, maxres; - memset(&info, 0, sizeof(struct ohash_info)); - - info.halloc = hash_halloc; + info.calloc = hash_calloc; info.alloc = hash_alloc; - info.hfree = hash_free; + info.free = hash_free; info.key_offset = offsetof(struct match, pageid); *sz = cur = maxres = 0; @@ -235,11 +234,10 @@ mansearch(const struct mansearch *search, } else if (-1 == chdir(paths->paths[i])) { perror(paths->paths[i]); continue; - } + } - c = sqlite3_open_v2 - (MANDOC_DB, &db, - SQLITE_OPEN_READONLY, NULL); + c = sqlite3_open_v2(MANDOC_DB, &db, + SQLITE_OPEN_READONLY, NULL); if (SQLITE_OK != c) { perror(MANDOC_DB); @@ -288,9 +286,9 @@ mansearch(const struct mansearch *search, */ while (SQLITE_ROW == (c = sqlite3_step(s))) { pageid = sqlite3_column_int64(s, 2); - idx = ohash_lookup_memory - (&htab, (char *)&pageid, - sizeof(uint64_t), (uint32_t)pageid); + idx = ohash_lookup_memory(&htab, + (char *)&pageid, sizeof(uint64_t), + (uint32_t)pageid); if (NULL != ohash_find(&htab, idx)) continue; @@ -309,15 +307,16 @@ mansearch(const struct mansearch *search, sqlite3_finalize(s); - c = sqlite3_prepare_v2(db, - "SELECT * FROM mlinks WHERE pageid=?" - " ORDER BY sec, arch, name", + c = sqlite3_prepare_v2(db, + "SELECT sec, arch, name, pageid FROM mlinks " + "WHERE pageid=? ORDER BY sec, arch, name", -1, &s, NULL); if (SQLITE_OK != c) fprintf(stderr, "%s\n", sqlite3_errmsg(db)); c = sqlite3_prepare_v2(db, - "SELECT * FROM keys WHERE pageid=? AND bits & ?", + "SELECT bits, key, pageid FROM keys " + "WHERE pageid=? AND bits & ?", -1, &s2, NULL); if (SQLITE_OK != c) fprintf(stderr, "%s\n", sqlite3_errmsg(db)); @@ -327,8 +326,8 @@ mansearch(const struct mansearch *search, mp = ohash_next(&htab, &idx)) { if (cur + 1 > maxres) { maxres += 1024; - *res = mandoc_realloc - (*res, maxres * sizeof(struct manpage)); + *res = mandoc_reallocarray(*res, + maxres, sizeof(struct manpage)); } mpage = *res + cur; mpage->form = mp->form; @@ -542,7 +541,8 @@ sql_statement(const struct expr *e) size_t sz; int needop; - sql = mandoc_strdup("SELECT * FROM mpages WHERE "); + sql = mandoc_strdup( + "SELECT desc, form, pageid FROM mpages WHERE "); sz = strlen(sql); for (needop = 0; NULL != e; e = e->next) { @@ -788,10 +788,10 @@ exprfree(struct expr *p) } static void * -hash_halloc(size_t sz, void *arg) +hash_calloc(size_t nmemb, size_t sz, void *arg) { - return(mandoc_calloc(sz, 1)); + return(mandoc_calloc(nmemb, sz)); } static void * @@ -802,7 +802,7 @@ hash_alloc(size_t sz, void *arg) } static void -hash_free(void *p, size_t sz, void *arg) +hash_free(void *p, void *arg) { free(p);