-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.pl
107 lines (82 loc) · 1.88 KB
/
config.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
##############################################################################
#
#
# Perl functions to read FIDOGATE config file,
# included by <INCLUDE config.pl> when running subst.pl
#
my %CONFIG;
# specials for DosDrive and Zone
my %CONFIG_dosdrive;
my %CONFIG_zone;
my %CONFIG_default =
(
<GEN perl-default>
);
my %CONFIG_abbrev =
(
<GEN perl-abbrev>
);
sub CONFIG_read {
my($file) = @_;
my($key, $arg);
local *C;
$file = CONFIG_expand($file);
open(C,"$file") || die "config.pl: can't open config file $file\n";
while(<C>) {
chop;
next if( /^\s*\#/ ); # comments
next if( /^\s*$/ ); # empty
s/\s*$//; # remove trailing white space
s/^\s*//; # remove leading white space
($key,$arg) = split(' ', $_, 2);
$key =~ tr/A-Z/a-z/;
if($key eq "include") {
CONFIG_read($arg);
next;
}
if($key eq "dosdrive") {
my ($d, $path) = split(' ', $arg);
$CONFIG_dosdrive{lc($d)} = $path;
next;
}
if($key eq "zone") {
my ($z, $rest) = split(' ', $arg, 2);
$CONFIG_zone{$z} = $rest;
next;
}
$CONFIG{$key} = $arg if(!$CONFIG{$key});
}
close(C);
}
sub CONFIG_get1 {
my($key) = @_;
my($ukey);
$ukey = $key;
$ukey =~ tr/a-z/A-Z/;
return $ENV{"FIDOGATE_$ukey"} if($ENV{"FIDOGATE_$ukey"});
return $CONFIG{$key} if($CONFIG{$key});
return $CONFIG_default{$key};
}
sub CONFIG_get {
my($key) = @_;
my($ret);
my($exp);
$key =~ tr/A-Z/a-z/;
return CONFIG_expand( CONFIG_get1($key) );
}
sub CONFIG_expand {
my($v) = @_;
my($exp);
if($v =~ /^%([A-Z])/) {
$exp = CONFIG_get1($CONFIG_abbrev{$1});
$v =~ s/^%./$exp/;
}
return $v;
}
sub CONFIG_debug {
my($key);
for $key (keys %CONFIG) {
print "$key = $CONFIG{$key} -> ", CONFIG_get($key), "\n";
}
}
##############################################################################