summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpsresize2.pl38
1 files changed, 29 insertions, 9 deletions
diff --git a/psresize2.pl b/psresize2.pl
index d37e2d4..2638cd3 100755
--- a/psresize2.pl
+++ b/psresize2.pl
@@ -203,10 +203,13 @@ if (defined $crop) {
# Need to duplicate FIN, since it will be closed in the parent process
open *KIDFIN, "<&FIN" or die "Can't dup FIN: $!";
-
- my $pid = open3 "<&KIDFIN", ">&GS", *GS,
- 'gs', '-sDEVICE=bbox', '-dBATCH', '-dNOPAUSE', '-'
- or die "Can't run: `gs -sDEVICE=bbox -dBATCH -dNOPAUSE -'";
+
+ my @cmd = ('gs', '-sDEVICE=bbox', '-dBATCH', '-dNOPAUSE', '-');
+ my $pid = open3 "<&KIDFIN", ">&GS", *GS, @cmd
+ or die "Can't run: `" . &printcmd (@cmd) . "'";
+ # TODO: this `die' is actually useless, since it doesn't catch the
+ # signals of the child
+
my $n = 0;
my ($x0, $y0, $x1, $y1) = (1<<16, 1<<16, -(1<<16), -(1<<16));
while (<GS>) {
@@ -215,7 +218,7 @@ if (defined $crop) {
$y0 = $2 if $2 < $y0;
$x1 = $3 if $3 > $x1;
$y1 = $4 if $4 > $y1;
- print STDERR "[", ++$n, "] ";
+ print STDERR "[", ++$n, "] " unless defined $quiet;
}
}
close GS;
@@ -263,9 +266,10 @@ my $spec = 0 . &calc_pstops_page(@bbox, $x0, $y0, $x1, $y1);
# Run the program and filter the output
#
-my $pid = open2 *FINPS2PS, "<&FIN",
- 'pstops', "-w$outwidth", "-h$outheight", "$spec"
- or die "Can't run `pstops -w$outwidth -h$outheight $spec': $!\n";
+my @cmd = ('pstops', "-w$outwidth", "-h$outheight", "$spec");
+push @cmd, '-q' if defined $quiet;
+my $pid = open2 *FINPS2PS, "<&FIN", @cmd
+ or die "Can't run: `" . &printcmd (@cmd) . "'";
my $l;
# Header and comments
@@ -385,7 +389,7 @@ sub round {
#
-# In-place convert the given length into postscript points
+# In-place convert the given length to PostScript points
#
sub topoints {
my $l = $_;
@@ -447,3 +451,19 @@ sub papersize {
die "Unknown paper size: `$p'";
}
}
+
+#
+# Print a command just like you'd do it in a shell
+#
+sub printcmd {
+ my @cmd;
+
+ for (@_) {
+ my $s = $_;
+ $s =~ s/"/\\"/;
+ $s = "\"$s\"" if $s =~ /[ ()';#{}*?~&|`]/;
+ push @cmd, $s;
+ }
+
+ join ' ', @cmd;
+}