summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2008-10-17 15:46:11 +0200
committerDaniel Friesel <derf@derf.homelinux.org>2008-10-17 15:46:11 +0200
commit35c6eb861ee57c6db3030f3329d6c828324aebf2 (patch)
treeecd84528b6faee335b93ab4ac7901ec37edb5f2a
parent449a5245581491f1ef7704bb1ac0e865e9a557e2 (diff)
bin/tibtoa: Added experimental indentation rules
-rwxr-xr-xbin/tibtoa20
1 files changed, 19 insertions, 1 deletions
diff --git a/bin/tibtoa b/bin/tibtoa
index 9b15c1c..35055eb 100755
--- a/bin/tibtoa
+++ b/bin/tibtoa
@@ -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;