summaryrefslogtreecommitdiffstats
path: root/dnp-mangleppd.pl
blob: 74364e5824c2127c9e622e55fb6afcd2128cfab9 (plain)
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
#!/usr/bin/perl -w

# cups-genppd.5.2 -p /tmp -Z dnp-ds40 dnp-ds620 dnp-ds80 dnp-dsrx1
# for x in /tmp/*ppd ; do perl dnp-mangleppd.pl $x ; done

my ($ppd, %sizes);

$ppd = shift(@ARGV);

open FILE, "<$ppd" || die ("can't open file");

while(<FILE>) {
    if ($_ =~ "/\*PageSize (.*)\/(.*):.*/") {
	$sizes{$1} = $2;
    }
}

close FILE;

foreach my $key (keys(%sizes)) {
    open FILE, "<$ppd" || die ("can't open file $ppd");

    my $out = $ppd;
    $out =~ s/.*stp-dnp-(.*)\.5\.2\.ppd/$1/;
    $out =~ tr/a-z/A-Z/;
    $out =~ s/DSRX1/RX1/;
    
    $sizes{"$key"} =~ s/(.*)\*(.*)/$1_x$2/;
    $sizes{"$key"} =~ s/(.*)\+(.*)/$1_$2/;

    print "--> $key = $sizes{$key}\n";
    
    open FILE2, ">$out-$sizes{$key}.ppd";

    while(<FILE>) {
	s/\*DefaultPageSize: .*/*DefaultPageSize: $key/;
	s/\*DefaultPageRegion: .*/*DefaultPageRegion: $key/;
	s/\*DefaultImageableArea: .*/*DefaultImageableArea: $key/;
	s/\*DefaultPaperDimension: .*/*DefaultPaperDimension: $key/;
	s/\*DefaultStpColorCorrection: .*/*DefaultStpColorCorrection: Uncorrected/;
	s/\*DefaultStpColorPrecision: .*/*DefaultStpColorPrecision: Best/;

	print FILE2 "$_";
    }
    
    close FILE;
    close FILE2;
}