pisg.pl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. use FindBin;
  5. # pisg - Perl IRC Statistics Generator
  6. #
  7. # Copyright (C) 2001 <Morten Brix Pedersen> - morten@wtf.dk
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. sub main
  23. {
  24. my $cfg = get_cmdline_options();
  25. push(@INC, $cfg->{modules_dir});
  26. my $pisg;
  27. eval <<END;
  28. use Pisg;
  29. \$pisg = new Pisg(
  30. use_configfile => '1',
  31. override_cfg => \$cfg
  32. );
  33. \$pisg->run();
  34. END
  35. if ($@) {
  36. print $@;
  37. }
  38. if ($@) {
  39. print STDERR "Could not load pisg! Reason:\n$@\n";
  40. return undef;
  41. }
  42. }
  43. sub get_cmdline_options
  44. {
  45. my $cfg = {
  46. modules_dir => $FindBin::Bin . "/modules", # Module search path
  47. };
  48. my $tmp;
  49. # Commandline options
  50. my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help, $silent);
  51. my $usage = <<END_USAGE;
  52. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  53. [-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-h]
  54. -ch --channel=xxx : Set channel name
  55. -l --logfile=xxx : Log file to parse
  56. -o --outfile=xxx : Name of html file to create
  57. -ma --maintainer=xxx : Channel/statistics maintainer
  58. -f --format=xxx : Logfile format [see FORMATS file]
  59. -n --network=xxx : IRC Network this channel is on.
  60. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  61. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  62. Only works with --dir
  63. -mo --moduledir=xxx : Directory containing pisg's modules.
  64. -co --configfile=xxx : Config file
  65. -s --silent : Suppress output (except error messages)
  66. -h --help : Output this message and exit (-? also works).
  67. Example:
  68. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  69. All options may also be defined by editing the configuration file and
  70. calling pisg without arguments.
  71. END_USAGE
  72. #'
  73. if (GetOptions('channel=s' => \$channel,
  74. 'logfile=s' => \$logfile,
  75. 'format=s' => \$format,
  76. 'network=s' => \$network,
  77. 'maintainer=s' => \$maintainer,
  78. 'outfile=s' => \$outputfile,
  79. 'dir=s' => \$logdir,
  80. 'prefix=s' => \$prefix,
  81. 'ignorefile=s' => \$tmp,
  82. 'aliasfile=s' => \$tmp,
  83. 'moduledir=s' => \$moduledir,
  84. 'configfile=s' => \$configfile,
  85. 'silent' => \$silent,
  86. 'help|?' => \$help
  87. ) == 0 or $help) {
  88. die($usage);
  89. }
  90. if ($tmp) {
  91. die("The aliasfile and ignorefile has been obsoleted by the new
  92. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  93. }
  94. if ($channel) { $cfg->{channel} = $channel; }
  95. if ($logfile) { $cfg->{logfile} = $logfile; }
  96. if ($format) { $cfg->{format} = $format; }
  97. if ($network) { $cfg->{network} = $network; }
  98. if ($maintainer) { $cfg->{maintainer} = $maintainer; }
  99. if ($outputfile) { $cfg->{outputfile} = $outputfile; }
  100. if ($logdir) { $cfg->{logdir} = $logdir; }
  101. if ($prefix) { $cfg->{prefix} = $prefix; }
  102. if ($moduledir) { $cfg->{modules_dir} = $moduledir; }
  103. if ($configfile) { $cfg->{configfile} = $configfile; }
  104. if ($silent) { $cfg->{silent} = 1; }
  105. return $cfg;
  106. }
  107. main(); # Run the script