summaryrefslogtreecommitdiff
path: root/lib/sbin/parameter_parser.pl
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-05-16 14:55:05 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2005-05-16 14:55:05 +0000
commitfef61b76eb267beb01fdfa20fc061b5f6e857c1b (patch)
treea00a35fb4ff294b0eef3ecbf39c73d31b5ddc1dd /lib/sbin/parameter_parser.pl
parent4ef5191c6e95a4a879b4e704fc013250d5920e80 (diff)
Don't use keyword parameter ranges as regulare expressions but as ordinary
string values when comparing the default value against them. This closes PR Cactus/1927: "Keyword parameter checking in CST is wrong". git-svn-id: http://svn.cactuscode.org/flesh/trunk@4055 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/parameter_parser.pl')
-rw-r--r--lib/sbin/parameter_parser.pl550
1 files changed, 231 insertions, 319 deletions
diff --git a/lib/sbin/parameter_parser.pl b/lib/sbin/parameter_parser.pl
index 8c938e8f..065becff 100644
--- a/lib/sbin/parameter_parser.pl
+++ b/lib/sbin/parameter_parser.pl
@@ -1,16 +1,16 @@
-#! /usr/bin/perl
+#! /usr/bin/perl -w
#/*@@
# @file parameter_parser.pl
# @date Mon 25 May 08:07:40 1998
# @author Tom Goodale
-# @desc
+# @desc
# Parser for param.ccl files
-# @enddesc
+# @enddesc
# @version $Header$
#@@*/
#%implementations = ("flesh", "flesh", "test1", "test1", "test2", "test2");
-
+
#%parameter_database = create_parameter_database(%implementations);
#&print_parameter_database(%parameter_database);
@@ -19,14 +19,9 @@
# @routine create_parameter_database
# @date Wed Sep 16 11:45:18 1998
# @author Tom Goodale
-# @desc
+# @desc
# Creates a database of all the parameters
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
+# @enddesc
#@@*/
sub create_parameter_database
@@ -35,26 +30,25 @@ sub create_parameter_database
my($thorn, @indata);
my(@new_parameter_data);
my(@parameter_data);
-
- # Loop through each implementation's parameter file.
+
+ # Loop through each implementation's parameter file.
foreach $thorn (sort keys %thorns)
{
print " $thorn\n";
# Read the data
@indata = &read_file("$thorns{$thorn}/param.ccl");
-
- # Get the parameters from it
+
+ # Get the parameters from it
@new_parameter_data = &parse_param_ccl($thorn, @indata);
&PrintParameterStatistics($thorn, @new_parameter_data);
- # Add the parameters to the master parameter database
+ # Add the parameters to the master parameter database
push (@parameter_data, @new_parameter_data);
-
}
-
+
@parameter_data = &cross_index_parameters(scalar(keys %thorns), (sort keys %thorns), @parameter_data);
-
+
return @parameter_data;
}
@@ -67,30 +61,30 @@ sub cross_index_parameters
my($line);
my(@data);
my($thorn);
-
+
@thorns = @indata[0..$n_thorns-1];
%parameter_database = @indata[$n_thorns..$#indata];
-
+
$parameter_database{"GLOBAL PARAMETERS"} = "";
-
+
foreach $thorn (@thorns)
{
foreach $parameter (split(/ /, $parameter_database{"\U$thorn\E GLOBAL variables"}))
{
if($public_parameters{"\U$parameter\E"})
{
- $message = "Duplicate public parameter $parameter, defined in $thorn and ".$public_parameters{"\Uparameter\E"};
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Duplicate public parameter $parameter, defined in " .
+ "$thorn and " . $public_parameters{"\Uparameter\E"},
+ '', __LINE__, __FILE__);
}
else
{
$public_parameters{"\Uparameter\E"} = "$thorn";
-
$parameter_database{"GLOBAL PARAMETERS"} .= "$thorn\::$parameter ";
}
}
}
-
+
return %parameter_database;
}
@@ -100,14 +94,9 @@ sub cross_index_parameters
# @routine parse_param_ccl
# @date Wed Sep 16 11:55:33 1998
# @author Tom Goodale
-# @desc
+# @desc
# Parses a param.ccl file and generates a database of the values.
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
+# @enddesc
#@@*/
sub parse_param_ccl
@@ -120,45 +109,44 @@ sub parse_param_ccl
my(%defined_parameters);
my($use_or_extend, $use_clause, $skip_range_block);
my($message);
-
+
# The default block is private.
- $block = "PRIVATE";
-
+ $block = 'PRIVATE';
+
# Initialise, to prevent perl -w from complaining.
- $parameter_db{"\U$thorn PRIVATE\E variables"} = "";
+ $parameter_db{"\U$thorn PRIVATE\E variables"} = '';
for($line_number = 0; $line_number < @data; $line_number++)
{
$line = $data[$line_number];
-
- # Parse the line
+
+ # Parse the line
if($line =~ m/(GLOBAL|RESTRICTED|PRIVATE|SHARES)\s*:\s*(\S*)\s*(.*)$/i)
{
- # It's a new block.
+ # It's a new block.
$block = "\U$1\E";
-
- if($block eq "SHARES")
+
+ if($block eq 'SHARES')
{
$current_friend = $2;
$current_friend =~ s:\s::;
-
- if ($3 !~ /^\s*$/)
- {
- $mess = "More than one implementation on SHARES line in param.ccl for thorn $thorn";
- &CST_error(0,$mess,"",__LINE__,__FILE__);
- }
-
- # It's a friend block.
+
+ if ($3 !~ /^\s*$/)
+ {
+ &CST_error(0, "More than one implementation on SHARES line in " .
+ "param.ccl for thorn $thorn",
+ '', __LINE__, __FILE__);
+ }
+
+ # It's a friend block.
$block .= " \U$current_friend\E";
- # Remember this friend, but make the memory unique.
+ # Remember this friend, but make the memory unique.
$friends{"\U$current_friend\E"} = 1;
}
-
+
# Do some initialisation to prevent perl -w from complaining.
- if(!$parameter_db{"\U$thorn $block\E variables"})
- {
- $parameter_db{"\U$thorn $block\E variables"} = "";
- }
+ $parameter_db{"\U$thorn $block\E variables"} = ''
+ if(! $parameter_db{"\U$thorn $block\E variables"});
}
elsif($line =~ m:(EXTENDS |USES )?\s*(?\:CCTK_)?(INT|REAL|BOOLEAN|KEYWORD|STRING)\s+([a-zA-Z]+[a-zA-Z0-9_]*)(\s*\[([^]]+)\])?(\s+\"[^\"]*\")?\s*(.*)$:i)
{
@@ -173,75 +161,68 @@ sub parse_param_ccl
$description =~ s:^\s*::;
- if($use_or_extend =~ m:USES:i)
- {
- $use_clause = 1;
- }
- else
- {
- $use_clause = 0;
- }
+ $use_clause = ($use_or_extend =~ m:USES:i) ? 1 : 0;
if($description !~ m:\":)
{
if($use_or_extend)
{
- $description = "";
+ $description = '';
}
else
{
- $message = "Missing description for parameter $variable in param.ccl for thorn $thorn.";
- $hint = "The first line of each parameter definition must have the syntax <TYPE> <NAME> <\"DESCRIPTION\">";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "Missing description for parameter $variable in " .
+ "param.ccl for thorn $thorn.",
+ "The first line of each parameter definition must have " .
+ "the syntax <TYPE> <NAME> <\"DESCRIPTION\">",
+ __LINE__, __FILE__);
}
}
my $realname = $variable;
# First deal with an alias
-
if($options =~ m/\bAS\s+([^\s]+)\s*/i)
{
my $alias = $1;
-
+
if($alias !~ m/[a-zA-Z]+[a-zA-Z0-9_]*/)
{
- $message = "Invalid alias name '$alias' for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Invalid alias name '$alias' for $variable of thorn " .
+ $thorn, '',__LINE__, __FILE__);
}
elsif($defined_parameters{"\U$alias\E"})
{
- $message = "Invalid alias name '$alias' for $variable of thorn $thorn - parameter of that name already exists";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Invalid alias name '$alias' for $variable of thorn " .
+ "$thorn - parameter of that name already exists",
+ '', __LINE__, __FILE__);
}
-
+
$options =~ s/\bAS\s+([^\s])+\s*//i;
# Rename the variable for internal use
$variable = $alias
}
-
-
+
if($defined_parameters{"\U$variable\E"})
{
-
- $message = "Duplicate parameter $variable in thorn $thorn. Ignoring second definition";
- &CST_error(1,$message,"",__LINE__,__FILE__);
+ &CST_error(1, "Duplicate parameter $variable in thorn $thorn. " .
+ "Ignoring second definition", '', __LINE__, __FILE__);
$line_number++ until ($line_number>@data || $data[$line_number] =~ m:\}:);
}
elsif($use_or_extend && $use_or_extend =~ m:(EXTENDS|USES):i && $block !~ m:SHARES\s*\S:)
{
# Can only extend a friend variable.
- $message = "Parse error in $thorn/param.ccl";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Parse error in $thorn/param.ccl", '', __LINE__,__FILE__);
$line_number++ until ($data[$line_number] =~ m:\}:);
}
elsif($data[$line_number+1] !~ m:^\s*\{\s*$: && $use_clause == 0)
{
# Since the data should have no blank lines, the next
# line should have { on it.
- $message = "Parse error in $thorn/param.ccl - missing \"{\" in definition of parameter \"$variable\"";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Parse error in $thorn/param.ccl - missing \"{\" in " .
+ "definition of parameter '$variable'",
+ '', __LINE__, __FILE__);
# Move past the end of this block.
$line_number++ until ($data[$line_number] =~ m:\}:);
}
@@ -251,16 +232,16 @@ sub parse_param_ccl
# Move past {
if($data[$line_number+1] !~ m:\s*\{\s*:)
{
- if ($use_clause)
+ if ($use_clause)
{
$skip_range_block = 1;
}
else
{
# This message is already given above.
-# message = "Missing { at start of range block for parameter $variable pf thorn $thorn";
-# &CST_error(0,$message,"",__LINE__,__FILE__);
- die "Internal error in parser: this line should never be reached."
+# &CST_error(0, "Missing { at start of range block for parameter " .
+# "$variable pf thorn $thorn", '', __LINE__, __FILE__);
+ die 'Internal error in parser: this line should never be reached.';
}
}
else
@@ -269,11 +250,10 @@ sub parse_param_ccl
$line_number++;
$line_number++;
}
-
- # Parse the options
+ # Parse the options
%options = split(/\s*=\s*|\s+/, $options);
-
+
foreach $option (sort keys %options)
{
if($option =~ m:STEERABLE:i)
@@ -290,9 +270,11 @@ sub parse_param_ccl
}
else
{
- $message = "Unknown parameter '$options{$option}' specified as accumulator-base of $variable of thorn $thorn\n" .
- " HINT: if it comes from another thorn it must be shared";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Unknown parameter '$options{$option}' " .
+ "specified as accumulator-base of $variable of " .
+ "thorn $thorn",
+ 'if it comes from another thorn it must be shared',
+ __LINE__, __FILE__);
}
}
elsif($options{$option} =~ m/[a-zA-Z]+[a-zA-Z0-9_]*/)
@@ -301,9 +283,10 @@ sub parse_param_ccl
}
else
{
- $message = "Invalid accumulator-base $options{$option} for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
- }
+ &CST_error(0, "Invalid accumulator-base $options{$option} for " .
+ "$variable of thorn $thorn",
+ '', __LINE__, __FILE__);
+ }
}
elsif($option =~ m:ACCUMULATOR:i)
{
@@ -315,45 +298,52 @@ sub parse_param_ccl
}
elsif($retcode == 1)
{
- $message = "Invalid accumulator expression '$options{$option}' for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Invalid accumulator expression " .
+ "'$options{$option}' for $variable of thorn $thorn",
+ '', __LINE__, __FILE__);
}
elsif($retcode == 2)
{
- $message = "Arithmetic error in accumulator expression '$options{$option}' for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Arithmetic error in accumulator expression " .
+ "'$options{$option}' for $variable of thorn $thorn",
+ '', __LINE__, __FILE__);
}
elsif($retcode == 3)
{
- $message = "Accumulator expression '$options{$option}' can be infinite for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Accumulator expression '$options{$option}' " .
+ "can be infinite for $variable of thorn $thorn",
+ '', __LINE__, __FILE__);
}
elsif($retcode == 4)
{
- $message = "Accumulator expression '$options{$option}' does not commute for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Accumulator expression '$options{$option}' " .
+ "does not commute for $variable of thorn $thorn",
+ '', __LINE__, __FILE__);
}
else
{
- $message = "Internal-error while checking accumulator expression '$options{$option}' for $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Internal-error while checking accumulator " .
+ "expression '$options{$option}' for $variable " .
+ "of thorn $thorn",
+ '', __LINE__, __FILE__);
}
}
else
{
- $message = "Unknown option '$option' for parameter $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Unknown option '$option' for parameter $variable " .
+ "of thorn $thorn",
+ '', __LINE__, __FILE__);
}
}
-
- # Check array size
+ # Check array size
if($array_size)
{
if($array_size !~ /^\d+$/)
{
- $message = "Invalid array size '$array_size' for parameter $variable of thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Invalid array size '$array_size' for parameter " .
+ "$variable of thorn $thorn",
+ '', __LINE__, __FILE__);
}
else
{
@@ -362,14 +352,13 @@ sub parse_param_ccl
}
# Store data about this variable.
-
$defined_parameters{"\U$variable\E"} = 1;
$parameter_db{"\U$thorn $variable\E realname"} = $realname;
$parameter_db{"\U$thorn $block\E variables"} .= $variable." ";
$parameter_db{"\U$thorn $variable\E type"} = $type;
$parameter_db{"\U$thorn $variable\E description"} = $description;
$parameter_db{"\U$thorn $variable\E ranges"} = 0;
-
+
if(! $skip_range_block)
{
# Parse the allowed values and their descriptions.
@@ -383,29 +372,34 @@ sub parse_param_ccl
else
{
($new_ranges, $delim, $new_desc) = ($data[$line_number],"","");
- }
+ }
# Increment the number of ranges found (ranges)
$parameter_db{"\U$thorn $variable\E ranges"}++;
- # Strip out any spaces in the range for a numeric parameter.
- if($type =~ m:INT|REAL:)
- {
- $new_ranges =~ s/\s//g;
- }
-
+
+ # Strip out any leading and trailing spaces in the range
+ $new_ranges =~ s/^\s*//;
+ $new_ranges =~ s/\s*$//;
+ # Strip out double quotes enclosing a non-numeric parameter range
+ $new_ranges =~ s/^"(.*)"$/$1/ if ($type !~ m:INT|REAL:);
+
$parameter_db{"\U$thorn $variable\E range $parameter_db{\"\U$thorn $variable\E ranges\"} range"} = $new_ranges;
-
+
# Check description
if($delim eq "" || ($delim =~ /::/ && $new_desc =~ /^\s*$/))
{
- $new_ranges =~ /^\s*(.*)\s*\n/;
- $message = "Missing description for range $1 for parameter $variable in param.ccl for thorn $thorn.";
- $hint = "Each parameter range line should have the syntax <RANGE> :: <\"DESCRIPTION\">";
- &CST_error(1,$message,$hint,__LINE__,__FILE__);
+ $new_ranges =~ /^\s*(.*)\s*\n/;
+ &CST_error(1, "Missing description for range $1 for parameter " .
+ "$variable in param.ccl for thorn $thorn.",
+ "Each parameter range line should have the syntax " .
+ "<RANGE> :: <\"DESCRIPTION\">",
+ __LINE__, __FILE__);
}
elsif ($new_desc =~ /^\s*\".*[^\s\"]\s*$|^\s*[^\s\"].*\"\s*$/)
{
- $message = "Description of range for parameter $variable has misplaced quotes ($new_desc) in param.ccl for thorn $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ &CST_error(0, "Description of range for parameter $variable " .
+ "has misplaced quotes ($new_desc) in param.ccl " .
+ "for thorn $thorn",
+ '', __LINE__, __FILE__);
}
$parameter_db{"\U$thorn $variable\E range $parameter_db{\"\U$thorn $variable\E ranges\"} description"} = $new_desc;
$line_number++;
@@ -415,54 +409,63 @@ sub parse_param_ccl
# Give a warning if no range was given and it was needed
if (($use_clause == 0) && ($parameter_db{"\U$thorn $variable\E ranges"}==0 && $type =~ m:INT|REAL:))
{
- $message = "No range provided for parameter $variable in param.ccl for thorn $thorn";
- $hint = "All definitions for integer and real parameters must provide one or more allowed ranges";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "No range provided for parameter $variable in " .
+ "param.ccl for thorn $thorn",
+ "All definitions for integer and real parameters must " .
+ "provide one or more allowed ranges",
+ __LINE__, __FILE__);
}
if($block !~ m:SHARES:)
{
if($data[$line_number] =~ m:\s*\}\s*([^\s].*)\s*:)
{
- $default = $1;
- $default =~ m:^(.*[^\s])\s*:;
- $default = $1;
-
- if ($type =~ m:INT|REAL: && $default =~ m:":)
- {
- $message = "String default given for $type $variable in $thorn";
- &CST_error(0,$message,"",__LINE__,__FILE__);
- }
- elsif ($type =~ m:STRING|KEYWORD: && $default !~ m:".*":)
- {
- $message = "Default given for $type $variable in $thorn is not a string";
- &CST_error(0,$message,"",__LINE__,__FILE__);
- }
- elsif ($type =~ m:BOOLEAN: && $default =~ m:": && $default !~ m:".*":)
- {
- $message = "Default given for $type $variable in $thorn is missing a quote";
- &CST_error(0,$message,"",__LINE__,__FILE__);
- }
-
- $default = $1 if ($default =~ m:\"(((\\\")|[^\"])*)\":);
-
- &CheckParameterDefault($thorn,$variable,$default,%parameter_db);
+ $default = $1;
+ $default =~ m:^(.*[^\s])\s*:;
+ $default = $1;
+
+ if ($type =~ m:INT|REAL: && $default =~ m:":)
+ {
+ &CST_error(0, "String default given for $type $variable in " .
+ "$thorn",
+ '', __LINE__, __FILE__);
+ }
+ elsif ($type =~ m:STRING|KEYWORD: && $default !~ m:".*":)
+ {
+ &CST_error(0, "Default given for $type $variable in $thorn " .
+ "is not a string",
+ '', __LINE__, __FILE__);
+ }
+ elsif ($type =~ m:BOOLEAN: && $default =~ m:": && $default !~ m:".*":)
+ {
+ &CST_error(0, "Default given for $type $variable in $thorn " .
+ "is missing a quote",
+ '', __LINE__, __FILE__);
+ }
+
+ $default = $1 if ($default =~ m:\"(((\\\")|[^\"])*)\":);
- $parameter_db{"\U$thorn $variable\E default"} = $default;
+ &CheckParameterDefault($thorn,$variable,$default,%parameter_db);
+
+ $parameter_db{"\U$thorn $variable\E default"} = $default;
}
else
{
- $message = "Unable to find default value for parameter $variable";
- $hint = "Last line of parameter block should be } <default value>";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
- }
+ &CST_error(0, "Unable to find default value for parameter " .
+ "$variable",
+ "Last line of parameter block should be " .
+ "} <default value>",
+ __LINE__, __FILE__);
+ }
}
if($block =~ m:SHARES:i)
{
if($data[$line_number] =~ m:\s*\}\s*([^\s].*)\s*:)
{
- $message = "param.ccl of thorn '$thorn' attempts to change default value of shared or extended parameter '$variable'";
- &CST_error(0,$message,"",__LINE__,__FILE__);
- }
+ &CST_error(0, "param.ccl of thorn '$thorn' attempts to change " .
+ "default value of shared or extended parameter " .
+ "'$variable'",
+ '', __LINE__, __FILE__);
+ }
}
}
}
@@ -470,19 +473,19 @@ sub parse_param_ccl
{
if($line =~ m:\{:)
{
- $message = "Skipping parameter block in $thorn with missing keyword";
- &CST_error(1,$message,"",__LINE__,__FILE__);
+ &CST_error(1, "Skipping parameter block in $thorn with missing keyword",
+ '', __LINE__, __FILE__);
$line_number++ until ($data[$line_number] =~ m:\}:);
}
else
{
- $line =~ /^(.*)\n*$/;
- $message = "Unknown line in param.ccl for thorn $thorn\n\"$1\"";
- &CST_error(0,$message,"",__LINE__,__FILE__);
+ $line =~ /^(.*)\n*$/;
+ &CST_error(0, "Unknown line in param.ccl for thorn $thorn\n\"$1\"",
+ '', __LINE__, __FILE__);
}
}
}
-
+
$parameter_db{"\U$thorn\E SHARES implementations"} = join(" ", sort keys %friends);
return %parameter_db;
@@ -492,20 +495,15 @@ sub parse_param_ccl
# @routine print_parameter_database
# @date Wed Sep 16 14:58:52 1998
# @author Tom Goodale
-# @desc
+# @desc
# Prints out a parameter database.
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
+# @enddesc
#@@*/
sub print_parameter_database
{
my(%parameter_database) = @_;
my($field);
-
+
foreach $field ( sort keys %parameter_database )
{
print "$field has value $parameter_database{$field}\n";
@@ -517,22 +515,16 @@ sub print_parameter_database
# @routine PrintParameterStatistics
# @date Sun Sep 19 13:04:18 1999
# @author Tom Goodale
-# @desc
+# @desc
# Prints out some statistics about a thorn's param.ccl
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
-#
+# @enddesc
#@@*/
sub PrintParameterStatistics
{
my($thorn, %parameter_database) = @_;
my($block);
my($sep);
-
+
if($parameter_database{"\U$thorn SHARES implementations"} ne "")
{
print " Shares: " . $parameter_database{"\U$thorn SHARES implementations"} . "\n";
@@ -546,8 +538,6 @@ sub PrintParameterStatistics
}
print " parameters\n";
-
- return;
}
@@ -555,184 +545,118 @@ sub PrintParameterStatistics
# @routine CheckParameterDefault
# @date Sun Dec 17 18.20
# @author Gabrielle Allen
-# @desc
+# @desc
# Check default in allowed range
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
-#
+# @enddesc
#@@*/
sub CheckParameterDefault
{
my($thorn,$variable,$default,%parameter_db) = @_;
- my($foundit,$message,$i,$range,$minok,$maxok);
+ my($foundit,$i,$range);
+
+ $foundit = 0;
# Check that boolean default is correct
if ($parameter_db{"\U$thorn $variable\E type"} =~ /BOOLEAN/)
{
if ($default !~ m:^yes|no|y|n|1|0|t|f|true|false$:i)
- {
- $message = "Default ($default) for boolean parameter \"$variable\" is incorrect in param.ccl for thorn $thorn";
- $hint = "The default value for a boolean parameter must be one of yes,no,y,n,1,0,t,f,true,false";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
- }
+ {
+ &CST_error(0, "Default ($default) for boolean parameter '$variable' " .
+ "is incorrect in param.ccl for thorn $thorn",
+ "The default value for a boolean parameter must be one of " .
+ "yes,no,y,n,1,0,t,f,true,false",
+ __LINE__, __FILE__);
+ }
}
-
- # Check that keyword default is correct
- if ($parameter_db{"\U$thorn $variable\E type"} =~ /KEYWORD/)
+ elsif ($parameter_db{"\U$thorn $variable\E type"} =~ /KEYWORD/)
{
- $foundit = 0;
$nranges=$parameter_db{"\U$thorn $variable\E ranges"};
for ($i=1; $i<=$nranges; $i++)
{
+ # Keywords don't use pattern matching but are case insensitive
$range = $parameter_db{"\U$thorn $variable\E range $i range"};
- $range =~ s/^\s*//;
- $range =~ s/\s*$//;
- $range =~ s/^"(.*)"$/$1/;
- # Key words don't use pattern matching
- $range = quotemeta $range;
- if ($default =~ m:$range:i)
- {
- $foundit = 1;
- }
+ $foundit = 1 if ("\U$default\E" eq "\U$range\E");
}
if ($foundit == 0)
{
- $message = "Default ($default) for keyword parameter \"$variable\" is incorrect in param.ccl for thorn $thorn";
- $hint = "The default value for a parameter must lie within the allowed range";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "Default ($default) for keyword parameter '$variable' " .
+ "is incorrect in param.ccl for thorn $thorn",
+ "The default value for a parameter must lie within the " .
+ "allowed range",
+ __LINE__, __FILE__);
}
}
-
- # Check that string default is correct
- if ($parameter_db{"\U$thorn $variable\E type"} =~ /STRING/)
+ elsif ($parameter_db{"\U$thorn $variable\E type"} =~ /STRING/)
{
- $foundit = 0;
$nranges=$parameter_db{"\U$thorn $variable\E ranges"};
for ($i=1; $i<=$nranges; $i++)
{
$range = $parameter_db{"\U$thorn $variable\E range $i range"};
- $range =~ s/^\s*//;
- $range =~ s/\s*$//;
- $range =~ s/^"(.*)"$/$1/;
# An empty regular expression should match everything.
# Instead, perl returns the result of the last match.
# Therefore, prevent using empty patterns.
- if ($range eq '' || $default =~ m:$range:i)
- {
- $foundit = 1;
- }
+ $foundit = 1 if ($range eq '' || $default =~ m:$range:i);
}
if ($foundit == 0)
{
- $message = "Default ($default) for string parameter \"$variable\" is incorrect in param.ccl for thorn $thorn";
- $hint = "The default value for a parameter must lie within an allowed range";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "Default ($default) for string parameter '$variable' " .
+ "is incorrect in param.ccl for thorn $thorn",
+ "The default value for a parameter must lie within an " .
+ "allowed range",
+ __LINE__, __FILE__);
}
}
-
- # Check that integer default is correct
- if ($parameter_db{"\U$thorn $variable\E type"} =~ /INT/)
+ elsif ($parameter_db{"\U$thorn $variable\E type"} =~ /INT/)
{
$nranges=$parameter_db{"\U$thorn $variable\E ranges"};
for ($i=1; $i<=$nranges; $i++)
{
-
- $minok=0;
- $maxok=0;
$range = $parameter_db{"\U$thorn $variable\E range $i range"};
- $range =~ s/^\s*//;
- $range =~ s/\s*$//;
- $range =~ s/^"(.*)"$/$1/;
$range =~ /^([\s\*0-9]*):([\s\*0-9]*)/;
$min = $1;
$max = $2;
- if ($min =~ /^\s*[\*\s]*\s*$/)
- {
- $minok=1;
- }
- elsif ($default >= $min)
- {
- $minok=1;
- }
- if ($max =~ /^\s*[\*\s]*\s*$/)
- {
- $maxok=1;
- }
- elsif ($default <= $max)
- {
- $maxok=1;
- }
- if ($minok == 1 && $maxok == 1)
- {
- $foundit = 1;
- }
+ $foundit = 1 if ($min =~ /^\s*[\*\s]*\s*$/ && $default >= $min &&
+ $max =~ /^\s*[\*\s]*\s*$/ && $default <= $max);
}
if ($nranges > 0 && $foundit == 0)
{
- $message = "Default ($default) for integer parameter \"$variable\" is incorrect in param.ccl for thorn $thorn";
- $hint = "The default value for a parameter must lie within the allowed range";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "Default ($default) for integer parameter '$variable' " .
+ "is incorrect in param.ccl for thorn $thorn",
+ "The default value for a parameter must lie within the " .
+ "allowed range",
+ __LINE__, __FILE__);
}
}
-
- # Check that real default is correct
- if ($parameter_db{"\U$thorn $variable\E type"} =~ /REAL/)
+ elsif ($parameter_db{"\U$thorn $variable\E type"} =~ /REAL/)
{
$nranges=$parameter_db{"\U$thorn $variable\E ranges"};
for ($i=1; $i<=$nranges; $i++)
{
- $minok=0;
- $maxok=0;
$range = $parameter_db{"\U$thorn $variable\E range $i range"};
- $range =~ s/^\s*//;
- $range =~ s/\s*$//;
- $range =~ s/^"(.*)"$/$1/;
$range =~ /^([\s\*0-9\.eE+-]*):([\s\*0-9\.eE+-]*)/;
$min = $1;
$max = $2;
- if ($min =~ /^\s*[\*\s]*\s*$/)
- {
- $minok=1;
- }
- elsif ($default >= $min)
- {
- $minok=1;
- }
- if ($max =~ /^\s*[\*\s]*\s*$/)
- {
- $maxok=1;
- }
- elsif ($default <= $max)
- {
- $maxok=1;
- }
- if ($minok == 1 && $maxok == 1)
- {
- $foundit = 1;
- }
+ $foundit = 1 if ($min =~ /^\s*[\*\s]*\s*$/ && $default >= $min &&
+ $max =~ /^\s*[\*\s]*\s*$/ && $default <= $max);
}
if ($nranges > 0 && $foundit == 0)
{
- $message = "Default ($default) for real parameter \"$variable\" is incorrect in param.ccl for thorn $thorn";
- $hint = "The default value for a parameter must lie within the allowed range";
- &CST_error(0,$message,$hint,__LINE__,__FILE__);
+ &CST_error(0, "Default ($default) for real parameter '$variable' " .
+ "is incorrect in param.ccl for thorn $thorn",
+ "The default value for a parameter must lie within the " .
+ "allowed range",
+ __LINE__, __FILE__);
}
}
-
- return;
}
#/*@@
# @routine CheckExpression
# @date Fri May 17 21:26:52 2002
# @author Tom Goodale
-# @desc
+# @desc
# Checks that an accumulator parameter's expression is valid.
# The expression should commute when applied twice
# I.e. if a is the original value of the parameter,
@@ -742,12 +666,7 @@ sub CheckParameterDefault
# The expression
# L(L(a,b),c) = L(L(a,c),b)
# should be true.
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
+# @enddesc
#
# @var expression
# @vdesc The expression to verify
@@ -782,7 +701,7 @@ sub CheckExpression
my $a = 37;
my $b = 53;
my $c = 59;
-
+
# Convert to Perl's exponentiation operator syntax.
$expression =~ s/\^/**/;
@@ -792,14 +711,14 @@ sub CheckExpression
# Calculate L(L(a,b),c).
my $answer1 = &EvalExpression(&EvalExpression($a,$b,"$expression"),$c,$expression);
-
+
# print "$answer1\n" if defined $answer1;
-
+
# Calculate L(L(a,c),b).
my $answer2 = &EvalExpression(&EvalExpression($a,$c,"$expression"),$b,$expression);
-
+
# print "$answer2\n" if defined $answer2;
-
+
if( !defined $answer1 || ! defined $answer2)
{
$retval = 2;
@@ -821,7 +740,7 @@ sub CheckExpression
{
$retval = 1;
}
-
+
return $retval;
}
@@ -830,15 +749,10 @@ sub CheckExpression
# @routine EvalExpression
# @date Fri May 17 21:34:18 2002
# @author Tom Goodale
-# @desc
+# @desc
# Takes an expression involving $x and $y
# and evaluates it.
-# @enddesc
-# @calls
-# @calledby
-# @history
-#
-# @endhistory
+# @enddesc
#
# @var x
# @vdesc An argument in the expression
@@ -872,5 +786,3 @@ sub EvalExpression
1;
-
-