X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fperl%2FConfig.pm;h=d145495cb25a4c21c0d5b02b2057b68918ef8818;hb=1d8112cb590e458baa899805908a8ac910f58163;hp=0d968da01aef3482511d8c331c5e24fccd83092a;hpb=3f29125f27f7ee82281e49fef16ad32811cc3dcc;p=libucw.git diff --git a/lib/perl/Config.pm b/lib/perl/Config.pm index 0d968da0..d145495c 100644 --- a/lib/perl/Config.pm +++ b/lib/perl/Config.pm @@ -1,6 +1,6 @@ # Perl module for parsing Sherlock configuration files (using the config utility) # -# (c) 2002 Martin Mares +# (c) 2002--2005 Martin Mares # # This software may be freely distributed and used according to the terms # of the GNU Lesser General Public License. @@ -14,6 +14,9 @@ use Getopt::Long; our %Sections = (); our $DefaultConfigFile = ""; +our $Usage = "-C, --config filename Override the default configuration file +-S, --set sec.item=val Manual setting of a configuration item"; + sub Parse(@) { my @options = @_; @@ -21,18 +24,20 @@ sub Parse(@) { 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 @l = `bin/config $defargs $section $optlist`; + 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;