pisg.pl 4.2 KB

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