On Sat, May 11, 2024 at 11:18:43PM +0200, Steffen Nurpmeso wrote:
Ralph Corderoy wrote in
<20240511091822.B6691215AA(a)orac.inputplus.co.uk>:
|Hi Steffen,
|
|> pr has always been enscript here, for example.
|
|enscript turns text into PostScript. That's not too handy to read.
|pr's output doesn't have to be sent to a printer. I doubt there's
|a week goes by without my using it. It just depends what your fingers
|know.
Nah, it can create text too (with control sequences, but that you
can filter away again, and mostly there are none, anyway).
I am actually not using it no more that often; i used it often to
review (80 column) code via printout, and it can/could give you
8 pages on a single DIN A4 paper. (Or two times 4 pages, to be
more exact.)
Wow, that brings back memories. Let me look. Yeah here it is.
Prints 8 pages per page from postscript. Pretty sure I wrote it,
it looks like my style. But 100% sure it was useful when my eyesight
was better :-)
#!/usr/bin/perl -w
open(STDOUT, "|mpage -a -P- -8");
# Print the starting stuff
while (<>) {
print;
last if /%%EndProlog/;
}
$base = "/tmp/psrev";
$page = 1;
# Save each page from
# %%Page to the next in a file
$_ = <>;
while ($_ && !/%%Trailer/) {
$file = $base . $page++;
#warn "Creating $file\n";
open(OUT, ">$file");
do {
print OUT;
$_ = <>;
} while ($_ && !/%%Page/ && !/%%Trailer/);
close(OUT);
}
# Take each 8 and print them in the right order
$here = 0;
while ($here < $page - 8) {
foreach $i (2,4,6,8,1,3,5,7) {
&show($here + $i);
}
$here += 8;
}
# One page left.
if ($here == $page - 2) {
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
}
# Two pages left
if ($here == $page - 3) {
&show($here + 2);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
}
# Three pages left
if ($here == $page - 4) {
&show($here + 2);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
&show($here + 3);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
}
# Four pages left
if ($here == $page - 5) {
&show($here + 2);
&show($here + 4);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
&show($here + 3);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
}
# Five pages left
if ($here == $page - 6) {
&show($here + 2);
&show($here + 4);
print "%%Page: 0 0\nshowpage\n";
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
&show($here + 3);
&show($here + 5);
print "%%Page: 0 0\nshowpage\n";
}
# Six pages left
if ($here == $page - 7) {
&show($here + 2);
&show($here + 4);
&show($here + 6);
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
&show($here + 3);
&show($here + 5);
print "%%Page: 0 0\nshowpage\n";
}
# Seven pages left
# foreach $i (2,4,6,8,1,3,5,7) {
if ($here == $page - 8) {
&show($here + 2);
&show($here + 4);
&show($here + 6);
print "%%Page: 0 0\nshowpage\n";
&show($here + 1);
&show($here + 3);
&show($here + 5);
&show($here + 7);
}
if ($_) {
do {
print;
} while (defined($_ = <>));
}
exit;
sub show
{
local($p) = $_[0];
$file = $base . $p;
if (-e $file) {
#warn "Doing $file\n";
open(IN, $file);
while (defined($line = <IN>)) {
print $line;
}
unlink($file);
}
}