1 # Perl module for parsing LibUCW configuration files (using the ucw-config utility)
3 # (c) 2002--2005 Martin Mares <mj@ucw.cz>
5 # This software may be freely distributed and used according to the terms
6 # of the GNU Lesser General Public License.
16 our $DefaultConfigFile = "";
17 our $Usage = "-C, --config filename Override the default configuration file
18 -S, --set sec.item=val Manual setting of a configuration item";
24 my $override_config = 0;
25 push @options, "config|C=s" => sub { my ($o,$a)=@_; $defargs .= " -C'$a'"; $override_config=1; };
26 push @options, "set|S=s" => sub { my ($o,$a)=@_; $defargs .= " -S'$a'"; };
27 Getopt::Long::Configure("bundling");
28 Getopt::Long::GetOptions(@options) or return 0;
29 if (!$override_config && $DefaultConfigFile) {
30 $defargs = "-C'$DefaultConfigFile' $defargs";
32 foreach my $section (keys %Sections) {
33 my $opts = $Sections{$section};
34 my $optlist = join(";", keys %$opts);
35 my %filtered_opts = map { my $t=$_; $t=~s/[#\$]+$//; $t => $$opts{$_} } keys %$opts;
36 my @l = `bin/config $defargs "$section\{$optlist\}"`;
39 $o =~ /^CF_.*_([^=]+)='(.*)'\n$/ or die "Cannot parse bin/config output: $_";
40 my $var = $filtered_opts{$1};
42 if (ref $var eq "SCALAR") {
44 } elsif (ref $var eq "ARRAY") {
47 die ("UCW::Config::Parse: don't know how to set $o");