Hi all,
I wrote this little perl script, which may be incomplete, but it did
what I needed, which will reformat a template (*.j) file, moving all the
XDt tags to the left and shifting them out for each level of scope.
ie:
<XDtOuter>
<XDtInner>
<XDtInnerSub1></XDtInnerSub1>
<XDtInnerSub2></XDtInnerSub2>
</XDtInner>
</XDtOuter>
and turns it into:
<XDtOuter>
<XDtInner>
<XDtInnerSub1></XDtInnerSub1>
<XDtInnerSub2></XDtInnerSub2>
</XDtInner>
</XDtOuter>
It leaves alone any line that doesn't start with <XDt and will not
add to the offset lines when the XDt tag opens/closes on the same line.
I'm not very good a perl, so it looks a little weird. But I find it
very usefull when working with poorly formatted templates.
Note: you run it as
btemp < input.j > output.j
(or just)
btemp < input.j
and it will dump to stdout
-David
#!/usr/bin/perl -w
use strict;
my $xdspace=0;
while (<STDIN>){
chomp;
my $orig = $_;
s/^\s*//;
if ( /^\<XDt/ ) {
for ( my $tmp = 0; $tmp < $xdspace; $tmp++ ) {
print " ";
}
print "$_\n";
if ( ! /^\<\/XD/ and ! /^\<XD.*\/\>/ ) {
$xdspace += 2;
}
}
elsif ( /^\<\/XDt/ ) {
$xdspace-=2;
for ( my $tmp = 0; $tmp < $xdspace; $tmp++ ) {
print " ";
}
print "$_\n";
}
else {
print "$orig\n";
}
}