summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-12-05 21:55:04 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-12-05 21:55:04 +0000
commit1c23090f08a7aeaf5a36d9b14dd73f1671924b41 (patch)
treec05974049b1c2012c9f7d4c5e094ba20437e26fa /main.c
parentb3ad7718d1bb1f24324eaed392efbf6df95674ec (diff)
downloadmandoc-1c23090f08a7aeaf5a36d9b14dd73f1671924b41.tar.gz
implement help(1)
Diffstat (limited to 'main.c')
-rw-r--r--main.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/main.c b/main.c
index a9d41285..34a363b5 100644
--- a/main.c
+++ b/main.c
@@ -96,6 +96,8 @@ static void version(void) __attribute__((noreturn));
static int woptions(struct curparse *, char *);
static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
+static char help_arg[] = "help";
+static char *help_argv[] = {help_arg, NULL};
static const char *progname;
@@ -142,6 +144,8 @@ main(int argc, char *argv[])
search.argmode = ARG_EXPR;
else if (strncmp(progname, "whatis", 6) == 0)
search.argmode = ARG_WORD;
+ else if (strncmp(progname, "help", 4) == 0)
+ search.argmode = ARG_NAME;
else
search.argmode = ARG_FILE;
@@ -273,15 +277,24 @@ main(int argc, char *argv[])
resp = NULL;
#endif
- /* Quirk for a man(1) section argument without -s. */
+ /*
+ * Quirks for help(1)
+ * and for a man(1) section argument without -s.
+ */
- if (search.argmode == ARG_NAME &&
- argv[0] != NULL &&
- isdigit((unsigned char)argv[0][0]) &&
- (argv[0][1] == '\0' || !strcmp(argv[0], "3p"))) {
- search.sec = argv[0];
- argv++;
- argc--;
+ if (search.argmode == ARG_NAME) {
+ if (*progname == 'h') {
+ if (argc == 0) {
+ argv = help_argv;
+ argc = 1;
+ }
+ } else if (argv[0] != NULL &&
+ isdigit((unsigned char)argv[0][0]) &&
+ (argv[0][1] == '\0' || !strcmp(argv[0], "3p"))) {
+ search.sec = argv[0];
+ argv++;
+ argc--;
+ }
}
rc = MANDOCLEVEL_OK;