From d70d3214b2b26f6d8e1bd6771ffe5cdca2c99cf3 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 30 Dec 2023 15:51:54 +0100 Subject: Add support for long options --- grab.1 | 4 ++-- grab.c | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/grab.1 b/grab.1 index 4d18f9a..fba3c4e 100644 --- a/grab.1 +++ b/grab.1 @@ -38,9 +38,9 @@ which represents the standard input. .Pp The options are as follows: .Bl -tag -width Ds -.It Fl h +.It Fl h , Fl Fl help Display help information by opening this manual page. -.It Fl z +.It Fl z , Fl Fl zero Separate output data by null bytes .Pq Sq \e0 instead of newlines. diff --git a/grab.c b/grab.c index 0eb2dbc..6d0beba 100644 --- a/grab.c +++ b/grab.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -91,6 +92,10 @@ main(int argc, char **argv) { int opt; struct ops ops; + struct option longopts[] = { + {"help", no_argument, 0, 'h'}, + {"zero", no_argument, 0, 'z'}, + }; argv[0] = basename(argv[0]); if (argc < 2) @@ -98,7 +103,7 @@ main(int argc, char **argv) setlocale(LC_ALL, ""); - while ((opt = getopt(argc, argv, "hz")) != -1) { + while ((opt = getopt_long(argc, argv, "hz", longopts, NULL)) != -1) { switch (opt) { case 'h': execlp("man", "man", "1", argv[0], NULL); -- cgit v1.2.3