diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-20 16:29:50 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-20 16:29:50 +0000 |
commit | f58ce4bef2800a6b3fe1b7a02e1a842cbf97aa3d (patch) | |
tree | 2d3fc8013455fcf6b65528334d6ca4080859a10e /apropos_db.c | |
parent | afde6cd162c77758617c4f2a82cda0ffaa96711c (diff) | |
download | mandoc-f58ce4bef2800a6b3fe1b7a02e1a842cbf97aa3d.tar.gz |
Clarify some behaviour, bringing schwarze@'s patch and mine closer together
(although I still don't have -M, which is a big piece).
First, the default search path is the cwd. This will change to use -M
once I look over that code.
If MANPATH is specified, this replaces the cwd.
Both of these are augmented by -m.
If paths don't exist or don't have databases, they're silently ignored.
This makes perfect sense: you may be given a superset of possible paths.
The corner case of no paths (where, say, MANPATH consists of bogus paths
or the cwd is unreadable) simply means that no paths are searched.
Diffstat (limited to 'apropos_db.c')
-rw-r--r-- | apropos_db.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/apropos_db.c b/apropos_db.c index a0e8215a..dcf52453 100644 --- a/apropos_db.c +++ b/apropos_db.c @@ -374,14 +374,13 @@ index_read(const DBT *key, const DBT *val, } /* - * Search mandocdb databases in argv (size argc) for the expression - * "expr". + * Search mandocdb databases in paths for expression "expr". * Filter out by "opts". * Call "res" with the results, which may be zero. * Return 0 if there was a database error, else return 1. */ 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, void (*res)(struct res *, size_t, void *)) { @@ -392,19 +391,24 @@ apropos_search(int argc, char *argv[], const struct opts *opts, memset(&tree, 0, sizeof(struct rectree)); + rc = 0; mc = mchars_alloc(); - for (rc = 1, i = 0; rc && i < argc; i++) { - /* FIXME: ugly warning: we shouldn't get here! */ - if (chdir(argv[i])) + /* + * Main loop. Change into the directory containing manpage + * databases. Run our expession over each database in the set. + */ + + for (i = 0; i < pathsz; i++) { + if (chdir(paths[i])) continue; - rc = single_search(&tree, opts, expr, terms, mc); - /* FIXME: warn and continue... ? */ + if ( ! single_search(&tree, opts, expr, terms, mc)) + goto out; } /* - * Count the matching files - * and feed them to the output handler. + * Count matching files, transfer to a "clean" array, then feed + * them to the output handler. */ for (mlen = i = 0; i < tree.len; i++) @@ -421,6 +425,8 @@ apropos_search(int argc, char *argv[], const struct opts *opts, (*res)(ress, mlen, arg); free(ress); + rc = 1; +out: for (i = 0; i < tree.len; i++) recfree(&tree.node[i]); @@ -454,11 +460,11 @@ single_search(struct rectree *tree, const struct opts *opts, memset(&r, 0, sizeof(struct rec)); if (NULL == (btree = btree_open())) - return(0); + return(1); if (NULL == (idx = index_open())) { (*btree->close)(btree); - return(0); + return(1); } while (0 == (ch = (*btree->seq)(btree, &key, &val, R_NEXT))) { |