|
22 | 22 | ($outfile) = $outfile =~ /(.*)/; # Untaint |
23 | 23 |
|
24 | 24 | END { |
25 | | - if ($? != 0) { |
26 | | - unlink("$outfile.tmp"); |
27 | | - unlink($outfile); |
28 | | - } |
| 25 | + if ($? != 0) { |
| 26 | + unlink("$outfile.tmp"); |
| 27 | + unlink($outfile); |
| 28 | + } |
29 | 29 | } |
30 | 30 |
|
31 | 31 | (my $resdir) = $outfile =~ m#^(build/[^/]+)/#; |
|
44 | 44 | close $fh; |
45 | 45 |
|
46 | 46 | $template =~ / |
47 | | - ^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ([\w-]+?)--$ |
48 | | - (.*?) |
49 | | - (^[^%].*?) |
50 | | - ^%\ --END\ \1\ \2--$ |
| 47 | + ^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ([\w-]+?)--$ |
| 48 | + (.*?) |
| 49 | + (^[^%].*?) |
| 50 | + ^%\ --END\ \1\ \2--$ |
51 | 51 | /msgx; |
52 | 52 |
|
53 | 53 | my $resource = $2; |
|
59 | 59 |
|
60 | 60 | my $neededresources = ''; |
61 | 61 | foreach (split /\s+/, $reqs) { |
62 | | - if ($_ eq 'preamble') { |
63 | | - $neededresources.="Category/uk.co.terryburton.bwipp "; |
64 | | - } else { |
65 | | - $neededresources.="uk.co.terryburton.bwipp/$_ "; |
66 | | - } |
| 62 | + if ($_ eq 'preamble') { |
| 63 | + $neededresources.="Category/uk.co.terryburton.bwipp "; |
| 64 | + } else { |
| 65 | + $neededresources.="uk.co.terryburton.bwipp/$_ "; |
| 66 | + } |
67 | 67 | } |
68 | 68 | $neededresources =~ s/\s+$//; |
69 | 69 |
|
|
74 | 74 | my $category = 'uk.co.terryburton.bwipp'; |
75 | 75 | my $key = $resource; |
76 | 76 | if ($resource eq 'preamble') { |
77 | | - $category = 'Category'; |
78 | | - $key = 'uk.co.terryburton.bwipp'; |
| 77 | + $category = 'Category'; |
| 78 | + $key = 'uk.co.terryburton.bwipp'; |
79 | 79 | } |
80 | 80 |
|
81 | 81 | my $vmusage = '0 0'; |
|
84 | 84 | my $qualifier = "0.0 $yyyy$mm$dd" . sprintf("%02d",$rr || 0); |
85 | 85 |
|
86 | 86 | { |
87 | | - use File::Temp qw(tempfile); |
88 | | - my ($vmusage_fh, $vmusagefile) = tempfile('vmusage.XXXXXX', DIR => '/tmp', UNLINK => 1); |
89 | | - ($vmusagefile) = $vmusagefile =~ /(.*)/; # Untaint |
| 87 | + use File::Temp qw(tempfile); |
| 88 | + my ($vmusage_fh, $vmusagefile) = tempfile('vmusage.XXXXXX', DIR => '/tmp', UNLINK => 1); |
| 89 | + ($vmusagefile) = $vmusagefile =~ /(.*)/; # Untaint |
90 | 90 |
|
91 | | - my $oldpwd = getcwd(); |
92 | | - ($oldpwd) = $oldpwd =~ /(.*)/; # Untaint |
93 | | - chdir("$resdir/Resource") or die "Cannot chdir to $resdir/Resource: $!"; |
| 91 | + my $oldpwd = getcwd(); |
| 92 | + ($oldpwd) = $oldpwd =~ /(.*)/; # Untaint |
| 93 | + chdir("$resdir/Resource") or die "Cannot chdir to $resdir/Resource: $!"; |
94 | 94 |
|
95 | | - open(my $gs_fh, '-|', $gs, '-P', '-dNOSAFER', '-dQUIET', '-dNOPAUSE', '-dBATCH', '-sDEVICE=nullpage', "-sInputFilename=$abspath/$outfile.tmp", "-sOutputFilename=$abspath/$outfile", "-sVMusageFilename=$vmusagefile", "-sCategory=$category", "-sKey=$key", "-sVMusage=$vmusage", "-sQualifier=$qualifier", "-sVersion=$version", "-sNeededResources=$neededresources", "-sPostWatermark=$category/$key $qualifier", "../../$packager") |
96 | | - or die "Cannot execute gs: $!"; |
97 | | - print while <$gs_fh>; |
98 | | - close $gs_fh or die 'GS create resource error'; |
| 95 | + open(my $gs_fh, '-|', $gs, '-P', '-dNOSAFER', '-dQUIET', '-dNOPAUSE', '-dBATCH', '-sDEVICE=nullpage', "-sInputFilename=$abspath/$outfile.tmp", "-sOutputFilename=$abspath/$outfile", "-sVMusageFilename=$vmusagefile", "-sCategory=$category", "-sKey=$key", "-sVMusage=$vmusage", "-sQualifier=$qualifier", "-sVersion=$version", "-sNeededResources=$neededresources", "-sPostWatermark=$category/$key $qualifier", "../../$packager") |
| 96 | + or die "Cannot execute gs: $!"; |
| 97 | + print while <$gs_fh>; |
| 98 | + close $gs_fh or die 'GS create resource error'; |
99 | 99 |
|
100 | | - chdir($oldpwd) or die "Cannot chdir back to $oldpwd: $!"; |
101 | | - unlink("$outfile.tmp"); |
| 100 | + chdir($oldpwd) or die "Cannot chdir back to $oldpwd: $!"; |
| 101 | + unlink("$outfile.tmp"); |
102 | 102 |
|
103 | | - open(my $vm_fh, '-|', $gs, '-dQUIET', '-dNOPAUSE', '-dBATCH', '-sDEVICE=nullpage', '--', $vmusagefile, '2>&1') |
104 | | - or die "Cannot execute gs for VMusage: $!"; |
105 | | - my $vmout = do { local $/; <$vm_fh> }; |
106 | | - close $vm_fh or die "GS measure VMusage error: $vmout"; |
107 | | - ($vmusage) = $vmout =~ /VMusage \((\d+ \d+)\) def/ or die 'Failed to determine VMusage'; |
| 103 | + open(my $vm_fh, '-|', $gs, '-dQUIET', '-dNOPAUSE', '-dBATCH', '-sDEVICE=nullpage', '--', $vmusagefile, '2>&1') |
| 104 | + or die "Cannot execute gs for VMusage: $!"; |
| 105 | + my $vmout = do { local $/; <$vm_fh> }; |
| 106 | + close $vm_fh or die "GS measure VMusage error: $vmout"; |
| 107 | + ($vmusage) = $vmout =~ /VMusage \((\d+ \d+)\) def/ or die 'Failed to determine VMusage'; |
108 | 108 |
|
109 | | - # $vmusagefile auto-deleted when $vmusage_fh goes out of scope |
| 109 | + # $vmusagefile auto-deleted when $vmusage_fh goes out of scope |
110 | 110 | } |
111 | 111 |
|
112 | 112 | # Stamp VMusage into the resource |
113 | 113 | { |
114 | | - $^I = ''; |
115 | | - @ARGV = ($outfile); |
116 | | - while (<>) { |
117 | | - s/%%VMusage: \d+ \d+/%%VMusage: $vmusage/g; |
118 | | - s/%%BeginResource: (.*) \d+ \d+/%%BeginResource: $1 $vmusage/g; |
119 | | - print; |
120 | | - } |
| 114 | + $^I = ''; |
| 115 | + @ARGV = ($outfile); |
| 116 | + while (<>) { |
| 117 | + s/%%VMusage: \d+ \d+/%%VMusage: $vmusage/g; |
| 118 | + s/%%BeginResource: (.*) \d+ \d+/%%BeginResource: $1 $vmusage/g; |
| 119 | + print; |
| 120 | + } |
121 | 121 | } |
122 | 122 |
|
123 | 123 | $? = 0; # Mark successful completion |
|
0 commit comments