| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
############################################################################## |
| 4 |
# This is essentially a Perl program. We exec the Perl interpreter specifying |
| 5 |
# this same file as the Perl program and use the -x option to cause the Perl |
| 6 |
# interpreter to skip down to the Perl code. The reason we do this instead of |
| 7 |
# just making /usr/bin/perl the script interpreter (instead of /bin/sh) is |
| 8 |
# that the user may have multiple Perl interpreters and the one he wants to |
| 9 |
# use is properly located in the PATH. The user's choice of Perl interpreter |
| 10 |
# may be crucial, such as when the user also has a PERL5LIB environment |
| 11 |
# variable and it selects modules that work with only a certain main |
| 12 |
# interpreter program. |
| 13 |
# |
| 14 |
# An alternative some people use is to have /usr/bin/env as the script |
| 15 |
# interpreter. We don't do that because we think the existence and |
| 16 |
# compatibility of /bin/sh is more reliable. |
| 17 |
# |
| 18 |
# Note that we aren't concerned about efficiency because the user who needs |
| 19 |
# high efficiency can use directly the programs that this program invokes. |
| 20 |
# |
| 21 |
############################################################################## |
| 22 |
|
| 23 |
exec perl -w -x -S -- "$0" "$@" |
| 24 |
|
| 25 |
#!/usr/bin/perl |
| 26 |
############################################################################## |
| 27 |
# This is nothing but a compatibility interface for |
| 28 |
# Pamcrater/Pamshadedrelief. An old program coded to call Pgmcrater will |
| 29 |
# continue working because this interface exists. All new (or newly |
| 30 |
# modified) programs should call Pamcrater and Pamshadedrelief instead. |
| 31 |
# |
| 32 |
# In days past, Pamcrater and Pamshadedrelief did not exist. Pgmcrater did |
| 33 |
# both jobs together, with PGM output. |
| 34 |
############################################################################## |
| 35 |
|
| 36 |
use strict; |
| 37 |
|
| 38 |
use Getopt::Long; |
| 39 |
use IO::Handle; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
sub pm_message($) { |
| 44 |
STDERR->print("pgmcrater: $_[0]\n"); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
sub doVersionHack($) { |
| 51 |
my ($argvR) = @_; |
| 52 |
|
| 53 |
my $arg1 = $argvR->[0]; |
| 54 |
|
| 55 |
if (defined($arg1) && (($arg1 eq "--version") || ($arg1 eq "-version"))) { |
| 56 |
my $termStatus = system('pamcrater', '--version'); |
| 57 |
exit($termStatus == 0 ? 0 : 1); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
############################################################################## |
| 63 |
# |
| 64 |
# MAINLINE |
| 65 |
# |
| 66 |
############################################################################## |
| 67 |
|
| 68 |
doVersionHack(\@ARGV); |
| 69 |
|
| 70 |
my @pgmcraterArgv = @ARGV; |
| 71 |
|
| 72 |
my $validOptions = GetOptions( |
| 73 |
'number=i' => \my $numberOpt, |
| 74 |
'height=i' => \my $heightOpt, |
| 75 |
'ysize=i' => \my $ysizeOpt, |
| 76 |
'width=i' => \my $widthOpt, |
| 77 |
'xsize=i' => \my $xsizeOpt, |
| 78 |
'gamma=i' => \my $gammaOpt, |
| 79 |
'randomseed=i' => \my $randomseedOpt); |
| 80 |
|
| 81 |
if (!$validOptions) { |
| 82 |
pm_message("Invalid syntax"); |
| 83 |
exit(100); |
| 84 |
} |
| 85 |
|
| 86 |
my $pamcraterArgs; |
| 87 |
|
| 88 |
$pamcraterArgs = ''; # initial value |
| 89 |
|
| 90 |
if (defined($numberOpt)) { |
| 91 |
$pamcraterArgs .= "'-number=$numberOpt' "; |
| 92 |
} |
| 93 |
|
| 94 |
if (defined($heightOpt)) { |
| 95 |
$pamcraterArgs .= "'-height=$heightOpt' "; |
| 96 |
} elsif (defined($ysizeOpt)) { |
| 97 |
$pamcraterArgs .= "'-height=$ysizeOpt' "; |
| 98 |
} |
| 99 |
|
| 100 |
if (defined($widthOpt)) { |
| 101 |
$pamcraterArgs .= "'-width=$widthOpt' "; |
| 102 |
} elsif (defined($xsizeOpt)) { |
| 103 |
$pamcraterArgs .= "'-width=$xsizeOpt' "; |
| 104 |
} |
| 105 |
|
| 106 |
if (defined($randomseedOpt)) { |
| 107 |
$pamcraterArgs .= "'-randomseed=$randomseedOpt' "; |
| 108 |
} |
| 109 |
|
| 110 |
my $pamshadedreliefArgs; |
| 111 |
|
| 112 |
$pamshadedreliefArgs = ''; # initial value |
| 113 |
|
| 114 |
if (defined($gammaOpt)) { |
| 115 |
$pamshadedreliefArgs .= "'-gamma=$gammaOpt' "; |
| 116 |
} |
| 117 |
|
| 118 |
my $termStatus = |
| 119 |
system( |
| 120 |
"pamcrater $pamcraterArgs | " . |
| 121 |
"pamshadedrelief $pamshadedreliefArgs |" . |
| 122 |
"pamtopnm"); |
| 123 |
|
| 124 |
exit($termStatus == 0 ? 0 : 1); |