#!/usr/bin/perl -w use strict; use Getopt::Long; # pisg - Perl IRC Statistics Generator # # Copyright (C) 2001-2005 - morten@wtf.dk # Copyright (C) 2003-2006 Christoph Berg # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA sub main { my $script_dir = $0; # If the script was executed as ./pisg - then we just remove # everything after the last slash, if it was executed as 'perl pisg' # we assume that we are executing in the current dir. if ($script_dir =~ m/\/[^\/]*$/) { $script_dir =~ s/\/[^\/]*$//; } else { $script_dir = "."; } if (!-t STDOUT) { # we are not writing to a terminal push @ARGV, "--silent"; } my $cfg = get_cmdline_options($script_dir); unshift(@INC, $cfg->{modules_dir}); my $version; if ($cfg->{version}) { $version = 1; undef $cfg->{version}; } my $pisg; eval < '1', override_cfg => \$cfg, search_path => \$script_dir, ); if (\$version) { print \$pisg->{cfg}->{version} . "\n"; } else { \$pisg->run(); } END if ($@) { print STDERR "Could not load pisg! Reason:\n$@\n"; return undef; } } sub get_cmdline_options { my $script_dir = shift; my %cfg = ( modules_dir => "$script_dir/modules/", # Module search path logfile => [], logdir => [], ); # Commandline options my ($tmp, $help, $silent, $option, @cfg); my $usage = < \$cfg{channel}, 'cchannels=s@' => \@{ $cfg{cchannels} }, 'logfile=s' => \@{ $cfg{logfile} }, 'format=s' => \$cfg{format}, 'network=s' => \$cfg{network}, 'maintainer=s' => \$cfg{maintainer}, 'outfile=s' => \$cfg{outputfile}, 'tag=s' => \$cfg{outputtag}, 'dir=s' => \@{ $cfg{logdir} }, 'nfiles=i' => \$cfg{nfiles}, 'prefix=s' => \$cfg{logprefix}, 'moduledir=s' => \$cfg{moduledir}, 'configfile=s' => \$cfg{configfile}, 'ignorefile=s' => \$tmp, 'aliasfile=s' => \$tmp, 'silent' => \$silent, 'version' => \$cfg{version}, 'cfg=s' => \@cfg, 'help|?' => \$help ) == 0 or $help) { die($usage); } if ($tmp) { die("The aliasfile and ignorefile has been obsoleted by the new pisg.cfg, please use that instead [see pisg.cfg]\n"); } if ($silent) { $cfg{silent} = 1; } if (@cfg) { foreach (@cfg) { if (/(.*)=(.*)/) { $cfg{lc $1} = $2; } else { print STDERR "Warning: Couldn't parse -cfg option\n"; } } } return \%cfg; } main(); # Run the script