Parenomatic!

James Wondrasek (jimmy@nospam.socs.uts.EDU.AU)
Thu, 28 Apr 1994 11:29:37 +1000 (EST)

Here is *a* solution to my request yesterday. It's in perl. I did it.
There must be an easier or shorter way of doing this.

Now I can get back to the ToCS assignment...
-----

#!/usr/local/bin/perl
$/="";
$indent = 1;
$spaces="";

$_ = <>;

# all this is to hide "(" and ")" and then put them back after we set the
# points where we are going to split
s/\n/ /g;
s/\"\(\"/\[/g;
s/\"\)\"/\]/g;
s/\(/\&\(/g;
s/\)/\&\)/g;
s/\[/\"\(\"/g;
s/\]/\"\)\"/g;
@nospam.bits = split(/\&/);

foreach $line (@nospam.bits) {
if ( $line =~ /^\(/ ) {
print "$spaces$line\n";
$spaces = " " x $indent++;
}
elsif ( $line =~ /^\)/ ) {
$spaces = " " x (--$indent - 1);
print "$spaces$line\n";
}
else {
print "$spaces$line\n";
}
}