From 4e623379ca2ba5c502395234ab6ab9a8950eb256 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 1 Jan 2009 20:51:39 +0100 Subject: tibtoa: Added matrix (.8Xm) support --- bin/tibtoa | 90 ++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 32 deletions(-) (limited to 'bin') diff --git a/bin/tibtoa b/bin/tibtoa index 7511756..18fb865 100755 --- a/bin/tibtoa +++ b/bin/tibtoa @@ -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; -- cgit v1.2.3