=================================================================== RCS file: /cvs/mandoc/Attic/apropos.c,v retrieving revision 1.10 retrieving revision 1.14 diff -u -p -r1.10 -r1.14 --- mandoc/Attic/apropos.c 2011/11/09 22:05:56 1.10 +++ mandoc/Attic/apropos.c 2011/11/18 07:02:19 1.14 @@ -1,4 +1,4 @@ -/* $Id: apropos.c,v 1.10 2011/11/09 22:05:56 kristaps Exp $ */ +/* $Id: apropos.c,v 1.14 2011/11/18 07:02:19 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -14,6 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -21,11 +25,11 @@ #include #include -#include "apropos.h" +#include "apropos_db.h" #include "mandoc.h" static int cmp(const void *, const void *); -static void list(struct rec *, size_t, void *); +static void list(struct res *, size_t, void *); static void usage(void); static char *progname; @@ -33,7 +37,8 @@ static char *progname; int main(int argc, char *argv[]) { - int ch, cs; + int ch; + size_t terms; struct opts opts; struct expr *e; extern int optind; @@ -47,9 +52,7 @@ main(int argc, char *argv[]) else ++progname; - cs = 0; - - while (-1 != (ch = getopt(argc, argv, "S:s:I"))) + while (-1 != (ch = getopt(argc, argv, "S:s:"))) switch (ch) { case ('S'): opts.arch = optarg; @@ -57,9 +60,6 @@ main(int argc, char *argv[]) case ('s'): opts.cat = optarg; break; - case ('I'): - cs = 1; - break; default: usage(); return(EXIT_FAILURE); @@ -71,7 +71,7 @@ main(int argc, char *argv[]) if (0 == argc) return(EXIT_SUCCESS); - if (NULL == (e = exprcomp(cs, argv, argc))) { + if (NULL == (e = exprcomp(argc, argv, &terms))) { fprintf(stderr, "Bad expression\n"); return(EXIT_FAILURE); } @@ -83,18 +83,20 @@ main(int argc, char *argv[]) * The index database is a recno. */ - apropos_search(&opts, e, NULL, list); + ch = apropos_search(&opts, e, terms, NULL, list); exprfree(e); - return(EXIT_SUCCESS); + if (0 == ch) + fprintf(stderr, "%s: Database error\n", progname); + return(ch ? EXIT_SUCCESS : EXIT_FAILURE); } /* ARGSUSED */ static void -list(struct rec *res, size_t sz, void *arg) +list(struct res *res, size_t sz, void *arg) { int i; - qsort(res, sz, sizeof(struct rec), cmp); + qsort(res, sz, sizeof(struct res), cmp); for (i = 0; i < (int)sz; i++) printf("%s(%s%s%s) - %s\n", res[i].title, @@ -108,18 +110,14 @@ static int cmp(const void *p1, const void *p2) { - return(strcmp(((const struct rec *)p1)->title, - ((const struct rec *)p2)->title)); + return(strcmp(((const struct res *)p1)->title, + ((const struct res *)p2)->title)); } static void usage(void) { - fprintf(stderr, "usage: %s " - "[-I] " - "[-S arch] " - "[-s section] " - "EXPR\n", - progname); + fprintf(stderr, "usage: %s [-S arch] [-s section] " + "expression...\n", progname); }