X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/5a4bc87c675dd76627a0d413707139f2e0530eea..c1339294a28926ba7593adbd3d48ef9f1bcf6dfa:/modules/Config/DevEdit.pm?ds=inline diff --git a/modules/Config/DevEdit.pm b/modules/Config/DevEdit.pm index 8adfd35..7402ff1 100644 --- a/modules/Config/DevEdit.pm +++ b/modules/Config/DevEdit.pm @@ -3,10 +3,10 @@ package Config::DevEdit; # # Dev-Editor - Module Config::DevEdit # -# Parse the configuration file +# Read and parse the configuration files # -# Author: Patrick Canterino -# Last modified: 2004-01-16 +# Author: Patrick Canterino +# Last modified: 2005-01-06 # use strict; @@ -22,39 +22,62 @@ use base qw(Exporter); # read_config() # -# Parse the configuration file +# Read the configuration files of Dev-Editor # -# Params: Path to configuration file +# Params: Path to main configuration file # # Return: Configuration (Hash Reference) sub read_config($) +{ + my $file = shift; + + my $config = parse_config($file); + + $config->{'errors'} = parse_config($config->{'error_file'}); + $config->{'templates'} = parse_config($config->{'template_file'}); + + return $config; +} + +# parse_config() +# +# Parse a configuration file +# +# Params: Path to configuration file +# +# Return: Configuration (Hash Reference) + +sub parse_config($) { my $file = shift; local *CF; - open(CF,"<$file") or croak("Open $file: $!"); + open(CF,'<'.$file) or croak("Open $file: $!"); read(CF, my $data, -s $file); close(CF); my @lines = split(/\015\012|\012|\015/,$data); my $config = {}; + my $count = 0; foreach my $line(@lines) { + $count++; + next if($line =~ /^\s*#/); - next if($line !~ /^.+=.+$/); + next if($line !~ /^\s*\S+\s*=.*$/); my ($key,$value) = split(/=/,$line,2); # Remove whitespaces at the beginning and at the end - $key =~ s/^\s*//g; - $key =~ s/\s*$//g; - $value =~ s/^\s*//g; - $value =~ s/\s*$//g; + $key =~ s/^\s+//g; + $key =~ s/\s+$//g; + $value =~ s/^\s+//g; + $value =~ s/\s+$//g; - croak "Double defined value '$key' in configuration file '$file'" if($config->{$key}); + croak "Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key}); $config->{$key} = $value; }