File: gri_unpage

package info (click to toggle)
gri 2.4.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,540 kB
  • ctags: 1,966
  • sloc: cpp: 32,542; lisp: 3,243; perl: 806; makefile: 548; sh: 253
file content (63 lines) | stat: -rw-r--r-- 1,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl

$usage = "
PURPOSE: Chop multipage Gri PostScript file into one file per page.
USAGE:   gri_unpage name.ps -- create files name-1.ps, name-2.ps, etc, one
                               for each page of name.ps.
         gri_unpage -h      -- print this help message

BUGS:    1. Bounding box is always 8.5x11 inches.
         2. Assumes that all Gri fonts are used even if they aren't.
";

eval { require 'getopts.pl' ; };
my $use_getopts = $@ ? 0 : 1;

if ($use_getopts) {
    &Getopts('h');
    if ($opt_h) {
        print "$usage";
        exit 0;
    }
}

if ($#ARGV != 0) {
    die "Wrong number of arguments.\n$usage\n";
}
$file = $ARGV[0];

open(IN, $file) || die "Cannot open input file `$file'\n";
$prologue = "";
while(<IN>) {
    $prologue .= $_;
    last if (/%%EndProlog/);
}
$epilog = "
%%Trailer
%%BoundingBox: 0 0 612 792
%%DocumentFonts: Courier Helvetica Palatino-Roman Palatino-Italic Symbol Times-Roman
%%Pages: 1
";

$page = 0;

while(<IN>) {
    if (/%%Page:/) {
	$page++;
	if ($page < 10) {
	    $name = sprintf("$file-0%d", $page);
	} else {
	    $name = sprintf("$file-%d", $page);
	}
	if ($page != 1) {
	    print OUT $epilog;
	    close(OUT);
	}
	print STDERR "Creating file $name\n";
	open(OUT, ">$name") || die "Cannot open output file `$name'\n";
	print OUT $prologue;
    } else {
	print OUT;
    }
}
close OUT if ($page != 0);