diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2009-01-01 20:51:39 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2009-01-01 20:51:43 +0100 |
commit | 4e623379ca2ba5c502395234ab6ab9a8950eb256 (patch) | |
tree | 78b8bd3cf18793a7447f2f48b37cb6d96e6f9c36 /bin | |
parent | ca1798f88fb40e3cfd25177626c8fec4707e9cde (diff) |
tibtoa: Added matrix (.8Xm) support
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/tibtoa | 90 |
1 files changed, 58 insertions, 32 deletions
@@ -650,8 +650,8 @@ sub header_size($) { $size->{full} = ord(substr($header, 70, 1)) + 255 * ord(substr($header, 71, 1)); given(header_type($header)) { when('matrix') { - $size->{rows} = ord(substr($header, 72, 1)); - $size->{cols} = ord(substr($header, 73, 1)); + $size->{cols} = ord(substr($header, 72, 1)); + $size->{rows} = ord(substr($header, 73, 1)); } when('program') { $size->{source} = ord(substr($header, 72, 1)) + 255 * ord(substr($header, 73, 1)); @@ -695,37 +695,63 @@ if ($opts{h}) { # And now, the actual file content -while($offset < $length) { - $char = ord(substr($program, $offset++, 1)); - if (exists($all{$char})) { - $out = $all{$char}; - } elsif (exists($special->{$char})) { - $char2 = ord(substr($program, $offset++, 1)); - $out = $special->{$char}->{$char2}; - } else { - printf STDERR ( - "Unknown byte 0x%02x at offset %d\n", - $char, - $offset - 1, - ); - $out = chr($char); - } - if ($opts{i}) { - if ($out =~ /Then|While|Repeat|For/) { - $indent++; - } elsif ($out =~ /Else/) { - $rindent--; - } elsif ($out =~ /End/) { - $indent--; - $rindent--; +if (header_type($header) eq 'program') { + while($offset < $length) { + $char = ord(substr($program, $offset++, 1)); + if (exists($all{$char})) { + $out = $all{$char}; + } elsif (exists($special->{$char})) { + $char2 = ord(substr($program, $offset++, 1)); + $out = $special->{$char}->{$char2}; + } else { + printf STDERR ( + "Unknown byte 0x%02x at offset %d\n", + $char, + $offset - 1, + ); + $out = chr($char); + } + if ($opts{i}) { + if ($out =~ /Then|While|Repeat|For/) { + $indent++; + } elsif ($out =~ /Else/) { + $rindent--; + } elsif ($out =~ /End/) { + $indent--; + $rindent--; + } + } + $cache .= $out; + if ($out eq "\n") { + print "\t" x $rindent; + $rindent = $indent; + print $cache; + $cache = ''; } } - $cache .= $out; - if ($out eq "\n") { - print "\t" x $rindent; - $rindent = $indent; - print $cache; - $cache = ''; + print $cache; +} elsif (header_type($header) eq 'matrix') { + my ($step, $exp, $digit); + my $i = 0; + while ($offset+9 <= $length) { + $i++; + $digit = ''; + $exp = ord(substr($program, ++$offset, 1)) - 128; + for(1 .. 7) { + $char = ord(substr($program, ++$offset, 1)); + $digit .= $char >> 4; + if ($_ == 1) { + $digit .= '.'; + } + $digit .= $char & 0x0f; + } + $offset++; + printf('%-8s', $digit * (10 ** $exp)); + if ($i == header_size($header)->{cols}) { + print "\n"; + $i = 0; + } else { + print ' | '; + } } } -print $cache; |