From 347b60b62be557c42e5c0bbc92dbb8561a931178 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 1 Jan 2009 15:19:42 +0100 Subject: tibtoa: Skip last two file bytes (they don't contain data) Also, read the file in one piece instead of read()ing all the time --- bin/tibtoa | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'bin') diff --git a/bin/tibtoa b/bin/tibtoa index 220490a..7ad8833 100755 --- a/bin/tibtoa +++ b/bin/tibtoa @@ -1,5 +1,5 @@ #!/usr/bin/env perl -## Copyright (C) 2008 by Daniel Friesel +## Copyright (C) 2008, 2009 by Daniel Friesel ## License: 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 = ; +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}) { -- cgit v1.2.3