From e632349ce9ab655bc5628656fb9b1177faf37095 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 9 Dec 2023 22:59:57 +0100 Subject: Literally open grab(1) when someone uses -h --- grab.1 | 2 ++ grab.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/grab.1 b/grab.1 index b86f5d2..147fe4f 100644 --- a/grab.1 +++ b/grab.1 @@ -9,6 +9,8 @@ .Op Fl z .Ar pattern .Op Ar +.Nm +.Fl h .Sh DESCRIPTION .Sh EXIT STATUS .Ex -std diff --git a/grab.c b/grab.c index 117f466..0c3af26 100644 --- a/grab.c +++ b/grab.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -66,7 +67,10 @@ static const cmd_func op_table[UCHAR_MAX] = { static void usage(const char *s) { - fprintf(stderr, "Usage: %s [-d string] pattern [file ...]\n", s); + fprintf(stderr, + "Usage: %s [-z] pattern [file ...]\n" + " %s -h\n", + s, s); exit(EXIT_FAILURE); } @@ -76,13 +80,17 @@ main(int argc, char **argv) int rv, opt; struct ops ops; + argv[0] = basename(argv[0]); if (argc < 2) usage(argv[0]); setlocale(LC_ALL, ""); - while ((opt = getopt(argc, argv, "z")) != -1) { + while ((opt = getopt(argc, argv, "hz")) != -1) { switch (opt) { + case 'h': + if (execlp("man", "man", "1", argv[0], NULL) == -1) + die("execlp: man 1 %s", argv[0]); case 'z': delim = '\0'; break; -- cgit v1.2.3