X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FFiles.pl;h=3a294aae063c628a2fd3fb8c1c7eb23690cbf99a;hb=a3b7cbdc04f29264990ff836bdd1e8c91cb9b337;hp=45431839ed9fc19d2b2adddbd71f551c686c3bf1;hpb=f8deca40bc9bd35788be34d2c5bff98dca92a93c;p=infobot.git diff --git a/src/Files.pl b/src/Files.pl index 4543183..3a294aa 100644 --- a/src/Files.pl +++ b/src/Files.pl @@ -1,11 +1,15 @@ # # Files.pl: Open and close, read and probably write files. # Author: dms -# Version: v0.2 (2000502) +# Version: v0.3 (20010120) # Created: 19991221 # -if (&IsParam("useStrict")) { use strict; } +use strict; + +use vars qw(%lang %ircPort); +use vars qw(@ircServers); +use vars qw($bot_config_dir); # File: Language support. sub loadLang { @@ -13,153 +17,70 @@ sub loadLang { my $langCount = 0; my $replyName; - if (!open(FILE, $file)) { - &ERROR("FAILED loadLang ($file): $!"); - exit 0; + if ( !open( FILE, $file ) ) { + &ERROR("Failed reading lang file ($file): $!"); + exit 0; } - undef %lang; # for rehash. - - while () { - chop; - if ($_ eq "" || /^#/) { - undef $replyName; - next; - } - - if (!/^\s/) { - $replyName = $_; - next; - } - - s/^[\s\t]+//g; - if (!$replyName) { - &status("loadLang: bad line ('$_')"); - next; - } - - $lang{$replyName}{$_} = 1; - $langCount++; - } - close FILE; - - $file =~ s/^.*\///; - &status("Loaded lang $file ($langCount items)"); -} - -# File: Ignore list. -sub loadIgnore { - my ($file) = @_; - %ignoreList = (); - - if (!open(FILE, $file)) { - &ERROR("FAILED loadIgnore ($file): $!"); - return; - } - &status("Loading ignore list..."); + undef %lang; # for rehash. - my $count = 0; while () { - chomp; - next if /^\s*\#/; - next unless /\S/; - - if (/^(\S+)[\t\s]+(\S+)([\t\s]+.*)?$/) { - &status(" $2"); - $ignoreList{$2} = 1; - $count++; - } + chop; + if ( $_ eq '' || /^#/ ) { + undef $replyName; + next; + } + + if ( !/^\s/ ) { + $replyName = $_; + next; + } + + s/^[\s\t]+//g; + if ( !$replyName ) { + &status("loadLang: bad line ('$_')"); + next; + } + + $lang{$replyName}{$_} = 1; + $langCount++; } close FILE; $file =~ s/^.*\///; - &status("Loaded ignore $file ($count masks)"); + &status("Loaded $file ($langCount items)"); } # File: Irc Servers list. sub loadIRCServers { - my ($file) = @_; + my ($file) = $bot_config_dir . '/infobot.servers'; @ircServers = (); - %ircPort = (); + %ircPort = (); - if (!open(FILE, $file)) { - &ERROR("FAILED loadIRCServers ($file): $!"); - exit 0; + if ( !open( FILE, $file ) ) { + &ERROR("Failed reading server list ($file): $!"); + exit 0; } while () { - chop; - next if /^\s*$/; - next if /^[\#\[ ]/; - - if (/^(\S+)(:(\d+))?$/) { - push(@ircServers,$1); - $ircPort{$1} = ($3 || 6667); - } else { - &status("loadIRCServers: invalid line => '$_'."); - } + chop; + next if /^\s*$/; + next if /^[\#\[ ]/; + + if (/^\s*(\S+?)(:(\d+))?\s*$/) { + push( @ircServers, $1 ); + $ircPort{$1} = ( $3 || 6667 ); + } + else { + &status("loadIRCServers: invalid line => '$_'."); + } } close FILE; $file =~ s/^.*\///; - &status("Loaded ircServers $file (". scalar(@ircServers) ." servers)"); -} - -# File: User List. -sub loadUsers { - my ($file) = @_; - %userList = (); # clear it. - - if (!open(FILE, $file)) { - &ERROR("FAILED loadUsers ($file): $!"); - exit 0; - } - - my $userName; - - while () { - next if /^\s*$/; - next if /^#/; - - if (/^UserEntry\s+(.+?)\s/) { - $userName = $1; - if (/\s*\{\s*/) { - while () { - if (/^\s*(\w+)\s+(.+);$/) { - my ($opt,$val) = ($1,$2); - - $opt =~ tr/A-Z/a-z/; - $val =~ s/\"//g; - $val =~ s/\+// if ($opt =~ /^flags$/i); - - if ($opt =~ /^mask$/i) { - $userList{$userName}{$opt}{$val} = 1; - } else { - $userList{$userName}{$opt} = $val; - } - } elsif (/^\s*\}\s*$/) { - last; - } - } - } else { - &status("parse error: User Entry $userName without right brace"); - } - } - } - close FILE; - - return unless (&IsParam("VERBOSITY")); - - $file =~ s/^.*\///; - &status("Loaded userlist $file (". scalar(keys %userList) ." users)"); - foreach $userName (keys %userList) { - &status(" $userName:"); - &status(" flags: +$userList{$userName}{'flags'}"); - - foreach (keys %{$userList{$userName}{'mask'}}) { - &status(" hostmask: $_"); - } - } + &status( "Loaded $file (" . scalar(@ircServers) . ' servers)' ); } 1; + +# vim:ts=4:sw=4:expandtab:tw=80