Debian Codegraph @

fixtd

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/perl
2 #############################################################################
3 # This scripts changes a postscript with twoup so that every other page
4 # will no longer be printed upside down.
5 #
6 # The postscript code was copied from the 'parr' program that came together
7 # with the perl-reference guide by Johan Vromans.
8 #
9 # Copyright (C) 1999 Dov Grobgeld <[email protected]>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #
25 #############################################################################
26
27 while ($ARGV[0] =~ /^-/) {
28 $_ = shift;
29
30 if (/^-mode/) {
31 $mode = shift;
32 }
33 elsif (/^-tumble/) {
34 $tumble++;
35 }
36 elsif (/^-simplex/) {
37 $simplex++;
38 }
39 elsif (/-h(elp)?/) {
40 print<<EOH
41 fixdt - insert tumble and duplex directives in a PostScript file
42
43 Syntax:
44 fixtumble [-simplex] [-tumble] filename
45
46 Options:
47
48 -simplex Simplex printing. (Default is duplex)
49 -tumble Tumble pages.
50 EOH
51 ; exit;
52 }
53 }
54
55 while(<>) {
56 unless ($mode) {
57 if (/dvips/) { $mode='dvips'; }
58 elsif (/mpage/) { $mode='mpage'; }
59 elsif (/Start of enscript\.pro/) { $mode='enscript'; }
60 elsif (/pstops/) { $mode='pstops'; }
61 elsif (/ditroff/) { $mode='reenc'; }
62 elsif (($.==1000) || eof) { $mode='giveup'; last; }
63 }
64 else {
65 if ($mode eq 'dvips') {
66 last if /%%EndSetup/;
67 }
68 elsif ($mode eq 'mpage') {
69 last if /^statusdict/;
70 }
71 elsif ($mode eq 'enscript') {
72 last if /^%%EndProlog/;
73 }
74 elsif ($mode eq 'reenc') {
75 last if /^\/reencsmalldict/;
76 }
77 }
78 push(@P,$_);
79 }
80 die "Unable to determine format!\n" unless $mode;
81
82 if ($mode eq 'giveup') {
83 # Insert in first noncomment place
84 $i=0;
85 $p=shift(@P);
86 (print $p), ($p=shift(@P)) until $p!~ /^%/;
87 $_= $p.join("",@P) . $_;
88 }
89 else { print @P; }
90 print 'statusdict /setduplexmode known ' .
91 '{ statusdict begin true setduplexmode end } if',"\n" unless $simplex;
92 print 'statusdict /settumble known ' .
93 '{ statusdict begin true settumble end } if',"\n" if $tumble;
94 print $_;
95
96 # Copy the rest of it
97 while (<>) {
98 print;
99 }
100