summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-01-01 15:19:42 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2009-01-01 15:19:42 +0100
commit347b60b62be557c42e5c0bbc92dbb8561a931178 (patch)
tree11a5d4e99eb622e65b30ceb78ab4c3ecc7107015
parentae1a7367220af13b3fccc2bd79fd0a0f602fd24c (diff)
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
-rwxr-xr-xbin/tibtoa25
1 files changed, 17 insertions, 8 deletions
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 <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}) {