use strict;
use v5.012;
+use MISC;
package CONFIG;
-our %config = (
- 'address' => [ 2, 240, 8001, 7 ], # my address
- 'in_charset' => 'cp437', # input charset if unknown
+our %config;
- # Message Base
- 'dbase_driver' => 'sqlite',
- 'dbase_path' => '/home/basti/fido/msgbase',
- 'dbase_user' => '',
- 'dbase_pass' => '',
+# read and parse configuration file
+ my ($argidx) = grep $ARGV[$_] eq '-c', 0..$#ARGV;
+ if(!defined $argidx || !defined $ARGV[$argidx+1]) {
+ die("Please specify a configuration file (-c config)!\n\n");
+ }
+ open(CONF, '<', $ARGV[$argidx+1]) or
+ die("Can't open '$ARGV[$argidx+1]': $!!\n\n");
+ while(<CONF>) {
+ # sanitize input line
+ chomp;
+ next unless(/(\S)/); # empty lines
+ next if(/^[#;]/); # comment lines
+ s/^\s*//; s/\s*$//; # remove whitespace
- # Special Areas
- 'areafix' => 'AREAFIX',
- 'netmail' => 'NETMAIL',
- 'outbound' => 'OUTBOUND',
-);
+ # save valid lines
+ my ($key, $value) = split(/\s*=\s*/, $_);
+ $value =~ /^\"(.*)\"$/; $value = $1;
+ $config{lc $key}=$value;
+ }
+ close(CONF);
+
+# check mandatory keywords
+ my @keywords = (
+ 'address', 'in_charset', 'out_charset',
+ 'dbase_driver', 'dbase_path', 'dbase_user', 'dbase_pass',
+ 'netmail', 'outbound', 'areafix',
+ );
+ foreach my $key (@keywords) {
+ if(!defined $config{$key}) {
+ die("Keyword '$key' missing in configuration!\n\n");
+ }
+ }
+
+# fix non-strings
+ $config{address} = MISC::text2fido($config{address});
1;