diff options
-rwxr-xr-x | bin/tibtoa | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -1,5 +1,5 @@ #!/usr/bin/env perl -## Copyright (C) 2008 by Daniel Friesel <derf@derf.homelinux.org> +## Copyright (C) 2008, 2009 by Daniel Friesel <derf@derf.homelinux.org> ## License: WTFPL <http://sam.zoy.org/wtfpl> use strict; use feature 'switch'; @@ -12,8 +12,9 @@ my ($char, $char2); my $out; my $cache; my $hex; -my ($indent, $rindent); +my ($indent, $rindent) = (0,0); my %opts; +my ($program, $length, $offset); my %all = ( 0x01 => '►DMS', 0x02 => '►Dec', @@ -610,23 +611,31 @@ my $special = { 0x17 => 'Manual-Fit', }, }; +local $/; getopts('i', \%opts); open(PRGM, '<', shift) or die; +binmode(PRGM); # Remove header added by tilp2 seek(PRGM, 74, 0); -$indent = 0; -while(read(PRGM, $char, 1)) { - $char = ord($char); +$program = <PRGM>; +close(PRGM); + +# The last two bytes don't contain program code +substr($program, -2, 2, ''); +$length = length($program); +$offset = 0; + +while($offset <= $length) { + $char = ord(substr($program, $offset++, 1)); if (exists($all{$char})) { $out = $all{$char}; } elsif (exists($special->{$char})) { - read(PRGM, $char2, 1); - $char2 = ord($char2); + $char2 = ord(substr($program, $offset++, 1)); $out = $special->{$char}->{$char2}; } else { - warn(sprintf('Unknown byte: %2x', $char)); + warn(sprintf('Unknown byte 0x%02x', $char)); $out = chr($char); } if ($opts{i}) { |