version 1.8, 2011/11/20 15:43:14 |
version 1.11, 2011/11/23 09:55:28 |
Line 125 static int exprmark(const struct expr *, |
|
Line 125 static int exprmark(const struct expr *, |
|
static struct expr *exprexpr(int, char *[], int *, int *, size_t *); |
static struct expr *exprexpr(int, char *[], int *, int *, size_t *); |
static struct expr *exprterm(char *, int); |
static struct expr *exprterm(char *, int); |
static DB *index_open(void); |
static DB *index_open(void); |
static int index_read(const DBT *, const DBT *, |
static int index_read(const DBT *, const DBT *, int, |
const struct mchars *, struct rec *); |
const struct mchars *, struct rec *); |
static void norm_string(const char *, |
static void norm_string(const char *, |
const struct mchars *, char **); |
const struct mchars *, char **); |
Line 133 static size_t norm_utf8(unsigned int, char[7]); |
|
Line 133 static size_t norm_utf8(unsigned int, char[7]); |
|
static void recfree(struct rec *); |
static void recfree(struct rec *); |
static int single_search(struct rectree *, const struct opts *, |
static int single_search(struct rectree *, const struct opts *, |
const struct expr *, size_t terms, |
const struct expr *, size_t terms, |
struct mchars *); |
struct mchars *, int); |
|
|
/* |
/* |
* Open the keyword mandoc-db database. |
* Open the keyword mandoc-db database. |
Line 345 index_open(void) |
|
Line 345 index_open(void) |
|
* Returns 1 if an entry was unpacked, 0 if the database is insane. |
* Returns 1 if an entry was unpacked, 0 if the database is insane. |
*/ |
*/ |
static int |
static int |
index_read(const DBT *key, const DBT *val, |
index_read(const DBT *key, const DBT *val, int index, |
const struct mchars *mc, struct rec *rec) |
const struct mchars *mc, struct rec *rec) |
{ |
{ |
size_t left; |
size_t left; |
Line 364 index_read(const DBT *key, const DBT *val, |
|
Line 364 index_read(const DBT *key, const DBT *val, |
|
cp = (char *)val->data; |
cp = (char *)val->data; |
|
|
rec->res.rec = *(recno_t *)key->data; |
rec->res.rec = *(recno_t *)key->data; |
|
rec->res.volume = index; |
|
|
INDEX_BREAD(rec->res.file); |
INDEX_BREAD(rec->res.file); |
INDEX_BREAD(rec->res.cat); |
INDEX_BREAD(rec->res.cat); |
Line 374 index_read(const DBT *key, const DBT *val, |
|
Line 375 index_read(const DBT *key, const DBT *val, |
|
} |
} |
|
|
/* |
/* |
* Search mandocdb databases in argv (size argc) for the expression |
* Search mandocdb databases in paths for expression "expr". |
* "expr". |
|
* Filter out by "opts". |
* Filter out by "opts". |
* Call "res" with the results, which may be zero. |
* Call "res" with the results, which may be zero. |
* Return 0 if there was a database error, else return 1. |
* Return 0 if there was a database error, else return 1. |
*/ |
*/ |
int |
int |
apropos_search(int argc, char *argv[], const struct opts *opts, |
apropos_search(int pathsz, char **paths, const struct opts *opts, |
const struct expr *expr, size_t terms, void *arg, |
const struct expr *expr, size_t terms, void *arg, |
void (*res)(struct res *, size_t, void *)) |
void (*res)(struct res *, size_t, void *)) |
{ |
{ |
Line 392 apropos_search(int argc, char *argv[], const struct op |
|
Line 392 apropos_search(int argc, char *argv[], const struct op |
|
|
|
memset(&tree, 0, sizeof(struct rectree)); |
memset(&tree, 0, sizeof(struct rectree)); |
|
|
|
rc = 0; |
mc = mchars_alloc(); |
mc = mchars_alloc(); |
|
|
for (rc = 1, i = 0; rc && i < argc; i++) { |
/* |
/* FIXME: ugly warning: we shouldn't get here! */ |
* Main loop. Change into the directory containing manpage |
if (chdir(argv[i])) |
* databases. Run our expession over each database in the set. |
|
*/ |
|
|
|
for (i = 0; i < pathsz; i++) { |
|
if (chdir(paths[i])) |
continue; |
continue; |
rc = single_search(&tree, opts, expr, terms, mc); |
if ( ! single_search(&tree, opts, expr, terms, mc, i)) |
/* FIXME: warn and continue... ? */ |
goto out; |
} |
} |
|
|
/* |
/* |
* Count the matching files |
* Count matching files, transfer to a "clean" array, then feed |
* and feed them to the output handler. |
* them to the output handler. |
*/ |
*/ |
|
|
for (mlen = i = 0; i < tree.len; i++) |
for (mlen = i = 0; i < tree.len; i++) |
Line 421 apropos_search(int argc, char *argv[], const struct op |
|
Line 426 apropos_search(int argc, char *argv[], const struct op |
|
(*res)(ress, mlen, arg); |
(*res)(ress, mlen, arg); |
free(ress); |
free(ress); |
|
|
|
rc = 1; |
|
out: |
for (i = 0; i < tree.len; i++) |
for (i = 0; i < tree.len; i++) |
recfree(&tree.node[i]); |
recfree(&tree.node[i]); |
|
|
Line 432 apropos_search(int argc, char *argv[], const struct op |
|
Line 439 apropos_search(int argc, char *argv[], const struct op |
|
static int |
static int |
single_search(struct rectree *tree, const struct opts *opts, |
single_search(struct rectree *tree, const struct opts *opts, |
const struct expr *expr, size_t terms, |
const struct expr *expr, size_t terms, |
struct mchars *mc) |
struct mchars *mc, int vol) |
{ |
{ |
int root, leaf, ch; |
int root, leaf, ch; |
uint64_t mask; |
uint64_t mask; |
Line 454 single_search(struct rectree *tree, const struct opts |
|
Line 461 single_search(struct rectree *tree, const struct opts |
|
memset(&r, 0, sizeof(struct rec)); |
memset(&r, 0, sizeof(struct rec)); |
|
|
if (NULL == (btree = btree_open())) |
if (NULL == (btree = btree_open())) |
return(0); |
return(1); |
|
|
if (NULL == (idx = index_open())) { |
if (NULL == (idx = index_open())) { |
(*btree->close)(btree); |
(*btree->close)(btree); |
return(0); |
return(1); |
} |
} |
|
|
while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { |
while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { |
Line 519 single_search(struct rectree *tree, const struct opts |
|
Line 526 single_search(struct rectree *tree, const struct opts |
|
break; |
break; |
|
|
r.lhs = r.rhs = -1; |
r.lhs = r.rhs = -1; |
if ( ! index_read(&key, &val, mc, &r)) |
if ( ! index_read(&key, &val, vol, mc, &r)) |
break; |
break; |
|
|
/* XXX: this should be elsewhere, I guess? */ |
/* XXX: this should be elsewhere, I guess? */ |
Line 596 exprcomp(int argc, char *argv[], size_t *tt) |
|
Line 603 exprcomp(int argc, char *argv[], size_t *tt) |
|
* Return the root of the expression sequence if alright. |
* Return the root of the expression sequence if alright. |
*/ |
*/ |
static struct expr * |
static struct expr * |
exprexpr(int argc, char **argv, int *pos, int *lvl, size_t *tt) |
exprexpr(int argc, char *argv[], int *pos, int *lvl, size_t *tt) |
{ |
{ |
struct expr *e, *first, *next; |
struct expr *e, *first, *next; |
int log; |
int log; |