🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #3507

Re: PostScript page reverser?

#3507
From: Gisle Aas
Date: Wed, 31 Oct 1990 18:13
69 lines
2620 bytes
In article <BOB.90Oct30100901@volitans.MorningStar.Com> bob@MorningStar.Com (Bob Sutterfield) writes:
>   Adobe's TranScript package includes a program called "psrev" that can
>   take any format-conformant PostScript document and (re-)reverse it, or
>   even select page ranges for printing.  I've looked through the sources
>   of psroff, psf, a2ps, and groff and found nothing that looks
>   promising.  It's probably a quick hack (likely a Perl one-liner :-)
>   and one of those wheels that shouldn't be reinvented.
>
>   Has anyone written a freely available PostScript page reverser?
>

I once wrote the following perl program. (Not quite a one-line :-)

#!/usr/bin/perl
# simple psrev-clone in perl. Written by Gisle Aas, NCC, Oslo, 1990

@psfile = <>;   # slurp in the whole file

unless ($psfile[0] =~ /^%!PS-Adobe-(.*)/) {
    printf STDERR "This is not a conforming PostScript file\n";
    exit(1);
}
$version = $1;

# Locate pages
for ($i=0; $psfile[$i]; $i++) {
    if ($psfile[$i] =~ /^%%Page:(.*)(\d+)$/) {
        push(@pages,$i);
        push(@labels,$1);
    }
}
if ($#pages == 0) {
    print STDERR "This file contains no PostScript %%Page comments\n";
    exit;
}

# Locate trailer
$trailer = $#psfile;
for ($i = $#psfile; $i > $pages[$#pages]; $i--) {
    if ($psfile[$i] =~ /^%%Trailer/) {
       $trailer = $i;
       last;
    }
}

# Output prolog
for ($i=0; $i < $pages[0]; $i++) {
    print $psfile[$i];
}

# Output pages in reverse order
$pageno = 1;
$prev_lineno = $trailer;
while ($lineno = pop(@pages)) {
    printf "%%%%Page:%s%d\n",pop(@labels),$pageno++;
    for ($i = $lineno + 1; $i < $prev_lineno; $i++) {
        print $psfile[$i];
    }
    $prev_lineno = $lineno;
}

# Output trailer
for ($i = $trailer; $i <= $#psfile; $i++) {
    print $psfile[$i];
}
--
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.90Oct31191354@boeygen.nr.no>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!usc!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!nuug!ulrik!ulrik!aas
References: <BOB.90Oct30100901@volitans.MorningStar.Com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!usc!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!nuug!ulrik!ulrik!aas
From: aas@boeygen.nr.no (Gisle Aas)
Newsgroups: comp.lang.postscript
Subject: Re: PostScript page reverser?
Message-ID: <AAS.90Oct31191354@boeygen.nr.no>
Date: 31 Oct 90 18:13:54 GMT
References: <BOB.90Oct30100901@volitans.MorningStar.Com>
Sender: news@ulrik.uio.no (USENET News System)
Reply-To: Gisle.Aas@nr.no
Organization: Norwegain Computing Centre, Oslo, Norway
Lines: 69
In-Reply-To: bob@MorningStar.Com's message of 30 Oct 90 15:09:08 GMT