pisg.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 $conf = get_cmdline_options();
  25. push(@INC, $conf->{modules_dir});
  26. my $pisg;
  27. eval <<END;
  28. use Pisg;
  29. \$pisg = new Pisg(\$conf);
  30. \$pisg->run();
  31. END
  32. if ($@) {
  33. print $@;
  34. }
  35. if ($@) {
  36. print STDERR "Could not load pisg!\n$@\n";
  37. return undef;
  38. }
  39. }
  40. sub get_cmdline_options
  41. {
  42. my $conf = {
  43. modules_dir => $FindBin::Bin . "/modules", # Module search path
  44. };
  45. my $tmp;
  46. # Commandline options
  47. my ($moduledir, $channel, $logfile, $format, $network, $maintainer, $outputfile, $logdir, $prefix, $configfile, $help);
  48. my $usage = <<END_USAGE;
  49. Usage: pisg.pl [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  50. [-f format] [-n network] [-d logdir] [-mo moduledir] [-h]
  51. -ch --channel=xxx : Set channel name
  52. -l --logfile=xxx : Log file to parse
  53. -o --outfile=xxx : Name of html file to create
  54. -ma --maintainer=xxx : Channel/statistics maintainer
  55. -f --format=xxx : Logfile format [see FORMATS file]
  56. -n --network=xxx : IRC Network this channel is on.
  57. -d --dir=xxx : Analyze all files in this dir. Ignores logfile.
  58. -p --prefix=xxx : Analyse only files starting with xxx in dir.
  59. Only works with --dir
  60. -mo --moduledir=xxx : Directory containing pisg's modules.
  61. -co --configfile=xxx : Config file
  62. -h --help : Output this message and exit (-? also works).
  63. Example:
  64. \$ pisg.pl -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  65. All options may also be defined by editing the configuration file and
  66. calling pisg without arguments.
  67. END_USAGE
  68. #'
  69. if (GetOptions('channel=s' => \$channel,
  70. 'logfile=s' => \$logfile,
  71. 'format=s' => \$format,
  72. 'network=s' => \$network,
  73. 'maintainer=s' => \$maintainer,
  74. 'outfile=s' => \$outputfile,
  75. 'dir=s' => \$logdir,
  76. 'prefix=s' => \$prefix,
  77. 'ignorefile=s' => \$tmp,
  78. 'aliasfile=s' => \$tmp,
  79. 'moduledir=s' => \$moduledir,
  80. 'configfile=s' => \$configfile,
  81. 'help|?' => \$help
  82. ) == 0 or $help) {
  83. die($usage);
  84. }
  85. if ($tmp) {
  86. die("The aliasfile and ignorefile has been obsoleted by the new
  87. pisg.cfg, please use that instead [look in pisg.cfg]\n");
  88. }
  89. if ($channel) {
  90. $conf->{channel} = $channel;
  91. }
  92. if ($logfile) {
  93. $conf->{logfile} = $logfile;
  94. }
  95. if ($format) {
  96. $conf->{format} = $format;
  97. }
  98. if ($network) {
  99. $conf->{network} = $network;
  100. }
  101. if ($maintainer) {
  102. $conf->{maintainer} = $maintainer;
  103. }
  104. if ($outputfile) {
  105. $conf->{outputfile} = $outputfile;
  106. }
  107. if ($logdir) {
  108. $conf->{logdir} = $logdir;
  109. }
  110. if ($prefix) {
  111. $conf->{prefix} = $prefix;
  112. }
  113. if ($moduledir) {
  114. $conf->{modules_dir} = $moduledir;
  115. }
  116. if ($configfile) {
  117. $conf->{configfile} = $configfile;
  118. }
  119. return $conf;
  120. }
  121. main(); # Run the script