From ffa0d9869fe04de4649c4101f2117473ad91fcdf Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 24 Apr 2016 22:54:44 +0000 Subject: Add -version, change temporary file handling git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2717 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/ppmshadow | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'editor/ppmshadow') diff --git a/editor/ppmshadow b/editor/ppmshadow index 62cdf8b8..87ccd292 100755 --- a/editor/ppmshadow +++ b/editor/ppmshadow @@ -48,6 +48,7 @@ exec perl -w -x -S -- "$0" "$@" ############################################################################## use strict; +use File::Temp; require 5.0; # The good open() syntax, with the mode separate from the file name, # came after 5.0. So did mkdir() with default mode. @@ -55,6 +56,20 @@ require 5.0; my $true=1; my $false=0; + +sub doVersionHack($) { + my ($argvR) = @_; + + my $arg1 = $argvR->[0]; + + if (defined($arg1) && (($arg1 eq "--version") || ($arg1 eq "-version"))) { + my $termStatus = system('pamarith', '--version'); + exit($termStatus == 0 ? 0 : 1); + } +} + + + sub getDimensions($) { my ($fileName) = @_; #----------------------------------------------------------------------------- @@ -95,15 +110,10 @@ sub makeConvolutionKernel($$) { # MAINLINE ############################################################################## - -my $tmpdir = $ENV{TMPDIR} || "/tmp"; -my $ourtmp = "$tmpdir/ppmshadow$$"; -mkdir($ourtmp, 0777) or - die("Unable to create directory for temporary files '$ourtmp"); +doVersionHack(\@ARGV); # Process command line options - my $ifile; # Input file name my ($xoffset, $yoffset); @@ -113,6 +123,7 @@ my $translucent = $false; # Default not translucent while (@ARGV) { my $arg = shift; + if ((substr($arg, 0, 1) eq '-') && (length($arg) > 1)) { my $opt; $opt = substr($arg, 1, 1); @@ -142,6 +153,8 @@ while (@ARGV) { if ($yoffset < 0) { $yoffset = -$xoffset; } + } else { + die("Unknown option '$opt'\n"); } } else { if (defined $ifile) { @@ -151,6 +164,19 @@ while (@ARGV) { } } +# Create temporary directory + +my $tmpdir = $ENV{TMPDIR} || "/tmp"; +my $ourtmp; + +if ($keeptemp) { + $ourtmp = "$tmpdir/ppmshadow$$"; + mkdir($ourtmp, 0777) or + die("Unable to create directory for temporary files '$ourtmp"); +} else { + $ourtmp = File::Temp::tempdir("$tmpdir/ppmrainbowXXXX", UNLINK=>1); +} + # Apply defaults for arguments not specified if (!(defined $xoffset)) { -- cgit 1.4.1