#!/usr/contrib/bin/perl -w # Arrange pages of a Postscript file for printing up2 booklets # $Log: up2,v $ # Revision 1.2 1996/06/08 23:04:41 tjchol01 # Moved file tests before format tests. # # Revision 1.1 1996/06/08 23:00:17 tjchol01 # Initial revision # #use strict; use Text::Abbrev; my %dat = ( "up2" => [0.6933333, 8.06, 0.0, 5.106666, ""], "numerical recipes" => [0.92, 9.5, -0.5, 5.28, ""], "snns" => [0.7727, 8.7, -0.38, 5.7, ""], "a4" => [0.7727, 8.7, -0.38, 5.1, ""], "mathematica" => [0.7727, 8.5, -0.6682, 5.1, ""], "man" => [0.7, 8.26, 0, 5.846, ""], "fulli" => [0.6, 8.06, 0, 5.1067, ""], "music a4" => [0.6, 8.06, 0.25, 5.75, "-pa4"], "netscape" => [0.6933333, 8.06, -0.18, 5.406666, ""], "bbdb" => [0.6, 8.06, 0.2, 5.3067, ""], "knuth" => [0.85, 9.3, 0.0, 5.2, ""], ); format STDERR_TOP = Usage: up2 filename [format] key mag dy dx1 dx2 args . format STDERR = @<<<<<<<<<<<<<<<<<<@#.### @#.## @#.## @#.## @<<<<<<<<<<<<<<< $key, $mag, $dy, $dx1, $dx2, $args . if ($#ARGV < 0) { my $value; while (($key, $value) = each %dat) { ($mag, $dy, $dx1, $dx2, $args) = @$value; write STDERR; } exit 1; } my $file = $ARGV[0]; -r $file || die "Cannot read \"$file\"\n"; -T $file || die "\"$file\" is not a text file\n"; my $sh; %main::lok = (); abbrev (*main::lok, keys %dat); if ($#ARGV < 1) { $sh = "up2"; } else { $sh = $main::lok{$ARGV[1]} || die "Unsupported format\n"; } ($mag, $dy, $dx1, $dx2, $args) = @{$dat{$sh}}; #print "($mag, $dy, $dx1, $dx2, $args)\n"; print "Format: $sh\n"; my $pstops = "pstops $args "; $psselect = "psselect"; my $left = "L\@${mag}(${dy}in,${dx1}in)"; my $right = "L\@${mag}(${dy}in,${dx2}in)"; # ordering # man: -3, 0 / 1, -2 # up2: 3, 0 / -1, -2 # up2full: -3, 0 / -1, 2 # make number of pages divisible by 4 and create up2 arrangement open (PAG, "($pstops 4:0,1,2,3 $file | $pstops '2:-1$left+0$right' > ${file}1) 2>&1 | ") || die "$!\n"; my @pag = ; close PAG; #print "@pag"; my $lalin = $pag[$#pag]; $lalin =~ s/^.*Wrote (\d+) page.*\n$/$1/g || die "No pages info: $lalin\n"; my $half = $lalin / 2; print "$half sheets\n"; if ($lalin % 2 != 0) { die "There should be an even number of pages\n"; } # split into front and back pages system ("$psselect -q -p$half-1,_$half-_1 ${file}1 ${file}0"); unlink "${file}1"; #system ("$psselect -r -q -p1-$half ${file}0 ${file}1"); #system ("$psselect -q -p_$half-_1 ${file}0 ${file}2");