pisg.pl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. # If the script was executed as ./pisg.pl - then we just remove
  25. # everything after the last slash, if it was executed as 'perl pisg.pl'
  26. # we assume that we are executing in the current dir.
  27. if ($script_dir =~ m/\/[^\/]*$/) {
  28. $script_dir =~ s/\/[^\/]*$//;
  29. } else {
  30. $script_dir = ".";
  31. }
  32. my $cfg = get_cmdline_options($script_dir);
  33. push(@INC, $cfg->{modules_dir});
  34. my $pisg;
  35. eval <<END;
  36. use Pisg;
  37. \$pisg = new Pisg(
  38. use_configfile => '1',
  39. override_cfg => \$cfg,
  40. search_path => \$script_dir,
  41. );
  42. \$pisg->run();
  43. END
  44. if ($@) {
  45. print $@;
  46. }
  47. if ($@) {
  48. print STDERR "Could not load pisg! Reason:\n$@\n";
  49. return undef;
  50. }
  51. }
  52. sub get_cmdline_options
  53. {
  54. my $script_dir = shift;
  55. my $cfg = {
  56. modules_dir => "$script_dir/modules/", # Module search path
  57. };
  58. # Commandline options
  59. my ($tmp, $help, $silent, $option);
  60. my $usage = <<END_USAGE;
  61. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  62. [-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-h]
  63. -ch --channel=xxx : Set channel name
  64. -l --logfile=xxx : Log file to parse
  65. -o --outfile=xxx : Name of HTML file to create
  66. -ma --maintainer=xxx : Channel/statistics maintainer
  67. -f --format=xxx : Logfile format [see FORMATS file]
  68. -n --network=xxx : IRC Network for the channel.
  69. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  70. -p --prefix=xxx : Analyse only files prefixed by xxx in dir.
  71. Only works with --dir
  72. -mo --moduledir=xxx : Directory containing pisg modules.
  73. -co --configfile=xxx : Configuration file
  74. -s --silent : Suppress output (except error messages)
  75. -h --help : Output this message and exit (-? also works).
  76. Example:
  77. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  78. All options may also be defined by editing the configuration file and
  79. calling pisg without arguments.
  80. END_USAGE
  81. if (GetOptions('channel=s' => \$cfg->{channel},
  82. 'logfile=s' => \$cfg->{logfile},
  83. 'format=s' => \$cfg->{format},
  84. 'network=s' => \$cfg->{network},
  85. 'maintainer=s' => \$cfg->{maintainer},
  86. 'outfile=s' => \$cfg->{outputfile},
  87. 'dir=s' => \$cfg->{logdir},
  88. 'prefix=s' => \$cfg->{prefix},
  89. 'moduledir=s' => \$cfg->{moduledir},
  90. 'configfile=s' => \$cfg->{configfile},
  91. 'ignorefile=s' => \$tmp,
  92. 'aliasfile=s' => \$tmp,
  93. 'silent' => \$silent,
  94. 'help|?' => \$help
  95. ) == 0 or $help) {
  96. die($usage);
  97. }
  98. if ($tmp) {
  99. die("The aliasfile and ignorefile has been obsoleted by the new
  100. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  101. }
  102. if ($silent) { $cfg->{silent} = 1; }
  103. return $cfg;
  104. }
  105. main(); # Run the script