aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-30 15:51:54 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-30 15:51:54 +0100
commitd70d3214b2b26f6d8e1bd6771ffe5cdca2c99cf3 (patch)
treef4388299fe9735e4be0a853df53561d6d78192fb
parent329a4f5b40c85077859ad8be2830d1e3511c10d0 (diff)
Add support for long options
-rw-r--r--grab.14
-rw-r--r--grab.c7
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 <assert.h>
#include <err.h>
+#include <getopt.h>
#include <libgen.h>
#include <limits.h>
#include <locale.h>
@@ -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);