3 # ************************************************************
4 # Description : Reads a generic config file and store the values
5 # Author : Chad Elliott
6 # Create Date : 6/12/2006
7 # ************************************************************
9 # ************************************************************
11 # ************************************************************
20 # ************************************************************
22 # ************************************************************
25 my($class, $valid) = @_;
26 my $self = $class->SUPER::new
();
28 ## Set up the internal data members
29 $self->{'values'} = {};
30 $self->{'clean'} = {};
31 $self->{'valid'} = $valid;
32 $self->{'warned'} = {};
39 my($self, $if, $line) = @_;
44 elsif ($line =~ /^([^=]+)\s*=\s*(.*)$/) {
45 ## Save the name, removing any trailing white space, and the value
50 ## Pre-process the name and value
51 my $value = $self->preprocess($clean);
52 $name = $self->preprocess($name);
55 ## Store the name value pair
56 if (!defined $self->{'valid'}) {
57 ## There are no valid names, so all names are valid, except an
60 $self->{'values'}->{$name} = $value;
61 $self->{'clean'}->{$name} = $clean;
64 elsif (defined $self->{'valid'}->{lc($name)}) {
65 ## This is a valid value, so we can store it.
66 $self->{'values'}->{lc($name)} = $value;
67 $self->{'clean'}->{lc($name)} = $clean;
70 $error = "Invalid keyword: $name";
74 $error = "Unrecognized line: $line";
77 return (defined $error ?
0 : 1), $error;
82 my @names = keys %{$_[0]->{'values'}};
88 ## Try the tag first and if that doesn't work make it all lower-case.
90 return $self->{'values'}->{$tag} || $self->{'values'}->{lc($tag)};
95 ## Try the tag first and if that doesn't work make it all lower-case.
97 return $self->{'clean'}->{$tag} || $self->{'clean'}->{lc($tag)};
102 my($self, $str) = @_;
104 ## We need to replace $(...) with the equivalent environment variable
106 while ($str =~ /\$(\?)?([\(\w\)]+)/) {
109 $name =~ s/[\(\)]//g;
110 my $val = $ENV{$name};
113 if (defined $optional) {
117 ## If the environment variable is not set, we will end up removing
118 ## the reference, but we need to warn the user that we're doing so.
120 if (!defined $self->{'warned'}->{$name}) {
121 $self->diagnostic("$name was used in the configuration file, " .
122 "but was not defined.");
123 $self->{'warned'}->{$name} = 1;
127 ## Do the replacement
128 $str =~ s/\$\??([\(\w\)]+)/$val/;
131 ## Remove leading and trailing spaces