From 2c898597ea54b439369f0e3fabc6373729e1ea85 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 ++ doc/coreutils.texi | 2 ++ src/nl.c | 2 +- tests/misc/nl.sh | 12 ++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 61b711611e..7cf15498c6 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/doc/coreutils.texi b/doc/coreutils.texi index a55514d594..8d9320ca24 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -1867,6 +1867,7 @@ Analogous to @option{--body-numbering}. @opindex -i @opindex --line-increment Increment line numbers by @var{number} (default 1). +@var{number} can be negative to decrement. @item -l @var{number} @itemx --join-blank-lines=@var{number} @@ -1916,6 +1917,7 @@ Separate the line number from the text line in the output with @opindex -v @opindex --starting-line-number Set the initial line number on each logical page to @var{number} (default 1). +The starting @var{number} can be negative. @item -w @var{number} @itemx --number-width=@var{number} diff --git a/src/nl.c b/src/nl.c index 154131f366..959909f053 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 c134a98960..fd9c5326c9 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.47.2