#!/usr/bin/perl -w use strict; @ARGV = grep { !/^\s*\||\|\s*$/ } @ARGV; # Don't allow pipes. use Getopt::Std; my %opt; getopts('t', \%opt); my $TIMESTAMPS = $opt{ t }; die "Usage: $0 [-t] file ...\n -t Add timestamps.\n" unless @ARGV; require Text::Wrap; while ( my $line = <> ) { $line .= $_ until ($_ = <>) =~ /^\s*\];/; # Append lines until we find end. $line .= $_; # Append that last line. $line =~ s/^[^[]*//; # Prep for eval'ing. my $aref = eval $line; die $@ if $@; pretty_print_message($_) for (@$aref); } sub pretty_print_message { my $msg = shift; my $txt = $msg->{ text }; my $out = $TIMESTAMPS ? "[$msg->{ time }] " : ''; $txt =~ s/&(lt|gt|amp);/${{lt => '<', gt => '>', amp => '&'}}{$1}/g; unless ( $txt =~ s!^/me !! ) { $out .= "<$msg->{ author }> "; } else { $out .= "* $msg->{ author } "; } my $indent = length $out; $out .= $txt; print Text::Wrap::wrap('', ' ' x $indent, $out), "\n"; }