From d30690e8a6d494287d655e1bddd722f5c0bee432 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sat, 25 Apr 2009 22:49:52 +0000 Subject: exit with proper exit status upon failure git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@894 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- generator/ppmrainbow | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'generator/ppmrainbow') diff --git a/generator/ppmrainbow b/generator/ppmrainbow index 90a940bf..f98536cd 100755 --- a/generator/ppmrainbow +++ b/generator/ppmrainbow @@ -6,6 +6,13 @@ my ($FALSE, $TRUE) = (0,1); (my $myname = $0) =~ s#\A.*/##; +sub fatal($) { + my ($msg) = @_; + + print(STDERR "$msg\n"); + exit(1); +} + my ($Twid, $Thgt, $tmpdir, $norepeat, $verbose); # set defaults @@ -21,15 +28,16 @@ GetOptions("width=i" => \$Twid, "norepeat!" => \$norepeat, "verbose!" => \$verbose); -die "invalid width and/or height" unless $Twid >= 1 && $Thgt >= 1; - +if ($Twid < 1 || $Thgt < 1) { + fatal("invalid width and/or height"); +} my $verboseCommand = $verbose ? "set -x;" : ""; if (@ARGV < 1) { - die("You must specify at least one color as an argument"); + fatal("You must specify at least one color as an argument"); } elsif (@ARGV < 2 && $norepeat) { - die("With the -norepeat option, you must specify at least two colors " . - "as arguments."); + fatal("With the -norepeat option, you must specify at least two colors " . + "as arguments."); } my @colorlist; @@ -57,7 +65,7 @@ while (@colorlist >= 2) { my $rc = system("$verboseCommand pgmramp -lr $w $Thgt | " . "pgmtoppm \"$colorlist[0]-$colorlist[1]\" >$outfile"); if ($rc != 0) { - die("pgmramp|pgmtoppm failed."); + fatal("pgmramp|pgmtoppm failed."); } $widthRemaining -= $w; $n++; -- cgit 1.4.1