#! /usr/bin/perl -w # # Copyright (c) 2000-2001 Hugo Haas # # $Id: vil 1049 2001-01-31 21:53:03Z hugo $ use strict; use Text::Wrap; my $grep; my $dest; my @files; &parse_arguments(); while (@files) { $_ = shift(@files); if (m/\.bz2$/) { open(FILE, "bunzip2 -c $_ |") || next; } elsif (m/\.gz$/) { open(FILE, "gunzip -c $_ |") || next; } else { open(FILE, $_) || next; } if ($grep) { while() { next if (! m/$grep/); &show_line($_); } } else { while() { &show_line($_); } } } sub show_line() { $_ = $_[0]; chop; my $offset = 13; # From Gerald my ($dow,$month,$day,$hh,$mm,$ss,$yyyy,$nick,$who,$command,$to,$text) = (/^\[(\w+) (\w+) ([ \d]+) (\d+):(\d+):(\d+) (\d+)\] ([\w-]+)\!(\S+) ([\w]+) (\S+) ?:?(.*)/); if (!defined($dow)) { # Numerics return; } my $rcp = ''; if ($dest) { return if ($dest ne $to); } else { $rcp = sprintf("%9s ", $to); } if ($command eq 'PRIVMSG') { my $flag = ''; if ($text =~ /^/) { if ($text =~ /^ACTION/) { $text =~ s/^ACTION ?//; $text =~ s/$//; $flag = '*'; } else { return; } } if ($text eq '') { $text = ' '; } my $output = sprintf('%s/%s %2s:%2s %s%s%9s%s ', $month, $day, $hh, $mm, $rcp, $flag, $nick, ($flag eq '*' ? '' : ':')); print wrap($output, ' ' x $offset, $text), "\n"; return; } if ($command eq 'TOPIC') { my $output = sprintf('%s/%s %2s:%2s %s %9s ', $month, $day, $hh, $mm, $rcp, $nick); print wrap($output, ' ' x $offset, 'TOPIC: '.$text), "\n"; return; } if ($command eq 'JOIN') { $to =~ s/^://; my $output = sprintf('%s/%s %2s:%2s %s %9s ', $month, $day, $hh, $mm, $rcp, $nick); print wrap($output, ' ' x $offset, 'JOINED'), "\n"; return; } if ($command eq 'PART') { my $output = sprintf('%s/%s %2s:%2s %s %9s ', $month, $day, $hh, $mm, $rcp, $nick); print wrap($output, ' ' x $offset, 'LEFT: '.$text), "\n"; return; } if ($command eq 'MODE') { my $output = sprintf('%s/%s %2s:%2s %s %9s ', $month, $day, $hh, $mm, $rcp, $nick); print wrap($output, ' ' x $offset, 'MODE: '.$text), "\n"; return; } } sub parse_arguments() { while (@ARGV) { $_ = shift(@ARGV); if (/^-(d|-dest)$/) { $dest = shift(@ARGV); } elsif (/^-(g|-grep)$/) { $grep = shift(@ARGV); } else { push(@files, $_); } } }