=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/Attic/apropos.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- src/usr.bin/mandoc/Attic/apropos.c 2012/01/05 22:07:42 1.15 +++ src/usr.bin/mandoc/Attic/apropos.c 2012/04/15 11:54:47 1.16 @@ -1,6 +1,6 @@ -/* $Id: apropos.c,v 1.15 2012/01/05 22:07:42 schwarze Exp $ */ +/* $Id: apropos.c,v 1.16 2012/04/15 11:54:47 schwarze Exp $ */ /* - * Copyright (c) 2011 Kristaps Dzonsons + * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any @@ -15,6 +15,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include #include #include @@ -34,8 +36,9 @@ apropos(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; @@ -54,6 +57,8 @@ 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 +109,17 @@ } rc = apropos_search - (paths.sz, paths.paths, - &opts, e, terms, NULL, list); + (paths.sz, paths.paths, &opts, + e, terms, NULL, &ressz, &res, list); - if (0 == rc) - fprintf(stderr, "%s: Error reading " - "manual database\n", progname); - + 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); } @@ -122,16 +127,20 @@ static void list(struct res *res, size_t sz, void *arg) { - int i; + size_t i; qsort(res, sz, sizeof(struct res), cmp); - for (i = 0; i < (int)sz; i++) - printf("%s(%s%s%s) - %.*s\n", res[i].title, + 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 : "", - 70, res[i].desc); + res[i].desc); + } } static int