Commit c52986a6 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

fiji_scripts: unify the setting of default values of FIJI Settings

parent 0d9e6233
...@@ -79,7 +79,49 @@ sub read_configfile { ...@@ -79,7 +79,49 @@ sub read_configfile {
} }
sub _bla { ## @function _set_defaults (%$map_ref, %$consts_ref)
# @brief Set defaults according to FIJI.pm.
#
# The functions compares the given constants to the defaults and rules
# in FIJI.pm.
sub _set_defaults {
my $logger = get_logger();
my ($map_ref, $consts_ref) = @_;
my $new_hash = {};
# Iterating over respective hash from FIJI.pm and set defaults if need be
foreach my $k (keys($map_ref)) {
my $ini_name = $map_ref->{$k}->{'ini_name'};
if (exists($consts_ref->{$ini_name})) {
$new_hash->{$k} = $consts_ref->{$ini_name};
$logger->trace(sprintf("Copying setting %s (%s) = %s.", $k, $ini_name, $consts_ref->{$ini_name}));
} else {
if (exists($map_ref->{$k}->{default})) {
$new_hash->{$k} = $map_ref->{$k}->{default};
$logger->trace(sprintf("Adding default constant: %s (%s) = %s.", $k, $ini_name, $map_ref->{$k}->{default}));
# If the default key is there but its value is undef then
# the value will be set somewhere else later (used for FIU_NUM)
if (!defined($new_hash->{$k})) {
next;
}
} else {
$logger->error(sprintf("%s is missing from FIJI Settings.", $ini_name));
return undef;
}
}
my $orig = $new_hash->{$k};
# convert non-decimal (hexadecimal, binary, octal) values to decimal
if ($map_ref->{$k}->{'is_numeric'}) {
$new_hash->{$k} = oct($orig) if $orig =~ /^0/;
$logger->trace("Converted value of $k (\"$orig\") to \"$new_hash->{$k}\".") if ($orig ne $new_hash->{$k});
if (!looks_like_number($new_hash->{$k})) {
$logger->error("$orig does not look like a number.");
return undef;
}
}
}
return $new_hash;
} }
## @function _sanitize_fiu (%$fiu_ref) ## @function _sanitize_fiu (%$fiu_ref)
...@@ -98,32 +140,10 @@ sub _sanitize_fiu { ...@@ -98,32 +140,10 @@ sub _sanitize_fiu {
return undef; return undef;
} }
my $new_hash = {}; my $new_consts = _set_defaults(FIUMAP, $fiu_ref);
# Iterate over FIUMAP hash from FIJI.pm and set defaults if need be if (!defined($new_consts)) {
# FIXME: part of the loop almost identical to _sanitize_consts below $logger->fatal("Could not set defaults for design constants.");
foreach my $k (keys(FIUMAP)) { return undef;
my $ini_name = FIUMAP->{$k}->{'ini_name'};
if (exists($fiu_ref->{$ini_name})) {
$new_hash->{$k} = $fiu_ref->{$ini_name};
$logger->trace(sprintf("Copying setting %s (%s) = %s.", $k, $ini_name, $fiu_ref->{$ini_name}));
} else {
if (exists(FIUMAP->{$k}->{default})) {
$new_hash->{$k} = FIUMAP->{$k}->{default};
$logger->trace(sprintf("Adding default constant: %s (%s) = %s.", $k, $ini_name, FIUMAP->{$k}->{default}));
} else {
$logger->error(sprintf("%s is missing from FIJI constants.", $ini_name));
return undef;
}
}
# convert non-decimal (hexadecimal, binary, octal) values to decimal
# my $orig = $new_hash->{$k};
# $new_hash->{$k} = oct($orig) if $orig =~ /^0/;
# $logger->trace("Converted value of $k (\"$orig\") to \"$new_hash->{$k}\".") if ($orig ne $new_hash->{$k});
# if (!looks_like_number($new_hash->{$k})) {
# $logger->error("$orig does not look like a number.");
# return undef;
# }
} }
# check for sane values # check for sane values
...@@ -192,38 +212,10 @@ sub _sanitize_consts { ...@@ -192,38 +212,10 @@ sub _sanitize_consts {
} }
} }
my $new_consts = {}; my $new_consts = _set_defaults(DESIGNMAP, $consts_ref);
# Iterating over DESIGNMAP hash from FIJI.pm and set defaults if need be if (!defined($new_consts)) {
foreach my $k (keys(DESIGNMAP)) { $logger->fatal("Could not set defaults for design constants.");
my $ini_name = DESIGNMAP->{$k}->{'ini_name'}; return undef;
if (exists($consts_ref->{$ini_name})) {
$new_consts->{$k} = $consts_ref->{$ini_name};
$logger->trace(sprintf("Copying setting %s (%s) = %s.", $k, $ini_name, $consts_ref->{$ini_name}));
} else {
if (exists(DESIGNMAP->{$k}->{default})) {
$new_consts->{$k} = DESIGNMAP->{$k}->{default};
$logger->trace(sprintf("Adding default constant: %s (%s) = %s.", $k, $ini_name, DESIGNMAP->{$k}->{default}));
# If the default key is there but its value is undef then
# the value will be set somewhere else later (used for FIU_NUM)
if (!defined($new_consts->{$k})) {
next;
}
} else {
$logger->error(sprintf("%s is missing from FIJI constants.", $ini_name));
return undef;
}
}
my $orig = $new_consts->{$k};
# convert non-decimal (hexadecimal, binary, octal) values to decimal
if (DESIGNMAP->{$k}->{is_numeric}) {
$new_consts->{$k} = oct($orig) if $orig =~ /^0/;
$logger->trace("Converted value of $k (\"$orig\") to \"$new_consts->{$k}\".") if ($orig ne $new_consts->{$k});
if (!looks_like_number($new_consts->{$k})) {
$logger->error("$orig does not look like a number.");
return undef;
}
}
} }
# check for sane values # check for sane values
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment