summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-12-17 22:50:34 +0000
committerallen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac>2000-12-17 22:50:34 +0000
commita6fce3ff2df49cb81da5b1feb07645b1b2988262 (patch)
tree049656d90224263c104919a7b3f128c28bf19774 /lib
parenta7f51a146b130797919370a7a30eac7a5c848fd7 (diff)
Check default parameter value lies in allowed ranges during CST
Cactus/323 git-svn-id: http://svn.cactuscode.org/flesh/trunk@1971 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rw-r--r--lib/sbin/parameter_parser.pl174
1 files changed, 173 insertions, 1 deletions
diff --git a/lib/sbin/parameter_parser.pl b/lib/sbin/parameter_parser.pl
index 9bb9e9b7..e9bb8040 100644
--- a/lib/sbin/parameter_parser.pl
+++ b/lib/sbin/parameter_parser.pl
@@ -272,6 +272,7 @@ sub parse_param_ccl
{
$new_ranges =~ s/[ \t]+/ /g;
}
+
$parameter_db{"\U$thorn $variable\E range $parameter_db{\"\U$thorn $variable\E ranges\"} range"} = $new_ranges;
# Check description
@@ -280,7 +281,7 @@ sub parse_param_ccl
$message = "Missing description of range '$new_ranges' for parameter $thorn\::$variable";
&CST_error(1,$message,__LINE__,__FILE__);
}
- elsif ($new_desc !~ /^\s*\".*\"\s*$/)
+ elsif ($new_desc =~ /^\s*\".*[^\s\"]\s*$|^\s*[^\s\"].*\"\s*$/)
{
$message = "Description of range for $thorn\::$variable has misplaced quotes ($new_desc)";
&CST_error(0,$message,__LINE__,__FILE__);
@@ -318,6 +319,8 @@ sub parse_param_ccl
}
$default = $1 if ($default =~ m:\"(((\\\")|[^\"])*)\":);
+
+ &CheckParameterDefault($thorn,$variable,$default,%parameter_db);
$parameter_db{"\U$thorn $variable\E default"} = $default;
}
@@ -407,6 +410,175 @@ sub PrintParameterStatistics
return;
}
+
+#/*@@
+# @routine CheckParameterDefault
+# @date Sun Dec 17 18.20
+# @author Gabrielle Allen
+# @desc
+# Check default in allowed range
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+
+sub CheckParameterDefault
+{
+ my($thorn,$variable,$default,%parameter_db) = @_;
+ my($foundit,$message,$i,$range,$minok,$maxok);
+
+ # Check that boolean default is correct
+ if ($parameter_db{"\U$thorn $variable\E type"} =~ /BOOLEAN/)
+ {
+ if ($default !~ m:^yes|no|1|0$:i)
+ {
+ $message = "Default ($default) for boolean incorrect for $variable in $thorn";
+ &CST_error(0,$message,__LINE__,__FILE__);
+ }
+ }
+
+ # Check that keyword default is correct
+ if ($parameter_db{"\U$thorn $variable\E type"} =~ /KEYWORD/)
+ {
+ $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/;
+ # Key words don't use pattern matching
+ $range = quotemeta $range;
+ if ($default =~ m:$range:i)
+ {
+ $foundit = 1;
+ }
+ }
+ if ($foundit == 0)
+ {
+ $message = "Default ($default) for keyword incorrect for $variable in $thorn";
+ &CST_error(0,$message,__LINE__,__FILE__);
+ }
+ }
+
+ # Check that string default is correct
+ if ($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/;
+
+ if ($default =~ m:$range:i)
+ {
+ $foundit = 1;
+ }
+ }
+ if ($foundit == 0)
+ {
+ $message = "Default ($default) for string incorrect for $variable in $thorn";
+ &CST_error(0,$message,__LINE__,__FILE__);
+ }
+ }
+
+ # Check that integer default is correct
+ if ($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;
+ }
+ }
+ if ($foundit == 0)
+ {
+ $message = "Default ($default) for integer incorrect for $variable in $thorn";
+ &CST_error(0,$message,__LINE__,__FILE__);
+ }
+ }
+
+ # Check that real default is correct
+ if ($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\.]*):([\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;
+ }
+ }
+ if ($foundit == 0)
+ {
+ $message = "Default ($default) for real incorrect for $variable in $thorn";
+ &CST_error(0,$message,__LINE__,__FILE__);
+ }
+ }
+
+ return;
+}
+
1;