aboutsummaryrefslogtreecommitdiff
path: root/center.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-11-13 08:37:24 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-11-13 09:17:41 +0100
commitbd8824c999571179c963fe7a87a49d01c37c9018 (patch)
tree025ad5a344cd5747a5d2263104309a29c1cc69a0 /center.c
parente9ce2691c913004051c418f7457072df49ca2680 (diff)
Add support for long options
Diffstat (limited to 'center.c')
-rw-r--r--center.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/center.c b/center.c
index f4f2f00..cbc4d54 100644
--- a/center.c
+++ b/center.c
@@ -21,6 +21,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <getopt.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@@ -29,6 +30,7 @@
#include <unistd.h>
#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;