Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
my $sLogFile = $ARGV[0];
my $iRefreshRate = $ARGV[1];
my $bFilterChat = $ARGV[2];
my $bFilterOther = $ARGV[3];
print "Log file: $sLogFile\n";
print "Refresh Rate: $iRefreshRate\n";
print "Filter Chat: $bFilterChat\t(0 = Don't filter; anything else = filter)\n";
print "Filter Other: $bFilterOther\t(same as above)\n";
my @myFile;
my $curOffset = 0;
my $i;
my $lastMyFileSize = 0;
my $newMyFileSize = 0;
for (;;) {
$newMyFileSize = 0;
open FILEIN, $sLogFile || die "Can't open file \"$sLogFile\": $!";
foreach (<FILEIN>) {
@myFile[$newMyFileSize] = $_;
$newMyFileSize++;
}
close FILEIN;
# Hurm... someone call the cops... taspring is a pice of crap, written in spagetti... i meen... The devil's C++
# ie: log file was wrighten too, instead of appended
if ($lastMyFileSize > $newMyFileSize) {
print "Error, ta spring gayness has maxed out!\n";
print "Please wait while a real programmer fixes the issue ~.~\n";
# Reset offset to redraw entire log
$curOffset = 0;
}
$lastMyFileSize = $newMyFileSize;
# This (along with $curOffset) only prints new lines
for ($i=$curOffset; $i < $newMyFileSize; $i++) {
my $curLine = @myFile[$i];
# If we found a blank line, it's probably because of syncronization
# ie: log file is being written to, but has not finished writing the line
if ($curLine =~ /^\s+$/) {
# Be carful now... Don't hit a never ending loop, or miss a line...
#
# Make sure we're on the last line in the file...
if ($i != (@myFile - 1)) {
# Ok, not the last line, just a blank line... do jack
} else {
# Hokay... our offset must not change, to cause the line to be re-read
$i = $curOffset;
}
} else {
# Print other?
if ($bFilterOther == 0) {
if ($curLine =~ /^[^<[]/) {
print $curLine;
}
}
# Print chat?
if ($bFilterChat == 0) {
if ($curLine =~ /^(\<|\[)/) {
print $curLine;
}
}
}
}
# If we grow $i, we need to grow the offset; otherwise we just get old offset :P
$curOffset = $i;
sleep($iRefreshRate);
}
Code: Select all
start test.pl infolog.txt 1 1 0
start test.pl infolog.txt 1 0 1
Author DeadRAM
Distributed Under the NFB Licence:
"Don't Do Stupid Stuff It's Public"