From dfc1c5fe2f232d072fbe6514abe57b63c443baa8 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 24 Mar 2012 00:31:55 +0000 Subject: Simplify by not pre-filtering the result vector for satisfied matches: we can do this in the frontend. --- apropos.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'apropos.c') diff --git a/apropos.c b/apropos.c index 5589cbaf..0ca307a9 100644 --- a/apropos.c +++ b/apropos.c @@ -18,6 +18,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include #include #include @@ -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 -- cgit