version 1.8, 2011/11/20 15:43:14 |
version 1.10, 2011/11/20 16:29:50 |
Line 374 index_read(const DBT *key, const DBT *val, |
|
Line 374 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 391 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)) |
/* 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 425 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 454 single_search(struct rectree *tree, const struct opts |
|
Line 460 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 596 exprcomp(int argc, char *argv[], size_t *tt) |
|
Line 602 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; |