summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2009-01-01 20:51:39 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2009-01-01 20:51:43 +0100
commit4e623379ca2ba5c502395234ab6ab9a8950eb256 (patch)
tree78b8bd3cf18793a7447f2f48b37cb6d96e6f9c36
parentca1798f88fb40e3cfd25177626c8fec4707e9cde (diff)
tibtoa: Added matrix (.8Xm) support
-rwxr-xr-xbin/tibtoa90
1 files changed, 58 insertions, 32 deletions
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;