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
51 ## Pre-process the name and value
52 my $value = $self->preprocess($clean);
53 $name = $self->preprocess($name);
56 ## Store the name value pair
57 if (!defined $self->{'valid'}) {
58 ## There are no valid names, so all names are valid, except an
61 $self->{'values'}->{$name} = $value;
62 $self->{'clean'}->{$name} = $clean;
65 elsif (defined $self->{'valid'}->{lc($name)}) {
66 ## This is a valid value, so we can store it.
67 $self->{'values'}->{lc($name)} = $value;
68 $self->{'clean'}->{lc($name)} = $clean;
71 $error = "Invalid keyword: $name";
75 $error = "Unrecognized line: $line";
78 return (defined $error ?
0 : 1), $error;
83 my @names = keys %{$_[0]->{'values'}};
89 ## Try the tag first and if that doesn't work make it all lower-case.
91 return $self->{'values'}->{$tag} || $self->{'values'}->{lc($tag)};
96 ## Try the tag first and if that doesn't work make it all lower-case.
98 return $self->{'clean'}->{$tag} || $self->{'clean'}->{lc($tag)};
103 my($self, $str) = @_;
105 ## We need to replace $(...) with the equivalent environment variable
107 while ($str =~ /\$(\?)?([\(\w\)]+)/) {
110 $name =~ s/[\(\)]//g;
111 my $val = $ENV{$name};
114 if (defined $optional) {
118 ## If the environment variable is not set, we will end up removing
119 ## the reference, but we need to warn the user that we're doing so.
121 if (!defined $self->{'warned'}->{$name}) {
122 $self->diagnostic("$name was used in the configuration file, " .
123 "but was not defined.");
124 $self->{'warned'}->{$name} = 1;
128 ## Do the replacement
129 $str =~ s/\$\??([\(\w\)]+)/$val/;