X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fperl%2FConfig.pm;h=8d98c5615aa92a8736430c4e21c4aea4bcd86d98;hb=396571ed89ec4260ba3fd1b7ce2b38b07bd90ab7;hp=bf013b731d6eb9a4087780ffee2c204b20b0d8af;hpb=7d03eebb5f18086cf58077bd6a0bce808e62f7e7;p=libucw.git diff --git a/lib/perl/Config.pm b/lib/perl/Config.pm index bf013b73..8d98c561 100644 --- a/lib/perl/Config.pm +++ b/lib/perl/Config.pm @@ -1,5 +1,9 @@ -# Perl module for parsing Sherlock configuration files (using the config utility) -# (c) 2002 Martin Mares +# Perl module for parsing Sherlock configuration files (using the config utility) +# +# (c) 2002--2005 Martin Mares +# +# This software may be freely distributed and used according to the terms +# of the GNU Lesser General Public License. package Sherlock::Config; @@ -9,20 +13,28 @@ use Getopt::Long; our %Sections = (); +our $DefaultConfigFile = ""; + sub Parse(@) { my @options = @_; my $defargs = ""; - push @options, "config|C=s" => sub { my ($o,$a)=@_; $defargs .= " -C'$a'"; }; + my $override_config = 0; + push @options, "config|C=s" => sub { my ($o,$a)=@_; $defargs .= " -C'$a'"; $override_config=1; }; push @options, "set|S=s" => sub { my ($o,$a)=@_; $defargs .= " -S'$a'"; }; + Getopt::Long::Configure("bundling"); Getopt::Long::GetOptions(@options) or return 0; + if (!$override_config && $DefaultConfigFile) { + $defargs = "-C'$DefaultConfigFile' $defargs"; + } foreach my $section (keys %Sections) { my $opts = $Sections{$section}; my $optlist = join(" ", keys %$opts); + my %filtered_opts = map { my $t=$_; $t=~s/[#\$]+$//; $t => $$opts{$_} } keys %$opts; my @l = `bin/config $defargs $section $optlist`; $? && exit 1; foreach my $o (@l) { - $o =~ /^CF_([^=]+)="(.*)"\n$/ or die "Cannot parse bin/config output: $_"; - my $var = $$opts{$1}; + $o =~ /^CF_([^=]+)='(.*)'\n$/ or die "Cannot parse bin/config output: $_"; + my $var = $filtered_opts{$1}; my $val = $2; if (ref $var eq "SCALAR") { $$var = $val;