lilalo

diff l3config.pm @ 156:a0daf0c3fa52

bsd fix
author Igor Chubin <igor@chub.in>
date Mon Nov 28 13:15:16 2011 +0200 (2011-11-28)
parents a2bd59599719
children
line diff
     1.1 --- a/l3config.pm	Tue Jun 23 01:24:33 2009 +0300
     1.2 +++ b/l3config.pm	Mon Nov 28 13:15:16 2011 +0200
     1.3 @@ -6,7 +6,7 @@
     1.4  use Getopt::Long;
     1.5  
     1.6  @ISA = ('Exporter');
     1.7 -@EXPORT = qw(%Config &init_config);
     1.8 +@EXPORT = qw(%Config &init_config &init_config_without_command_line_processing);
     1.9  
    1.10  our $System_Config_File = "/etc/lilalo.conf";
    1.11  our $User_Config_File = "$ENV{HOME}/.l3rc";
    1.12 @@ -49,6 +49,7 @@
    1.13      "encoding"          => "utf-8",
    1.14  
    1.15      "cache"             => "$ENV{HOME}/.lilalo/report.xml",
    1.16 +    "cache_sqlite"      => "$ENV{HOME}/.lilalo/report.sqlite",
    1.17      "cache_stat"        => "$ENV{HOME}/.lilalo/.report.dat",
    1.18  
    1.19      "output"            => "/tmp/report.html",
    1.20 @@ -152,32 +153,44 @@
    1.21  
    1.22  sub read_config_file
    1.23  {
    1.24 -	my $config = $_[0];
    1.25 -	my $filename = $_[1];
    1.26 -	open(CONFIG, "$filename")
    1.27 -		or return;
    1.28 -	while (<CONFIG>) {
    1.29 +    my $config = $_[0];
    1.30 +    my $filename = $_[1];
    1.31 +    open(CONFIG, "$filename")
    1.32 +        or return;
    1.33 +    while (<CONFIG>) {
    1.34          chomp;
    1.35 -		s/#.*//;
    1.36 -		next if /^\s*$/;
    1.37 -		my ($var, $val) =  split /\s*=\s*/, $_, 2;
    1.38 -		$var =~ s/\s*//;
    1.39 -		$config->{$var} = $val;
    1.40 -	}
    1.41 -	close(CONFIG);
    1.42 +        s/#.*//;
    1.43 +        next if /^\s*$/;
    1.44 +        my ($var, $val) =  split /\s*=\s*/, $_, 2;
    1.45 +        $var =~ s/\s*//;
    1.46 +        $config->{$var} = $val;
    1.47 +    }
    1.48 +    close(CONFIG);
    1.49  }
    1.50  
    1.51  
    1.52  sub init_config
    1.53  {
    1.54 -	my %argv_config;
    1.55 -	my %file_config;
    1.56 -	read_config_file(\%file_config, $System_Config_File);
    1.57 -	read_config_file(\%file_config, $User_Config_File);
    1.58 -	GetOptions(\%argv_config, map "$_=s", keys %Config);
    1.59 -	%Config = (%Config, %file_config, %argv_config);
    1.60 +    my %argv_config;
    1.61 +    my %file_config;
    1.62 +    read_config_file(\%file_config, $System_Config_File);
    1.63 +    read_config_file(\%file_config, $User_Config_File);
    1.64 +    GetOptions(\%argv_config, map "$_=s", keys %Config);
    1.65 +    %Config = (%Config, %file_config, %argv_config);
    1.66      for my $key (keys %Config) {
    1.67          utf8::decode($Config{$key});
    1.68      }
    1.69  }
    1.70  
    1.71 +sub init_config_without_command_line_processing
    1.72 +{
    1.73 +    my %argv_config;
    1.74 +    my %file_config;
    1.75 +    read_config_file(\%file_config, $System_Config_File);
    1.76 +    read_config_file(\%file_config, $User_Config_File);
    1.77 +    %Config = (%Config, %file_config);
    1.78 +    for my $key (keys %Config) {
    1.79 +        utf8::decode($Config{$key});
    1.80 +    }
    1.81 +}
    1.82 +