3 # irclog2html.pl Version 2.1 - 27th July, 2001
4 # Copyright (C) 2000, Jeffrey W. Waugh
7 # Jeff Waugh <jdub@perkypants.org>
10 # Rick Welykochy <rick@praxis.com.au>
11 # Alexander Else <aelse@uu.net>
13 # Released under the terms of the GNU GPL
14 # http://www.gnu.org/copyleft/gpl.html
16 # Usage: irclog2html filename
18 # irclog2html will write out a colourised irc log, appending a .html
19 # extension to the output file.
22 ####################################################################################
26 #$^W = 1; #RW# turn on warnings
29 my $RELEASE = "27th July, 2001";
33 my $a = 0.95; # tune these for the starting and ending concentrations of R,G,B
35 my $rgb = [ [$a,$b,$b], [$b,$a,$b], [$b,$b,$a], [$a,$a,$b], [$a,$b,$a], [$b,$a,$a] ];
37 my $rgbmax = 125; # tune these two for the outmost ranges of colour depth
41 ####################################################################################
44 # Comment out the "table" assignment to use the plain version
49 "server" => "#009900",
50 "nickchange" => "#009900",
51 "action" => "#CC00CC",
54 my %prefs_colour_nick = (
56 "cantanker" => "#006600",
57 "chuckd" => "#339999",
61 "simplett" => "Text style with little use of colour",
62 "tt" => "Text style using colours for each nick",
63 "simpletable" => "Table style, without heavy use of colour",
64 "table" => "Default style, using a table with bold colours",
70 ####################################################################################
71 # Utility Functions & Variables
74 my ($nick, $text, $htmlcolour) = @_;
76 if ($STYLE eq "table") {
77 print OUTPUT "<tr><th bgcolor=\"$htmlcolour\"><font color=\"#ffffff\"><tt>$nick</tt></font></th>";
78 print OUTPUT "<td width=\"100%\" bgcolor=\"#eeeeee\"><tt><font color=\"$htmlcolour\">$text<\/font></tt></td></tr>\n";
79 } elsif ($STYLE eq "simpletable") {
80 print OUTPUT "<tr bgcolor=\"#eeeeee\"><th><font color=\"$htmlcolour\"><tt>$nick</tt></font></th>";
81 print OUTPUT "<td width=\"100%\"><tt>$text</tt></td></tr>\n";
82 } elsif ($STYLE eq "simplett") {
83 print OUTPUT "<\;$nick>\; $text<br>\n";
85 print OUTPUT "<font color=\"$htmlcolour\"><\;$nick>\;<\/font> <font color=\"#000000\">$text<\/font><br>\n";
89 sub output_servermsg {
92 if ($STYLE =~ /table/) {
93 print OUTPUT "<tr><td colspan=2><tt>$line</tt></td></tr>\n";
95 print OUTPUT "$line<br>\n";
101 my ($i,$ncolours) = @_;
102 $ncolours = 1 if $ncolours == 0;
105 my $m = $rgbmin + ($rgbmax - $rgbmin) * ($ncolours - $i) / $ncolours;
107 my $r = $rgb->[$n][0] * $m;
108 my $g = $rgb->[$n][1] * $m;
109 my $b = $rgb->[$n][2] * $m;
110 sprintf("#%02x%02x%02x",$r,$g,$b);
113 my $msg_usage = "Usage: irclog2html.pl [OPTION]... [FILE]
114 Colourises and converts IRC logs to HTML format for easy web reading.
116 -s, --style=[STYLE] format log according to specific style. style formats
117 described using irclog2html [-s|--style]
119 --colour-<attribute>=[COLOUR] format output colour scheme. attributes
120 described using irclog2html [--colour]
122 Report bugs to Jeff Waugh <jdub\@perkypants.org>.
125 my $msg_styles = "The following styles are available for use with irclog2html.pl:
128 Text style with little use of colour
131 Text style using colours for each nick
134 Table style, without heavy use of colour
137 Default style, using a table with bold colours
140 my $msg_colours = "The following attributes may be customized using the --colour
143 join, part, action, server, nickchange
147 ################################################################################
163 my %colours = %prefs_colours;
164 my %colour_nick = %prefs_colour_nick;
165 my %styles = %prefs_styles;
168 # Quit if there is no filename specified on the command line #
170 die "Required parameter missing\n\n$msg_usage";
174 # Loop through parameters, bringing filenames into $files #
177 while ($ARGV[$count]) {
179 if ($ARGV[$count] =~ /-s|--style.*/) {
180 $STYLE = $ARGV[$count];
182 if ($STYLE =~ /--style=.*/) {
183 $STYLE =~ s/--style=(.*)/$1/;
187 $STYLE = $ARGV[$count];
194 } elsif (!defined($styles{$STYLE})) {
195 die "irclog2html.pl: invalid style: `$STYLE'\n\n$msg_styles";
198 } elsif ($ARGV[$count] =~ /--colou?r.*/) {
199 my $colour_pref = $ARGV[$count];
200 my $colour = $colour_pref;
202 if ($colour_pref =~ /--colou?r$/) {
207 $colour_pref =~ s/--colou?r-(.*)?=.*/$1/;
208 $colour =~ s/--colou?r-.*?=(.*)/$1/;
210 $colours{$colour_pref} = $colour;
214 $inputfile = $ARGV[$count];
219 # Open input and output files #
221 # no file to open, print appropriate usage information
224 } elsif (!open(INPUT, $inputfile)) {
225 # not a vaild file to open, spew error and usage information
226 die "irclog2html.pl: cannot open $inputfile for reading\n\n$msg_usage";
228 if (!open(OUTPUT, ">$inputfile.html")) {
229 # can't open file for output, spew error
230 die "irclog2html.pl: cannot open $inputfile.html for writing\n";
235 print OUTPUT qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
238 <title>$inputfile</title>
239 <meta name="generator" content="irclog2html.pl $VERSION by Jeff Waugh">
240 <meta name="version" content="$VERSION - $RELEASE">
241 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
243 <body text="#000000" bgcolor="#ffffff"><tt>
246 if ($STYLE =~ /table/) {
247 print OUTPUT "<table cellspacing=3 cellpadding=2 border=0>\n";
250 while ($line = <INPUT>) {
256 # Replace ampersands, pointies, control characters #
257 $line =~ s/&/&\;/g;
258 $line =~ s/</<\;/g;
259 $line =~ s/>/>\;/g;
260 $line =~ s/[\x00-\x1f]+//g;
262 # Replace possible URLs with links #
263 $line =~ s/((http|https|ftp|gopher|news):\/\/\S*)/<a href="$1">$1<\/a>/g;
266 if ($line =~ /^\[?\d\d:\d\d(:\d\d)?\]? .*$/) {
268 $time =~ s/^\[?(\d\d:\d\d(:\d\d)?)\]? .*$/$1/;
269 $line =~ s/^\[?\d\d:\d\d(:\d\d)?\]? (.*)$/$2/;
273 # Colourise the comments
274 if ($line =~ /^<\;.*?>\;\s.*/) {
276 # Split $nick and $line
278 $nick =~ s/^<\;(.*?)>\;\s.*$/$1/;
280 # $nick =~ tr/[A-Z]/[a-z]/;
281 # <======= move this into another function when getting nick colour
284 $text =~ s/^<\;.*?>\;\s(.*)$/$1/;
285 $text =~ s/ / \; \;/g;
287 $htmlcolour = $colour_nick{$nick};
288 if (!defined($htmlcolour)) {
292 # if we've exceeded our estimate of the number of nicks, double it
293 $NICKMAX *= 2 if $nickcount >= $NICKMAX;
295 $htmlcolour = $colour_nick{$nick} = html_rgb($nickcount, $NICKMAX);
297 output_nicktext($nick, $text, $htmlcolour);
300 # Colourise the /me's #
301 if ($line =~ /^\* .*$/) {
302 $line =~ s/^(\*.*)$/<font color=\"$colours{"action"}\">$1<\/font>/;
305 # Colourise joined/left messages #
306 elsif ($line =~ /^(\*\*\*|-->) .*joined/) {
307 $line =~ s/(^(\*\*\*|-->) .*)/<font color=\"$colours{"join"}\">$1<\/font>/;
309 elsif ($line =~ /^(\*\*\*|<--) .*left|quit/) {
310 $line =~ s/(^(\*\*\*|<--) .*)/<font color=\"$colours{"part"}\">$1<\/font>/;
313 # Process changed nick results, and remember colours accordingly #
314 elsif ($line =~ /^(\*\*\*|---) (.*?) are|is now known as (.*)/) {
319 $nick_old =~ s/^(\*\*\*|---) (.*?) (are|is) now known as .*/$1/;
322 $nick_new =~ s/^(\*\*\*|---) .*? (are|is) now known as (.*)/$2/;
324 $colour_nick{$nick_new} = $colour_nick{$nick_old};
325 $colour_nick{$nick_old} = undef;
327 $line =~ s/^((\*\*\*|---) .*)/<font color=\"$colours{"nickchange"}\">$1<\/font>/
330 elsif ($line =~ /^(\*\*\*|---) /) {
331 $line =~ s/^((\*\*\*|---) .*)$/<font color=\"$colours{"server"}\">$1<\/font>/;
334 output_servermsg($line);
339 if ($STYLE =~ /table/) {
340 print OUTPUT "</table>\n";
344 <br>Generated by irclog2html.pl $VERSION by <a href="mailto:jdub\@NOSPAMperkypants.org">Jeff Waugh</a>
345 - find it at <a href="http://freshmeat.net/projects/irclog2html.pl/">freshmeat.net</a>!
346 </tt></body></html>};