Skip to content

Commit

Permalink
pr: incorrect looping with -l
Browse files Browse the repository at this point in the history
* pr enters a strange loop for certain -l values...

%perl pr -l 10 ed
...
Sat Nov 25 08:56:55 2023  Page 526462
...
Sat Nov 25 08:56:55 2023  Page 526463
...
Sat Nov 25 08:56:55 2023  Page 526464
...
Sat Nov 25 08:56:55 2023  Page 526465
...
Sat Nov 25 08:56:55 2023  Page 526466
...
Sat Nov 25 08:56:55 2023  Page 526467
^C

* In create_col(), $pagelength is set to zero for -l 10 because $trailerlength constant is 5
* After studying GNU pr manual, if -l value is 10 or less we assume -t and don't do any formatting of output
* When investigating this I discovered printf() should not occur for "perl pr -t file" (GNU pr copies input to output)
  • Loading branch information
mknos authored Nov 25, 2023
1 parent 759312d commit 89965cb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/pr
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ sub create_col {
my($col)=@_;

my $pagelen=$length-($trailerlength*2);
if ($pagelen <= 0) {
$trailer = 0;
$pagelen = 1;
}
if($doublespace) {
$pagelen=($pagelen%2 == 0)?$pagelen/2:int($pagelen/2)+1;
}
Expand Down Expand Up @@ -337,7 +341,7 @@ sub printpage {
print $numbering;
print $numberchar if ($number);

if (!$column_sep) {
if (!$column_sep && $trailer) {
$pfmt="%-${colwidth}s";
printf("$pfmt", $$column{text}[$line-1]{text});
} else {
Expand Down

0 comments on commit 89965cb

Please sign in to comment.