X-Git-Url: https://code.th-h.de/?p=usenet%2Fyapfaq.git;a=blobdiff_plain;f=yapfaq.pl;h=c9a8098c13ac98f0ee31dc7cf5025dd13cfc7ef6;hp=0d331b04b6a6ba2fcc388575b3b2b45d4235408c;hb=86c0a10044727dae98e0ccbd9aee475e8154c15f;hpb=2507947f17862c5463b0def8ce942e6d5b62631c diff --git a/yapfaq.pl b/yapfaq.pl index 0d331b0..c9a8098 100644 --- a/yapfaq.pl +++ b/yapfaq.pl @@ -14,6 +14,12 @@ 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", NNTPUser => "", NNTPPass => "", @@ -56,7 +62,7 @@ my ($TDY, $TDM, $TDD) = Today(); #TD: Today's date # read commandline options my %Options; -getopts('Vhvpdt:f:s:', \%Options); +getopts('Vhvpdt:f:c:s:', \%Options); # -V: print version / copyright information if ($Options{'V'}) { print "$0 v $Version\nCopyright (c) 2003 Marc Brockschmidt \nCopyright (c) 2010 Thomas Hochstein \n"; @@ -71,6 +77,14 @@ if ($Options{'h'}) { # -f: set $Faq my ($Faq) = $Options{'f'} if ($Options{'f'}); +# read runtime configuration (configuration variables) +$RCFile = $Options{'c'} if ($Options{'c'}); +if (-f $RCFile) { + readrc (\$RCFile,\%Config); +} else { + warn "$0: W: .rc file $RCFile does not exist!\n"; +} + # read configuration (configured FAQs) my @Config; readconfig (\$Config{'ConfigFile'}, \@Config, \$Faq); @@ -124,6 +138,26 @@ foreach (@Config) { 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 () { + 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 ################################## # 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