]> jfr.im git - irc/pisg.git/blob - pisg/pisg
import from cvs
[irc/pisg.git] / pisg / pisg
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5
6 # pisg - Perl IRC Statistics Generator
7 #
8 # Copyright (C) 2001-2005 <Morten Brix Pedersen> - morten@wtf.dk
9 # Copyright (C) 2003-2006 Christoph Berg <cb@df7cb.de>
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25 sub main
26 {
27 my $script_dir = $0;
28
29 # If the script was executed as ./pisg - then we just remove
30 # everything after the last slash, if it was executed as 'perl pisg'
31 # we assume that we are executing in the current dir.
32 if ($script_dir =~ m/\/[^\/]*$/) {
33 $script_dir =~ s/\/[^\/]*$//;
34 } else {
35 $script_dir = ".";
36 }
37
38 if (!-t STDOUT) { # we are not writing to a terminal
39 push @ARGV, "--silent";
40 }
41
42 my $cfg = get_cmdline_options($script_dir);
43 unshift(@INC, $cfg->{modules_dir});
44
45 my $version;
46 if ($cfg->{version}) {
47 $version = 1;
48 undef $cfg->{version};
49 }
50
51 my $pisg;
52 eval <<END;
53
54 use Pisg;
55
56 \$pisg = new Pisg(
57 use_configfile => '1',
58 override_cfg => \$cfg,
59 search_path => \$script_dir,
60 );
61
62 if (\$version) {
63 print \$pisg->{cfg}->{version} . "\n";
64 } else {
65 \$pisg->run();
66 }
67 END
68 if ($@) {
69 print STDERR "Could not load pisg! Reason:\n$@\n";
70 return undef;
71 }
72 }
73
74 sub get_cmdline_options
75 {
76 my $script_dir = shift;
77
78 my %cfg = (
79 modules_dir => "$script_dir/modules/", # Module search path
80 logfile => [],
81 logdir => [],
82 );
83
84 # Commandline options
85 my ($tmp, $help, $silent, $option, @cfg);
86
87 my $usage = <<END_USAGE;
88 Usage: pisg [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
89 [-f format] [-ne network] [-d logdir] [-mo moduledir] [-s] [-v] [-h]
90
91 -ch --channel=xxx : Set channel name
92 -cc --cchannels=xxx : Only do this channel from cfg file, give multiple
93 times to do multiple channels
94 -l --logfile=xxx : Log file to parse, give multiple times to use
95 multiple log files.
96 -o --outfile=xxx : Name of HTML file to create
97 -t --tag=xxx : Replace \%t in --outfile by xxx
98 -ma --maintainer=xxx : Channel/statistics maintainer
99 -f --format=xxx : Logfile format [see FORMATS file]
100 -ne --network=xxx : IRC network for the channel
101 -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
102 Give multiple times to use multiple directories.
103 -nf --nfiles=xxx : Analyze the last xxx files if used with --dir
104 -p --prefix=xxx : Analyze only files prefixed by xxx in dir
105 Only works with --dir
106 -cf --cfg opt=value : Specify configuration options, eg. -cf ShowWpl=1
107 -co --configfile=xxx : Configuration file
108 -mo --moduledir=xxx : Directory containing pisg modules
109 -s --silent : Suppress output (except error messages)
110 -v --version : Show version
111 -h --help : Output this message and exit.
112
113 Example:
114
115 \$ pisg -ne IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
116
117 All options may also be defined by editing the configuration file and
118 calling pisg without arguments.
119 END_USAGE
120
121 if (GetOptions('channel=s' => \$cfg{channel},
122 'cchannels=s@' => \@{ $cfg{cchannels} },
123 'logfile=s' => \@{ $cfg{logfile} },
124 'format=s' => \$cfg{format},
125 'network=s' => \$cfg{network},
126 'maintainer=s' => \$cfg{maintainer},
127 'outfile=s' => \$cfg{outputfile},
128 'tag=s' => \$cfg{outputtag},
129 'dir=s' => \@{ $cfg{logdir} },
130 'nfiles=i' => \$cfg{nfiles},
131 'prefix=s' => \$cfg{logprefix},
132 'moduledir=s' => \$cfg{moduledir},
133 'configfile=s' => \$cfg{configfile},
134 'ignorefile=s' => \$tmp,
135 'aliasfile=s' => \$tmp,
136 'silent' => \$silent,
137 'version' => \$cfg{version},
138 'cfg=s' => \@cfg,
139 'help|?' => \$help
140 ) == 0 or $help) {
141 die($usage);
142 }
143
144 if ($tmp) {
145 die("The aliasfile and ignorefile has been obsoleted by the new
146 pisg.cfg, please use that instead [see pisg.cfg]\n");
147 }
148
149 if ($silent) { $cfg{silent} = 1; }
150
151 if (@cfg) {
152 foreach (@cfg) {
153 if (/(.*)=(.*)/) {
154 $cfg{lc $1} = $2;
155 } else {
156 print STDERR "Warning: Couldn't parse -cfg option\n";
157 }
158 }
159 }
160
161 return \%cfg;
162
163 }
164
165 main(); # Run the script