aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apropos_db.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-20 16:29:50 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-20 16:29:50 +0000
commit06acc5d53500a0a7feb20e948d2a07950d0b4bad (patch)
tree0fb899aff7cdbc2cd09c716b7854dc2749fb04a8 /apropos_db.c
parent28e2cf1e5beb4674637a8c3f7f0b0908f817e325 (diff)
downloadmandoc-06acc5d53500a0a7feb20e948d2a07950d0b4bad.tar.gz
mandoc-06acc5d53500a0a7feb20e948d2a07950d0b4bad.tar.zst
mandoc-06acc5d53500a0a7feb20e948d2a07950d0b4bad.zip
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.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/apropos_db.c b/apropos_db.c
index 0ac52624..53418532 100644
--- a/apropos_db.c
+++ b/apropos_db.c
@@ -1,4 +1,4 @@
-/* $Id: apropos_db.c,v 1.9 2011/11/20 15:45:37 kristaps Exp $ */
+/* $Id: apropos_db.c,v 1.10 2011/11/20 16:29:50 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -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))) {