]> git.donarmstrong.com Git - infobot.git/blob - src/Files.pl
b302604d09a46c2b4e6f1bf4c4cae764a3ca86f9
[infobot.git] / src / Files.pl
1 #
2 # Files.pl: Open and close, read and probably write files.
3 #   Author: dms
4 #  Version: v0.3 (20010120)
5 #  Created: 19991221
6 #
7
8 if (&IsParam("useStrict")) { use strict; }
9
10 # File: Language support.
11 sub loadLang {
12     my ($file) = @_;
13     my $langCount = 0;
14     my $replyName;
15
16     if (!open(FILE, $file)) {
17         &ERROR("FAILED loadLang ($file): $!");
18         exit 0;
19     }
20
21     undef %lang;                # for rehash.
22
23     while (<FILE>) {
24         chop;
25         if ($_ eq "" || /^#/) {
26             undef $replyName;
27             next;
28         }
29
30         if (!/^\s/) {
31             $replyName = $_;
32             next;
33         }
34
35         s/^[\s\t]+//g;
36         if (!$replyName) {
37             &status("loadLang: bad line ('$_')");
38             next;
39         }
40
41         $lang{$replyName}{$_} = 1;
42         $langCount++;
43     }
44     close FILE;
45
46     $file =~ s/^.*\///;
47     &status("Loaded lang $file ($langCount items)");
48 }
49
50 # File: Irc Servers list.
51 sub loadIRCServers {
52     my ($file)  = $bot_config_dir."/ircII.servers";
53     @ircServers = ();
54     %ircPort = ();
55
56     if (!open(FILE, $file)) {
57         &ERROR("FAILED loadIRCServers ($file): $!");
58         exit 0;
59     }
60
61     while (<FILE>) {
62         chop;
63         next if /^\s*$/;
64         next if /^[\#\[ ]/;
65
66         if (/^(\S+)(:(\d+))?$/) {
67             push(@ircServers,$1);
68             $ircPort{$1} = ($3 || 6667);
69         } else {
70             &status("loadIRCServers: invalid line => '$_'.");
71         }
72     }
73     close FILE;
74
75     $file =~ s/^.*\///;
76     &status("Loaded ircServers $file (". scalar(@ircServers) ." servers)");
77 }
78
79 1;