diff options
Diffstat (limited to 'editor/pnmquant')
-rwxr-xr-x | editor/pnmquant | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/editor/pnmquant b/editor/pnmquant index f7af9e7a..4dd133f1 100755 --- a/editor/pnmquant +++ b/editor/pnmquant @@ -37,9 +37,16 @@ use Getopt::Long; use File::Spec; #use Fcntl ":seek"; # not available in Perl 5.00503 use Fcntl; # gets open flags +use IO::Handle; my ($TRUE, $FALSE) = (1,0); +sub pm_message($) { + STDERR->print("pnmquant: $_[0]\n"); +} + + + my ($SEEK_SET, $SEEK_CUR, $SEEK_END) = (0, 1, 2); @@ -59,16 +66,17 @@ sub doVersionHack($) { sub tempFile($) { + my ($suffix) = @_; + # We trust Perl's File::Temp to do a better job of creating the temp # file, but it doesn't exist before Perl 5.6.1. if (eval { require File::Temp; 1 }) { return File::Temp::tempfile("pnmquant_XXXX", - SUFFIX=>".pnm", + SUFFIX=>$suffix, DIR=>File::Spec->tmpdir(), UNLINK=>$TRUE); } else { - my ($suffix) = @_; my $fileName; local *file; # For some inexplicable reason, must be local, not my my $i; @@ -102,17 +110,16 @@ sub parseCommandLine(@) { "plain"); if (!$optsAreValid) { - print(STDERR "Invalid option syntax.\n"); + pm_message("Invalid option syntax"); exit(1); } if (@ARGV > 2) { - print(STDERR "This program takes at most 2 arguments. You specified ", - scalar(@ARGV), "\n"); + pm_message("This program takes at most 2 arguments. You specified " . + scalar(@ARGV)); exit(1); } elsif (@ARGV < 1) { - print(STDERR - "You must specify the number of colors as an argument.\n"); + pm_message("You must specify the number of colors as an argument."); exit(1); } my $infile; @@ -120,9 +127,8 @@ sub parseCommandLine(@) { if (!($cmdline{ncolors} =~ m{ ^[[:digit:]]+$ }x ) || $cmdline{ncolors} == 0) { - print(STDERR - "Number of colors argument '$cmdline{ncolors}' " . - "is not a positive integer.\n"); + pm_message("Number of colors argument '$cmdline{ncolors}' " . + "is not a positive integer."); exit(1); } @@ -210,8 +216,8 @@ sub makeColormap($$$$$$$) { my ($mapfileFh, $mapfileSpec) = tempFile(".pnm"); if (!defined($mapfileFh)) { - print(STDERR "Unable to create temporary file for colormap. " . - "errno = $ERRNO\n"); + pm_message("Unable to create temporary file for colormap. " . + "errno = $ERRNO"); exit(1); } @@ -223,8 +229,8 @@ sub makeColormap($$$$$$$) { (defined($opt_center) ? 1 : 0); if ($colorSummaryOptCt > 1) { - print(STDERR "You can specify only one of " . - "-meanpixel, -meancolor, and -center\n"); + pm_message("You can specify only one of " . + "-meanpixel, -meancolor, and -center"); exit(1); } if (defined($opt_meanpixel)) { @@ -240,8 +246,8 @@ sub makeColormap($$$$$$$) { (defined($opt_spreadbrightness) ? 1 : 0); if ($spreadOptCt > 1) { - print(STDERR "You can specify only one of " . - "-spreadluminosity and -spreadbrightness\n"); + pm_message("You can specify only one of " . + "-spreadluminosity and -spreadbrightness"); exit(1); } @@ -263,7 +269,7 @@ sub makeColormap($$$$$$$) { my $maprc = system("pnmcolormap", $ncolors, @options); if ($maprc != 0) { - print(STDERR "pnmcolormap failed, rc=$maprc\n"); + pm_message("pnmcolormap failed, rc=$maprc"); exit(1); } return $mapfileSpec; @@ -287,15 +293,15 @@ sub remap($$$$$$) { } if ($opt_norandom) { if (defined($opt_randomseed)) { - print(STDERR "You cannot specify -randomseed with -norandom\n"); + pm_message("You cannot specify -randomseed with -norandom"); exit(1); } push(@options, "-norandom"); } if (defined($opt_randomseed)) { if ($opt_randomseed < 0) { - print(STDERR "-randomseed value must not be negative. " . - "You specified $opt_randomseed\n"); + pm_message("-randomseed value must not be negative. " . + "You specified $opt_randomseed"); exit(10); } push(@options, "-randomseed=$opt_randomseed"); @@ -310,7 +316,7 @@ sub remap($$$$$$) { my $remaprc = system("pnmremap", "-mapfile=$mapfileSpec", @options); if ($remaprc != 0) { - print(STDERR "pnmremap failed, rc=$remaprc\n"); + pm_message("pnmremap failed, rc=$remaprc"); exit(1); } } |