>From 23926a5276df3e9345b6924fa29f185975bc01ac Mon Sep 17 00:00:00 2001 From: KOBAYASHI Takashi Date: Sun, 25 Oct 2020 17:09:04 +0000 Subject: [PATCH] nl: support a negative --line-increment * src/nl.c (main): Allow -i to accept down to INTMAX_MIN. * tests/misc/nl.sh: Add test cases. * NEWS: Mention the new feature. --- NEWS | 2 ++ src/nl.c | 2 +- tests/misc/nl.sh | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 61b711611..7cf15498c 100644 --- a/NEWS +++ b/NEWS @@ -36,6 +36,8 @@ GNU coreutils NEWS -*- outline -*- ls --classify now supports the "always", "auto", or "never" flags, to support only outputting classifier characters if connected to a tty. + nl --line-increment can now take a negative number to decrement the count. + ** Improvements stat and tail now know about the "vboxsf" file system type. diff --git a/src/nl.c b/src/nl.c index 154131f36..959909f05 100644 --- a/src/nl.c +++ b/src/nl.c @@ -521,7 +521,7 @@ main (int argc, char **argv) 0); break; case 'i': - page_incr = xdectoimax (optarg, 1, INTMAX_MAX, "", + page_incr = xdectoimax (optarg, INTMAX_MIN, INTMAX_MAX, "", _("invalid line number increment"), 0); break; case 'p': diff --git a/tests/misc/nl.sh b/tests/misc/nl.sh index c134a9896..fd9c5326c 100755 --- a/tests/misc/nl.sh +++ b/tests/misc/nl.sh @@ -67,4 +67,16 @@ EOF compare exp out || fail=1 returns_ 1 nl -p -v$INTMAX_MAX in.txt > out || fail=1 +# Test negative iteration +returns_ 1 nl -i$INTMAX_UFLOW /dev/null || fail=1 +printf '%s\n' a b > in.txt || framework_failure_ +nl -v$INTMAX_MAX -i$INTMAX_MIN in.txt > out || fail=1 +cat < exp +$INTMAX_MAX a + -1 b +EOF +compare exp out || fail=1 +printf '%s\n' a b c > in.txt || framework_failure_ +returns_ 1 nl -v$INTMAX_MAX -i$INTMAX_MIN in.txt > out || fail=1 + Exit $fail -- 2.26.2