commit: 58f36fd6e0c32dcbb73e95e5961f6980a8f69b43
parent e7f60e064f879bb6af8d71b008c8e037e3c5618b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 02:22:01 +0200
cmd/paste: add support for long options
Diffstat:
1 file changed, 19 insertions(+), 0 deletions(-)
diff --git a/cmd/paste.c b/cmd/paste.c
@@ -34,6 +34,7 @@
#define _POSIX_C_SOURCE 200809L
+#include "../config.h"
#include "../libutils/err.h"
#include "../libutils/getopt_nolong.h"
@@ -48,6 +49,9 @@
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
static wchar_t *delim;
static int delimcnt;
@@ -267,7 +271,22 @@ main(int argc, char *argv[])
int seq = 0;
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"delimiter", required_argument, NULL, 'd'},
+ {"serial", no_argument, NULL, 's'},
+ {"zero-terminated", no_argument, NULL, 'z'},
+ {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, "+:d:sz", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":d:sz")) != -1;)
+#endif
{
switch(c)
{