Mercurial > hg > batmud > misc
changeset 180:6fbb025265b2 misc
Bugfixes; Added commandline option handling and setting of debugmode and output file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jan 2011 18:38:55 +0000 |
parents | 86f1730c20b8 |
children | 221819ca9f18 |
files | log2npctemplate.pl |
diffstat | 1 files changed, 32 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/log2npctemplate.pl Fri Jan 14 17:28:29 2011 +0000 +++ b/log2npctemplate.pl Fri Jan 14 18:38:55 2011 +0000 @@ -12,6 +12,7 @@ my $opt_ansi = 1; # 1 = strip ANSI, 0 = don't (is faster) my $opt_debug = 0; # 1 = enable debug output my $opt_pkills_crop = 60; +my $opt_outfile; # Define the regular expression to match any outputs of "say" @@ -46,6 +47,32 @@ ); +### Options +while (defined(my $arg = shift)) { + if ($arg eq "-d") { + $opt_debug++; + } + elsif ($arg eq "-o") { + $opt_outfile = shift or die("Output file option -o requires an argument.\n"); + } + else { + die("Invalid option '$arg'. +Usage: $0 [options] < input.log > output.txt + + -o <filename> Output filename. + -d Enable debug mode. + +"); + } +} + +print STDERR "Debug mode enabled, level=".$opt_debug.".\n" if ($opt_debug); + +if (defined($opt_outfile)) { + open(STDOUT, '>', $opt_outfile) or die("Could not open output file '$opt_outfile'.\n"); +} + + ### Globals my %monsters = (); my %aligns = (); @@ -67,7 +94,7 @@ sub setstate($$) { return unless ($_[0] != $state); -# print STDERR "STATE = $_[0], old = $state\n"; + print STDERR "STATE = $_[0], old = $state\n" if ($opt_debug > 1); $state = $_[0]; if ($state < 0) { print STDERR "ERROR($line): $_[1]\n"; @@ -105,7 +132,7 @@ $monsters{$sdesc}{"exp"} = $exp; } } - } elsif ($s =~ /^\[\d\d:\d\d:\d\d\] hp/) { + } elsif ($s =~ /^\[\d\d:\d\d:\d\d\] hp/ || $s =~ /^You laugh out loud\.$/) { # Ignore } elsif ($s =~ /^You see nothing special\.$/o) { setstate(0, $s); @@ -244,7 +271,7 @@ my $qoffs = 1000; my $qline = -1; foreach my $aline (sort { $a <=> $b } keys %{$aligns{$mname}}) { - my $offs = abs($aline - $mline); + my $offs = ($aline - $mline); if ($offs < $qoffs) { $qoffs = $offs; $qline = $aline; @@ -263,7 +290,7 @@ my $qoffs = 1000; my $qline = -1; foreach my $aline (sort { $a <=> $b } keys %{$races{$mname}}) { - my $offs = abs($aline - $mline); + my $offs = ($aline - $mline); if ($offs < $qoffs) { $qoffs = $offs; $qline = $aline; @@ -279,7 +306,7 @@ # Spells my $hasspells = 0; - if (defined($spells{$mname}) && length($mname) > 4) { + if (defined($spells{$mname}) && length($mname) >= 4) { my $maxdist = length($mname) * 150 * length($mname); my $mindist = length($mname) * -5 * length($mname); my %mspells = ();