Article View: comp.lang.postscript
Article #3509Re: PostScript page reverser?
From: Gisle Aas
Date: Wed, 31 Oct 1990 19:15
Date: Wed, 31 Oct 1990 19:15
50 lines
2265 bytes
2265 bytes
In article <AAS.90Oct31191354@boeygen.nr.no> aas@boeygen.nr.no (Gisle Aas) writes:
> I once wrote the following perl program. (Not quite a one-line :-)
Since then I have learned not to write C for loops in perl. So here
you have a rewrite of my psrev program, done the perl way.
#!/usr/local/bin/perl
# Simple psrev clone in perl. Reverses pages of conforming postscript files.
# Author: Gisle Aas, NCC, Oslo. email: <Gisle.Aas@nr.no>
@psfile = <>; # Slurp in the whole file
die "This is not a conforming PostScript file"
unless $psfile[0] =~ /^%!PS-Adobe-(.*)/;
$line = $[; # Locate pages
for (@psfile) {
if (/^%%Page:(.*)(\d+)$/) {
push(@pages,$line);
push(@labels,$1);
}
$line++;
}
die "This file contains no PostScript %%Page comments\n" if $#pages < $[;
$trailer = $#psfile; # Locate trailer
for (reverse(@psfile)) {
last if /^%%Trailer/;
$trailer--;
}
print @psfile[$[..$pages[0] - 1]; # Output prolog
$pageno = 1; # Output pages in reverse order
$to_line = $trailer - 1;
while ($from_line = pop(@pages)) {
printf "%%%%Page:%s%d\n", pop(@labels), $pageno++;
print @psfile[$from_line + 1 .. $to_line];
$to_line = $from_line - 1;
}
print @psfile[$trailer .. $#psfile]; # Output trailer
__END__
--
Gisle Aas | snail: Boks 114 Blindern, N-0314 Oslo, Norway
Norsk Regnesentral | X.400: G=Gisle;S=Aas;O=nr;P=uninett;C=no
voice: +47-2-453561 | inet: Gisle.Aas@nr.no
Technical Details
Message-ID:
<AAS.90Oct31201558@boeygen.nr.no>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!nuug!ulrik!ulrik!aasReferences:
<BOB.90Oct30100901@volitans.MorningStar.Com> <AAS.90Oct31191354@boeygen.nr.no>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!nuug!ulrik!ulrik!aas From: aas@boeygen.nr.no (Gisle Aas) Newsgroups: comp.lang.postscript Subject: Re: PostScript page reverser? Message-ID: <AAS.90Oct31201558@boeygen.nr.no> Date: 31 Oct 90 19:15:58 GMT References: <BOB.90Oct30100901@volitans.MorningStar.Com> <AAS.90Oct31191354@boeygen.nr.no> Sender: news@ulrik.uio.no (USENET News System) Reply-To: Gisle.Aas@nr.no Organization: Norwegain Computing Centre, Oslo, Norway Lines: 50 In-Reply-To: aas@boeygen.nr.no's message of 31 Oct 90 19:13:54