aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-09 22:59:57 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-09 22:59:57 +0100
commite632349ce9ab655bc5628656fb9b1177faf37095 (patch)
treea27409582be940fa0c308f9700826ed02b82787a
parentfeb158c34f8eb5dddf83c9f99ced73c92c70f8d1 (diff)
Literally open grab(1) when someone uses -h
-rw-r--r--grab.12
-rw-r--r--grab.c12
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 <assert.h>
#include <err.h>
+#include <libgen.h>
#include <limits.h>
#include <locale.h>
#include <regex.h>
@@ -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;