summaryrefslogtreecommitdiffstats
path: root/apropos.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-11-27 18:54:01 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-11-27 18:54:01 +0000
commitdd0e5f88129e79f476e873d84e50a2df6c0fb422 (patch)
tree2d2b5131656fc873d94e534c9f43e52d1c4a04f8 /apropos.c
parent9c9b2be283f5e152e4043a33013ba3f871580670 (diff)
downloadmandoc-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.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/apropos.c b/apropos.c
index 8ba45765..95c92d03 100644
--- a/apropos.c
+++ b/apropos.c
@@ -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;
}