]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pr: fix so that LAST_PAGE is honored with -T
authorPádraig Brady <P@draigBrady.com>
Tue, 23 Aug 2011 23:09:30 +0000 (00:09 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 23 Aug 2011 23:21:17 +0000 (00:21 +0100)
Ever since the LAST_PAGE functionality was added
in commit ed0923a1, 1996-12-05,
"Apply big patch (patch-20) from Roland Huebner"
it was ignored when -t or -T were specified or
when -l <= 10.

* src/pr.c (print_page): Increment the current page here.
(print_header): Don't increment the current page here.
* tests/pr/pr-tests: Add a test case.
* NEWS: Mention the fix

Reported at http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9347

NEWS
src/pr.c
tests/pr/pr-tests

diff --git a/NEWS b/NEWS
index 569c33b0a6cd2f21f38cc38efea0c356fe90dbe2..db5a474a09ea8f2436760778504cdfd96853b144 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   as much memory.  du, chmod, chgrp and chown started using fts in 6.0.
   chcon was added in coreutils-6.9.91 with fts support.  ]
 
+  pr -T no longer ignores a specified LAST_PAGE to stop at.
+  [bug introduced in textutils-1.19q]
+
   printf '%d' '"' no longer accesses out-of-bounds memory in the diagnostic.
   [bug introduced in sh-utils-1.16]
 
index 771418c45be4e2d8174588b231ef5ca5a668c3de..d1adc5591f2c28e54b27e6afd90e113554cce720 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1887,7 +1887,7 @@ print_page (void)
       print_a_FF = false;
     }
 
-  if (last_page_number < page_number)
+  if (last_page_number < ++page_number)
     return false;              /* Stop printing with LAST_PAGE */
 
   reset_status ();             /* Change ON_HOLD to OPEN. */
@@ -2399,7 +2399,7 @@ print_header (void)
   /* The translator must ensure that formatting the translation of
      "Page %"PRIuMAX does not generate more than (sizeof page_text - 1)
      bytes.  */
-  sprintf (page_text, _("Page %"PRIuMAX), page_number++);
+  sprintf (page_text, _("Page %"PRIuMAX), page_number);
   available_width = header_width_available - mbswidth (page_text, 0);
   available_width = MAX (0, available_width);
   lhs_spaces = available_width >> 1;
index aafc0cfdbe1545b4844b16237196193f597fdd1d..d3dc25fba6f6911b212f3738cc4131b4c0a0cbd4 100755 (executable)
@@ -403,6 +403,10 @@ my @tv = (
 # This would clobber so much of the heap, it'd segfault or abort every time.
 ['smash-heap', '-t -e300', "a".("\b"x50)."\t", "a\b".(" "x300)."\n", 0],
 ['smash-heap8', '-t -e',   "a".("\b"x50)."\t", "a\b".(" "x  8)."\n", 0],
+
+# Before coreutils-8.13 page numbers were not handled correctly when
+# headers were not printed (when -l <= 10 or -t or -T specified)
+['page-range', '+1:1 -2 -l1 -s" "',  "a\nb\nc\n", "a b\n", 0],
 );
 
 # Convert the above old-style test vectors to the newer