#!/usr/bin/perl -w # ekglog.pl # # log formatter for EKG # # version 0.1 (18.06.2003) # by Michal Miszewski # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. use Getopt::Long; $ver = 0.1; $mynick = "Ja"; sub fmttime { my $time = ""; @tm = gmtime shift; $tm[3] = "0".$tm[3] if length($tm[3]) == 1; $tm[4]++; $tm[4] = "0".$tm[4] if length($tm[4]) == 1; $time = "$tm[3]-$tm[4]-".(1900 + $tm[5]) if (!$nodate); $time = $time." " if (!($nodate) && !($notime)); $time = $time."$tm[2]:$tm[1]" if (!$notime); return $time; } sub htmlize { my $ln = shift; $ln =~ s/\>/>/g; $ln =~ s/\$1\<\/a\>/gi; $ln =~ s/[^\\]\\n/
/g; $ln =~ s/[^\\]\\r//g; $ln =~ s/\\([^\\])/$1/g; $ln =~ s/\\\\/\\/g; return $ln; } sub txtize { my $ln = shift; $ln =~ s/[^\\]\\n/\n/g; $ln =~ s/[^\\]\\r//g; $ln =~ s/\\([^\\])/$1/g; $ln =~ s/\\\\/\\/g; return $ln; } $notime = 0; $nodate = 0; GetOptions('text|x' => \$ptext, 'nohdrs|n' => \$nohdrs, 'mynum|m=i' => \$mynum, 'mynick|y=s' => \$mynick, 'nocss|c' => \$nocss, 'help|h' => \$help, 'nodate|d' => \$nodate, 'notime|t' => \$notime); if ($help) { print "ekglog version $ver by Michał Miszewski \n"; print "Użycie: $0 [-hxndtcmy] [pliki...]\n"; print " -h, --help\t\twyświetl ten tekst pomocy\n"; print " -x, --text\t\tczysty tekst na wyjściu (bez HTML)\n"; print " -n, --nohdrs\t\tpomiń nagłówki HTML\n"; print " -d, --nodate\t\tpomiń datowniki\n"; print " -t, --notime\t\tpomiń znaczniki czasu\n"; print " -c, --nocss\t\tpomiń styl CSS w kodzie HTML\n"; print " -m, --mynum=NUM\ttwój numer GG\n"; print " -y, --mynick=NUM\ttwój nick (domyślnie: $mynick)\n"; exit 1; } if (!$nohdrs and !$ptext) { print ' log '; print ' ' if !$nocss; print '
'; } while () { chomp; $text = ''; if (m/^(chat|msg)(\w+)/) { $sent = ''; if ("$2" eq 'recv') { @ln = split /,/, $_, 6; $sent = fmttime($ln[4]); $sent = " ($sent)" if ($sent ne ""); if (m/\"/) { $text = substr $ln[5], 1, -1 } else { $text = $ln[5] }; $nick = $ln[2]; $num = "/".$ln[1]; } if ("$2" eq 'send') { @ln = split /,/, $_, 5; if (m/\"/) { $text = substr $ln[4], 1, -1 } else { $text = $ln[4] }; $nick = $mynick; if ($mynum) { $num = "/".$mynum } else { $num = "" } } $time = (fmttime($ln[3]).$sent); $time = $time." " if ($time ne ""); if ($ptext) { $text = txtize $text; print "$time$nick$num\n $text\n\n" } else { $text = htmlize $text; print "
$time$nick$num
\n
$text
\n"; }; } if (m/^status/) { @ln = split /,/, $_, 7; if (m/\"/) { $text = substr $ln[6], 1, -1 } else { $text = $ln[6] if defined($ln[6]); }; $time = fmttime $ln[4]; $time = $time." " if ($time ne ""); my %state = ( avail => "dostępny", busy => "zajęty", invisible => "niewidoczny", notavail => "niedostępny" ); if ($text eq "") { $text = "." } else { if ($ptext) { $text = txtize $text; $text = ": ".$text } else { $text = htmlize $text; $text = ": ".$text.""; } } if ($ptext) { print "$time$ln[2]/$ln[1] jest $state{$ln[5]}$text\n\n" } else { print "
$time$ln[2]/$ln[1] jest $state{$ln[5]}$text
\n" } } } print "
\n\n\n\n" if (!$nohdrs and !$ptext);