logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: e586ba803d431e4b73af962f25643a24b59a4bf6
parent 0178310640f9a9744669523772b6c107074e7fa1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 25 Jul 2025 11:04:17 +0200

cmd/uniq: add support for long options

Diffstat:

Mcmd/uniq.c21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/cmd/uniq.c b/cmd/uniq.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> // isblank @@ -12,6 +13,9 @@ #include <stdlib.h> // atoi #include <string.h> // strncmp #include <unistd.h> // getopt +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif enum uniq_mode { @@ -31,7 +35,24 @@ main(int argc, char *argv[]) char *endptr = NULL; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"count", no_argument, NULL, 'c'}, + {"repeated", no_argument, NULL, 'd'}, + {"skip-fields", required_argument, NULL, 'f'}, + {"skip-chars", required_argument, NULL, 's'}, + {"unique", no_argument, NULL, 'u'}, + {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, "+:cdf:s:u", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":cdf:s:u")) != -1;) +#endif { switch(c) {