aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/apropos.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2012-03-24 00:31:55 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2012-03-24 00:31:55 +0000
commitb0d41b53f31ecf7db5c6777a41fc0184d5d73231 (patch)
treef091045820142264a975c8815ebc0bf1b73afaa0 /apropos.c
parentce34328e22d20a0bb72bd41483eb34a654ea4751 (diff)
downloadmandoc-b0d41b53f31ecf7db5c6777a41fc0184d5d73231.tar.gz
mandoc-b0d41b53f31ecf7db5c6777a41fc0184d5d73231.tar.zst
mandoc-b0d41b53f31ecf7db5c6777a41fc0184d5d73231.zip
Simplify by not pre-filtering the result vector for satisfied matches:
we can do this in the frontend.
Diffstat (limited to 'apropos.c')
-rw-r--r--apropos.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/apropos.c b/apropos.c
index f222f356..5278832e 100644
--- a/apropos.c
+++ b/apropos.c
@@ -1,4 +1,4 @@
-/* $Id: apropos.c,v 1.26 2012/03/23 02:52:33 kristaps Exp $ */
+/* $Id: apropos.c,v 1.27 2012/03/24 00:31:55 kristaps Exp $ */
/*
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -18,6 +18,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <sys/param.h>
#include <assert.h>
#include <getopt.h>
@@ -39,8 +40,9 @@ int
main(int argc, char *argv[])
{
int ch, rc, whatis;
+ struct res *res;
struct manpaths paths;
- size_t terms;
+ size_t terms, ressz;
struct opts opts;
struct expr *e;
char *defpaths, *auxpaths;
@@ -59,6 +61,8 @@ main(int argc, char *argv[])
memset(&paths, 0, sizeof(struct manpaths));
memset(&opts, 0, sizeof(struct opts));
+ ressz = 0;
+ res = NULL;
auxpaths = defpaths = NULL;
conf_file = NULL;
e = NULL;
@@ -104,17 +108,17 @@ main(int argc, char *argv[])
}
rc = apropos_search
- (paths.sz, paths.paths,
- &opts, e, terms, NULL, list);
-
- if (0 == rc)
- fprintf(stderr, "%s: Error reading "
- "manual database\n", progname);
+ (paths.sz, paths.paths, &opts,
+ e, terms, NULL, &ressz, &res, list);
+ if (0 == rc) {
+ fprintf(stderr, "%s: Bad database\n", progname);
+ goto out;
+ }
out:
manpath_free(&paths);
+ resfree(res, ressz);
exprfree(e);
-
return(rc ? EXIT_SUCCESS : EXIT_FAILURE);
}
@@ -126,13 +130,16 @@ list(struct res *res, size_t sz, void *arg)
qsort(res, sz, sizeof(struct res), cmp);
- for (i = 0; i < sz; i++)
+ for (i = 0; i < sz; i++) {
+ if ( ! res[i].matched)
+ continue;
printf("%s(%s%s%s) - %.70s\n",
res[i].title,
res[i].cat,
*res[i].arch ? "/" : "",
*res[i].arch ? res[i].arch : "",
res[i].desc);
+ }
}
static int