commit: c4bdb59e7aa11fa552b117a30f8f6cec15cc4005
parent c792c0b615b830983b56bc8c2cc8245dc976c1fa
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 04:13:24 +0200
cmd/seq: add support for long options
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/cmd/seq.c b/cmd/seq.c
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
#define _POSIX_C_SOURCE 200809L
+#include "../config.h"
#include "../libutils/getopt_nolong.h"
#include <ctype.h> // isdigit
@@ -13,6 +14,9 @@
#include <stdlib.h> // exit, strtod
#include <string.h> // strerror
#include <unistd.h> // getopt, optarg, optind
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
const char *argv0 = "seq";
const char *sep = "\n";
@@ -81,7 +85,21 @@ usage(void)
int
main(int argc, char *argv[])
{
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"equal-width", no_argument, NULL, 'w'},
+ {"separator", required_argument, NULL, 's'},
+ {0, 0, 0, 0},
+ };
+ // clang-format on
+
+ // Need + as first character to get POSIX-style option parsing
+ for(int c = -1; (c = getopt_long(argc, argv, "+:ws:t:", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":ws:t:")) != -1;)
+#endif
{
switch(c)
{