]> mj.ucw.cz Git - libucw.git/blobdiff - lib/perl/Config.pm
When writing, the data needn't start at the beginning of the buffer.
[libucw.git] / lib / perl / Config.pm
index bf013b731d6eb9a4087780ffee2c204b20b0d8af..0d968da01aef3482511d8c331c5e24fccd83092a 100644 (file)
@@ -1,5 +1,9 @@
-# Perl module for parsing Sherlock configuration files (using the config utility)
-# (c) 2002 Martin Mares <mj@ucw.cz>
+#      Perl module for parsing Sherlock configuration files (using the config utility)
+#
+#      (c) 2002 Martin Mares <mj@ucw.cz>
+#
+#      This software may be freely distributed and used according to the terms
+#      of the GNU Lesser General Public License.
 
 package Sherlock::Config;
 
@@ -9,12 +13,18 @@ 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::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);