summaryrefslogtreecommitdiff
path: root/modules/ConfigParser.pm
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2006-07-11 11:42:26 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2006-07-11 11:42:26 +0000
commit69e64320e754bc3600c1b292857f0a8850e072ce (patch)
tree98001c260ada3448b3aed8c3bd4cfaad9e35129c /modules/ConfigParser.pm
parent879e6a2242d98121e58ffd07cf61f3b947a9db80 (diff)
downloadMPC-69e64320e754bc3600c1b292857f0a8850e072ce.tar.gz
ChangeLogTag: Tue Jul 11 11:42:25 UTC 2006 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'modules/ConfigParser.pm')
-rw-r--r--modules/ConfigParser.pm97
1 files changed, 97 insertions, 0 deletions
diff --git a/modules/ConfigParser.pm b/modules/ConfigParser.pm
new file mode 100644
index 00000000..c2b37078
--- /dev/null
+++ b/modules/ConfigParser.pm
@@ -0,0 +1,97 @@
+package ConfigParser;
+
+# ************************************************************
+# Description : Reads a generic config file and store the values
+# Author : Chad Elliott
+# Create Date : 6/12/2006
+# ************************************************************
+
+# ************************************************************
+# Pragmas
+# ************************************************************
+
+use strict;
+
+use Parser;
+
+use vars qw(@ISA);
+@ISA = qw(Parser);
+
+# ************************************************************
+# Subroutine Section
+# ************************************************************
+
+sub new {
+ my($class) = shift;
+ my($valid) = shift;
+ my($self) = $class->SUPER::new();
+
+ ## Set the values associative array
+ $self->{'values'} = {};
+ $self->{'valid'} = $valid;
+
+ return $self;
+}
+
+
+sub parse_line {
+ my($self) = shift;
+ my($if) = shift;
+ my($line) = shift;
+ my($status) = 1;
+ my($error) = undef;
+
+ if ($line eq '') {
+ }
+ elsif ($line =~ /^([^=]+)\s*=\s*(.*)$/) {
+ my($name) = $1;
+ my($value) = $2;
+ $name =~ s/\s+$//;
+
+ ## Pre-process the name and value
+ while($name =~ /\$(\w+)/) {
+ my($val) = $ENV{$1} || '';
+ $name =~ s/\$(\w+)/$val/;
+ }
+ while($value =~ /\$(\w+)/) {
+ my($val) = $ENV{$1} || '';
+ $value =~ s/\$(\w+)/$val/;
+ }
+ $name =~ s/\\/\//g;
+
+ ## Store the name value pair
+ if (!defined $self->{'valid'}) {
+ $self->{'values'}->{$name} = $value;
+ }
+ elsif (defined $self->{'valid'}->{lc($name)}) {
+ $self->{'values'}->{lc($name)} = $value;
+ }
+ else {
+ $status = 0;
+ $error = "Invalid keyword: $name";
+ }
+ }
+ else {
+ $status = 0;
+ $error = "Unrecognized line: $line";
+ }
+
+ return $status, $error;
+}
+
+
+sub get_names {
+ my($self) = shift;
+ my(@names) = keys %{$self->{'values'}};
+ return \@names;
+}
+
+
+sub get_value {
+ my($self) = shift;
+ my($tag) = shift;
+ return $self->{'values'}->{$tag} || $self->{'values'}->{lc($tag)};
+}
+
+
+1;