Moved “getconf” to its own “lib” file; bumped version to 0.5.5
This commit is contained in:
parent
c7ae27716d
commit
d402a403d1
1 changed files with 2 additions and 41 deletions
43
ganciof2f
43
ganciof2f
|
@ -18,8 +18,9 @@
|
|||
|
||||
$SNAME='GancioF2F';
|
||||
$ENAME=strtolower($SNAME);
|
||||
$SVERS='0.5.4';
|
||||
$SVERS='0.5.5';
|
||||
|
||||
require __DIR__.'/lib/getconf.php';
|
||||
require __DIR__.'/lib/ckmkeys.php';
|
||||
require __DIR__.'/lib/gettlds.php';
|
||||
require __DIR__.'/lib/mastodon-postLength.php';
|
||||
|
@ -564,46 +565,6 @@ if (!$opts['test']) {
|
|||
exit(0);
|
||||
|
||||
|
||||
function getConf(&$conf,&$confFP) {
|
||||
$errors=[];
|
||||
$nconf=[];
|
||||
$buff=@file($confFP,FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
if ($buff===false) dieYoung("Error: could not read configuration file «$confFP}».\n",1);
|
||||
$i=0;
|
||||
foreach ($buff as $line) {
|
||||
$i++;
|
||||
if ($line[0]!=='#') {
|
||||
if (preg_match('#^([^=]+)=(.+)$#',$line,$matches)===1) {
|
||||
$matches[1]=trim($matches[1]);
|
||||
$matches[2]=trim($matches[2]);
|
||||
if (array_key_exists($matches[1],$conf))
|
||||
$nconf[$matches[1]]=$matches[2];
|
||||
else
|
||||
$errors[]="line {$i}: «{$matches[1]}» is an unknown key";
|
||||
} else {
|
||||
$errors[]="could not interpret line {$i} («{$line}»)";
|
||||
}
|
||||
}
|
||||
}
|
||||
//print_r($nconf);
|
||||
foreach ($conf as $key=>$val) {
|
||||
if ($conf[$key]['required'] && !array_key_exists($key,$nconf))
|
||||
$errors[]="«{$key}» is not defined";
|
||||
if (array_key_exists($key,$nconf))
|
||||
$conf[$key]=$nconf[$key];
|
||||
else
|
||||
$conf[$key]=$conf[$key]['default'];
|
||||
}
|
||||
$errorsCount=count($errors);
|
||||
if ($errorsCount>0) {
|
||||
fwrite(STDERR,"Sorry, there are errors in configuration file «{$confFP}»:\n");
|
||||
for ($i=1; $i<=$errorsCount; $i++)
|
||||
fwrite(STDERR," {$i}. {$errors[$i-1]}\n");
|
||||
fwrite(STDERR,"Use «-h» or «--help» to display help.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function cknap($napid) {
|
||||
global $naps;
|
||||
$now=time();
|
||||
|
|
Loading…
Reference in a new issue