diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 15:51:54 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-12-30 15:51:54 +0100 |
commit | d70d3214b2b26f6d8e1bd6771ffe5cdca2c99cf3 (patch) | |
tree | f4388299fe9735e4be0a853df53561d6d78192fb | |
parent | 329a4f5b40c85077859ad8be2830d1e3511c10d0 (diff) |
Add support for long options
-rw-r--r-- | grab.1 | 4 | ||||
-rw-r--r-- | grab.c | 7 |
2 files changed, 8 insertions, 3 deletions
@@ -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. @@ -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); |