Add rcfile (.yapfaqrc) for configuration.
All configuration data is read from .yapfaqrc with defaults set in yapfaq.pl Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
2507947f17
commit
d60c2d5fdf
29
yapfaq.pl
29
yapfaq.pl
|
@ -14,6 +14,12 @@
|
||||||
|
|
||||||
my $Version = "0.6.2";
|
my $Version = "0.6.2";
|
||||||
|
|
||||||
|
my $RCFile = '.yapfaqrc';
|
||||||
|
my @ValidConfVars = ('NNTPServer','NNTPUser','NNTPPass','Sender','ConfigFile',
|
||||||
|
'UsePGP','pgp','PGPVersion','PGPSigner','PGPPass',
|
||||||
|
'PathtoPGPPass','pgpbegin','pgpend','pgptmpf','pgpheader');
|
||||||
|
|
||||||
|
################################### Defaults ##################################
|
||||||
my %Config = (NNTPServer => "localhost",
|
my %Config = (NNTPServer => "localhost",
|
||||||
NNTPUser => "",
|
NNTPUser => "",
|
||||||
NNTPPass => "",
|
NNTPPass => "",
|
||||||
|
@ -71,6 +77,9 @@ if ($Options{'h'}) {
|
||||||
# -f: set $Faq
|
# -f: set $Faq
|
||||||
my ($Faq) = $Options{'f'} if ($Options{'f'});
|
my ($Faq) = $Options{'f'} if ($Options{'f'});
|
||||||
|
|
||||||
|
# read runtime configuration (configuration variables)
|
||||||
|
readrc (\$RCFile,\%Config) if -f $RCFile;
|
||||||
|
|
||||||
# read configuration (configured FAQs)
|
# read configuration (configured FAQs)
|
||||||
my @Config;
|
my @Config;
|
||||||
readconfig (\$Config{'ConfigFile'}, \@Config, \$Faq);
|
readconfig (\$Config{'ConfigFile'}, \@Config, \$Faq);
|
||||||
|
@ -124,6 +133,26 @@ foreach (@Config) {
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
|
#################################### readrc ####################################
|
||||||
|
# Takes a filename and the reference to an array which contains the valid options
|
||||||
|
|
||||||
|
sub readrc{
|
||||||
|
my ($File, $Config) = @_;
|
||||||
|
|
||||||
|
print "Reading $$File.\n" if($Options{'v'});
|
||||||
|
|
||||||
|
open FH, "<$$File" or die "$0: Can't open $$File: $!";
|
||||||
|
while (<FH>) {
|
||||||
|
if (/^\s*(\S+)\s*=\s*'?(.*?)'?\s*(#.*$|$)/) {
|
||||||
|
if (grep(/$1/,@ValidConfVars)) {
|
||||||
|
$$Config{$1} = $2 if $2 ne '';
|
||||||
|
} else {
|
||||||
|
warn "$0: W: $1 is not a valid configuration variable (reading from $$File)\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
################################## readconfig ##################################
|
################################## readconfig ##################################
|
||||||
# Takes a filename, a reference to an array, which will hold hashes with
|
# Takes a filename, a reference to an array, which will hold hashes with
|
||||||
# the data from $File, and - optionally - the name of the (single) FAQ to post
|
# the data from $File, and - optionally - the name of the (single) FAQ to post
|
||||||
|
|
Loading…
Reference in a new issue