]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nl: support a negative --line-increment
authorKOBAYASHI Takashi <a1415tk@aiit.ac.jp>
Sun, 25 Oct 2020 17:09:04 +0000 (17:09 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 26 Oct 2020 13:15:46 +0000 (13:15 +0000)
* 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
doc/coreutils.texi
src/nl.c
tests/misc/nl.sh

diff --git a/NEWS b/NEWS
index 61b711611e85af2ec4f80ec540a31e82024a9d39..7cf15498c6ecfc766a584f9158b08ccd51d593d1 100644 (file)
--- 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.
index a55514d594c516ae8d9cdf0ff26bbb5e39915b36..8d9320ca248b6e9bcfc9f1b0fda15da0de6361ec 100644 (file)
@@ -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}
index 154131f366f34363e129c0bf803f7756ef4a7382..959909f053ade0259e838f4c1501132854eb17cf 100644 (file)
--- 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':
index c134a9896000224523b5030371350ea00a236c2a..fd9c5326c921edf1bbce29e49b24f650153a6cd6 100755 (executable)
@@ -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 <<EOF > 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