diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-27 18:54:01 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-11-27 18:54:01 +0000 |
commit | dd0e5f88129e79f476e873d84e50a2df6c0fb422 (patch) | |
tree | 2d2b5131656fc873d94e534c9f43e52d1c4a04f8 /apropos.c | |
parent | 9c9b2be283f5e152e4043a33013ba3f871580670 (diff) | |
download | mandoc-dd0e5f88129e79f476e873d84e50a2df6c0fb422.tar.gz |
Get us a whatis(1) mode for apropos(1).
This is from a patch to tech@ as critiqued by schwarze@, checked in to
get the ball rolling.
Diffstat (limited to 'apropos.c')
-rw-r--r-- | apropos.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -38,7 +38,7 @@ static char *progname; int main(int argc, char *argv[]) { - int ch, rc; + int ch, rc, whatis; struct manpaths paths; size_t terms; struct opts opts; @@ -53,12 +53,13 @@ main(int argc, char *argv[]) else ++progname; + whatis = 0 == strcmp(progname, "whatis"); + memset(&paths, 0, sizeof(struct manpaths)); memset(&opts, 0, sizeof(struct opts)); auxpaths = defpaths = NULL; e = NULL; - rc = 0; while (-1 != (ch = getopt(argc, argv, "M:m:S:s:"))) switch (ch) { @@ -76,20 +77,23 @@ main(int argc, char *argv[]) break; default: usage(); - goto out; + return(EXIT_FAILURE); } argc -= optind; argv += optind; - if (0 == argc) { - rc = 1; - goto out; - } + if (0 == argc) + return(EXIT_SUCCESS); + + rc = 0; manpath_parse(&paths, defpaths, auxpaths); - if (NULL == (e = exprcomp(argc, argv, &terms))) { + e = whatis ? termcomp(argc, argv, &terms) : + exprcomp(argc, argv, &terms); + + if (NULL == e) { fprintf(stderr, "%s: Bad expression\n", progname); goto out; } |