From bd8824c999571179c963fe7a87a49d01c37c9018 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 13 Nov 2022 08:37:24 +0100 Subject: Add support for long options --- center.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'center.c') diff --git a/center.c b/center.c index f4f2f00..cbc4d54 100644 --- a/center.c +++ b/center.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #define ESC 033 +#define OPTSTR "elrt:w:" #define PROG_ARGS "[-elr] [-t width] [-w width] [file ...]\n" #define die(...) err(EXIT_FAILURE, __VA_ARGS__) @@ -74,8 +76,16 @@ main(int argc, char **argv) { int opt; void (*centerfunc)(FILE *) = center; - - while ((opt = getopt(argc, argv, ":elrt:w:")) != -1) { + static struct option longopts[] = { + {"ignore-ansi", no_argument, NULL, 'e'}, + {"longest", no_argument, NULL, 'l'}, + {"spaces", no_argument, NULL, 'r'}, + {"tabsize", required_argument, NULL, 't'}, + {"width", required_argument, NULL, 'w'}, + {NULL, 0, NULL, 0 } + }; + + while ((opt = getopt_long(argc, argv, OPTSTR, longopts, NULL)) != -1) { switch (opt) { case 'e': lenfunc = utf8len; -- cgit v1.2.3