pisg 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long;
  4. # pisg - Perl IRC Statistics Generator
  5. #
  6. # Copyright (C) 2001-2002 <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 - then we just remove
  25. # everything after the last slash, if it was executed as 'perl pisg'
  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 $version;
  35. if ($cfg->{version}) {
  36. $version = 1;
  37. undef $cfg->{version};
  38. }
  39. my $pisg;
  40. eval <<END;
  41. use Pisg;
  42. \$pisg = new Pisg(
  43. use_configfile => '1',
  44. override_cfg => \$cfg,
  45. search_path => \$script_dir,
  46. );
  47. if (\$version) {
  48. print \$pisg->{cfg}->{version} . "\n";
  49. } else {
  50. \$pisg->run();
  51. }
  52. END
  53. if ($@) {
  54. print STDERR "Could not load pisg! Reason:\n$@\n";
  55. return undef;
  56. }
  57. }
  58. sub get_cmdline_options
  59. {
  60. my $script_dir = shift;
  61. my %cfg = (
  62. modules_dir => "$script_dir/modules/", # Module search path
  63. );
  64. # Commandline options
  65. my ($tmp, $help, $silent, $option, @cfg);
  66. my $usage = <<END_USAGE;
  67. Usage: pisg [-ch channel] [-l logfile] [-o outputfile] [-ma maintainer]
  68. [-f format] [-n network] [-d logdir] [-mo moduledir] [-s] [-v] [-h]
  69. -ch --channel=xxx : Set channel name
  70. -l --logfile=xxx : Log file to parse
  71. -o --outfile=xxx : Name of HTML file to create
  72. -ma --maintainer=xxx : Channel/statistics maintainer
  73. -f --format=xxx : Logfile format [see FORMATS file]
  74. -n --network=xxx : IRC network for the channel
  75. -d --dir=xxx : Analyze all files in this dir. Ignores logfile
  76. -p --prefix=xxx : Analyse only files prefixed by xxx in dir
  77. Only works with --dir
  78. -cf --cfg opt=value : Specify configuration options, eg. -cf ShowWpl=1
  79. -co --configfile=xxx : Configuration file
  80. -mo --moduledir=xxx : Directory containing pisg modules
  81. -s --silent : Suppress output (except error messages)
  82. -v --version : Show version
  83. -h --help : Output this message and exit.
  84. Example:
  85. \$ pisg -n IRCnet -f xchat -o suid.html -ch \\#channel -l logfile.log
  86. All options may also be defined by editing the configuration file and
  87. calling pisg without arguments.
  88. END_USAGE
  89. if (GetOptions('channel=s' => \$cfg{channel},
  90. 'logfile=s' => \$cfg{logfile},
  91. 'format=s' => \$cfg{format},
  92. 'network=s' => \$cfg{network},
  93. 'maintainer=s' => \$cfg{maintainer},
  94. 'outfile=s' => \$cfg{outputfile},
  95. 'dir=s' => \$cfg{logdir},
  96. 'prefix=s' => \$cfg{prefix},
  97. 'moduledir=s' => \$cfg{moduledir},
  98. 'configfile=s' => \$cfg{configfile},
  99. 'ignorefile=s' => \$tmp,
  100. 'aliasfile=s' => \$tmp,
  101. 'silent' => \$silent,
  102. 'version' => \$cfg{version},
  103. 'cfg=s' => \@cfg,
  104. 'help|?' => \$help
  105. ) == 0 or $help) {
  106. die($usage);
  107. }
  108. if ($tmp) {
  109. die("The aliasfile and ignorefile has been obsoleted by the new
  110. pisg.cfg, please use that instead [see pisg.cfg]\n");
  111. }
  112. if ($silent) { $cfg{silent} = 1; }
  113. if (@cfg) {
  114. foreach (@cfg) {
  115. if (/(.*)=(.*)/) {
  116. $cfg{$1} = $2;
  117. } else {
  118. print STDERR "Warning: Couldn't parse -cfg option\n";
  119. }
  120. }
  121. }
  122. return \%cfg;
  123. }
  124. main(); # Run the script