diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-17 15:46:11 +0200 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2008-10-17 15:46:11 +0200 |
commit | 35c6eb861ee57c6db3030f3329d6c828324aebf2 (patch) | |
tree | ecd84528b6faee335b93ab4ac7901ec37edb5f2a | |
parent | 449a5245581491f1ef7704bb1ac0e865e9a557e2 (diff) |
bin/tibtoa: Added experimental indentation rules
-rwxr-xr-x | bin/tibtoa | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -6,7 +6,9 @@ use utf8; binmode(STDOUT, ':utf8'); my ($char, $char2); my $out; +my $cache; my $hex; +my ($indent, $rindent); my %all = ( 0x01 => '►DMS', 0x02 => '►Dec', @@ -607,6 +609,7 @@ my $special = { open(PRGM, '<', shift) or die; # Remove header added by tilp2 seek(PRGM, 74, 0); +$indent = 0; while(read(PRGM, $char, 1)) { $char = ord($char); if (exists($all{$char})) { @@ -619,5 +622,20 @@ while(read(PRGM, $char, 1)) { warn(sprintf('Unknown byte: %2x', $char)); $out = chr($char); } - print $out; + 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 = ''; + } } +print $cache; |