=================================================================== RCS file: /cvs/mandoc/Attic/apropos.c,v retrieving revision 1.10 retrieving revision 1.13 diff -u -p -r1.10 -r1.13 --- mandoc/Attic/apropos.c 2011/11/09 22:05:56 1.10 +++ mandoc/Attic/apropos.c 2011/11/14 10:07:06 1.13 @@ -1,4 +1,4 @@ -/* $Id: apropos.c,v 1.10 2011/11/09 22:05:56 kristaps Exp $ */ +/* $Id: apropos.c,v 1.13 2011/11/14 10:07:06 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,7 +25,7 @@ #include #include -#include "apropos.h" +#include "apropos_db.h" #include "mandoc.h" static int cmp(const void *, const void *); @@ -33,7 +37,9 @@ static char *progname; int main(int argc, char *argv[]) { - int ch, cs; + int ch; + size_t sz; + char *buf; struct opts opts; struct expr *e; extern int optind; @@ -47,9 +53,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 +61,6 @@ main(int argc, char *argv[]) case ('s'): opts.cat = optarg; break; - case ('I'): - cs = 1; - break; default: usage(); return(EXIT_FAILURE); @@ -71,10 +72,31 @@ main(int argc, char *argv[]) if (0 == argc) return(EXIT_SUCCESS); - if (NULL == (e = exprcomp(cs, argv, argc))) { + /* + * Collapse expressions into a single string. + * First count up the contained strings, adding a space at the + * end of each (plus nil-terminator). Then merge. + */ + + for (sz = 0, ch = 0; ch < argc; ch++) + sz += strlen(argv[ch]) + 1; + + buf = mandoc_malloc(++sz); + + for (*buf = '\0', ch = 0; ch < argc; ch++) { + strlcat(buf, argv[ch], sz); + strlcat(buf, " ", sz); + } + + buf[sz - 2] = '\0'; + + if (NULL == (e = exprcomp(buf))) { fprintf(stderr, "Bad expression\n"); + free(buf); return(EXIT_FAILURE); } + + free(buf); /* * Configure databases.