version 1.33, 2014/04/17 19:20:01 |
version 1.37, 2014/06/20 02:24:40 |
Line 64 extern const char *const mansearch_keynames[]; |
|
Line 64 extern const char *const mansearch_keynames[]; |
|
} while (0) |
} while (0) |
|
|
struct expr { |
struct expr { |
uint64_t bits; /* type-mask */ |
uint64_t bits; /* type-mask */ |
const char *substr; /* to search for, if applicable */ |
const char *substr; /* to search for, if applicable */ |
regex_t regexp; /* compiled regexp, if applicable */ |
regex_t regexp; /* compiled regexp, if applicable */ |
int open; /* opening parentheses before */ |
int open; /* opening parentheses before */ |
Line 85 static void buildnames(struct manpage *, sqlite3 *, |
|
Line 85 static void buildnames(struct manpage *, sqlite3 *, |
|
static char *buildoutput(sqlite3 *, sqlite3_stmt *, |
static char *buildoutput(sqlite3 *, sqlite3_stmt *, |
uint64_t, uint64_t); |
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 *, void *); |
static void *hash_halloc(size_t, void *); |
static void *hash_calloc(size_t, size_t, void *); |
static struct expr *exprcomp(const struct mansearch *, |
static struct expr *exprcomp(const struct mansearch *, |
int, char *[]); |
int, char *[]); |
static void exprfree(struct expr *); |
static void exprfree(struct expr *); |
static struct expr *exprspec(struct expr *, uint64_t, |
static struct expr *exprspec(struct expr *, uint64_t, |
Line 101 static void sql_regexp(sqlite3_context *context, |
|
Line 101 static void sql_regexp(sqlite3_context *context, |
|
int argc, sqlite3_value **argv); |
int argc, sqlite3_value **argv); |
static char *sql_statement(const struct expr *); |
static char *sql_statement(const struct expr *); |
|
|
|
|
int |
int |
mansearch_setup(int start) |
mansearch_setup(int start) |
{ |
{ |
Line 170 mansearch(const struct mansearch *search, |
|
Line 171 mansearch(const struct mansearch *search, |
|
unsigned int idx; |
unsigned int idx; |
size_t i, j, cur, maxres; |
size_t i, j, cur, maxres; |
|
|
memset(&info, 0, sizeof(struct ohash_info)); |
info.calloc = hash_calloc; |
|
|
info.halloc = hash_halloc; |
|
info.alloc = hash_alloc; |
info.alloc = hash_alloc; |
info.hfree = hash_free; |
info.free = hash_free; |
info.key_offset = offsetof(struct match, pageid); |
info.key_offset = offsetof(struct match, pageid); |
|
|
*sz = cur = maxres = 0; |
*sz = cur = maxres = 0; |
Line 235 mansearch(const struct mansearch *search, |
|
Line 234 mansearch(const struct mansearch *search, |
|
} else if (-1 == chdir(paths->paths[i])) { |
} else if (-1 == chdir(paths->paths[i])) { |
perror(paths->paths[i]); |
perror(paths->paths[i]); |
continue; |
continue; |
} |
} |
|
|
c = sqlite3_open_v2 |
c = sqlite3_open_v2(MANDOC_DB, &db, |
(MANDOC_DB, &db, |
SQLITE_OPEN_READONLY, NULL); |
SQLITE_OPEN_READONLY, NULL); |
|
|
|
if (SQLITE_OK != c) { |
if (SQLITE_OK != c) { |
perror(MANDOC_DB); |
perror(MANDOC_DB); |
Line 288 mansearch(const struct mansearch *search, |
|
Line 286 mansearch(const struct mansearch *search, |
|
*/ |
*/ |
while (SQLITE_ROW == (c = sqlite3_step(s))) { |
while (SQLITE_ROW == (c = sqlite3_step(s))) { |
pageid = sqlite3_column_int64(s, 2); |
pageid = sqlite3_column_int64(s, 2); |
idx = ohash_lookup_memory |
idx = ohash_lookup_memory(&htab, |
(&htab, (char *)&pageid, |
(char *)&pageid, sizeof(uint64_t), |
sizeof(uint64_t), (uint32_t)pageid); |
(uint32_t)pageid); |
|
|
if (NULL != ohash_find(&htab, idx)) |
if (NULL != ohash_find(&htab, idx)) |
continue; |
continue; |
Line 309 mansearch(const struct mansearch *search, |
|
Line 307 mansearch(const struct mansearch *search, |
|
|
|
sqlite3_finalize(s); |
sqlite3_finalize(s); |
|
|
c = sqlite3_prepare_v2(db, |
c = sqlite3_prepare_v2(db, |
"SELECT * FROM mlinks WHERE pageid=?" |
"SELECT sec, arch, name, pageid FROM mlinks " |
" ORDER BY sec, arch, name", |
"WHERE pageid=? ORDER BY sec, arch, name", |
-1, &s, NULL); |
-1, &s, NULL); |
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, |
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); |
-1, &s2, NULL); |
if (SQLITE_OK != c) |
if (SQLITE_OK != c) |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
fprintf(stderr, "%s\n", sqlite3_errmsg(db)); |
Line 327 mansearch(const struct mansearch *search, |
|
Line 326 mansearch(const struct mansearch *search, |
|
mp = ohash_next(&htab, &idx)) { |
mp = ohash_next(&htab, &idx)) { |
if (cur + 1 > maxres) { |
if (cur + 1 > maxres) { |
maxres += 1024; |
maxres += 1024; |
*res = mandoc_realloc |
*res = mandoc_reallocarray(*res, |
(*res, maxres * sizeof(struct manpage)); |
maxres, sizeof(struct manpage)); |
} |
} |
mpage = *res + cur; |
mpage = *res + cur; |
mpage->form = mp->form; |
mpage->form = mp->form; |
Line 542 sql_statement(const struct expr *e) |
|
Line 541 sql_statement(const struct expr *e) |
|
size_t sz; |
size_t sz; |
int needop; |
int needop; |
|
|
sql = mandoc_strdup("SELECT * FROM mpages WHERE "); |
sql = mandoc_strdup( |
|
"SELECT desc, form, pageid FROM mpages WHERE "); |
sz = strlen(sql); |
sz = strlen(sql); |
|
|
for (needop = 0; NULL != e; e = e->next) { |
for (needop = 0; NULL != e; e = e->next) { |
Line 788 exprfree(struct expr *p) |
|
Line 788 exprfree(struct expr *p) |
|
} |
} |
|
|
static void * |
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 * |
static void * |
Line 802 hash_alloc(size_t sz, void *arg) |
|
Line 802 hash_alloc(size_t sz, void *arg) |
|
} |
} |
|
|
static void |
static void |
hash_free(void *p, size_t sz, void *arg) |
hash_free(void *p, void *arg) |
{ |
{ |
|
|
free(p); |
free(p); |