| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strict; |
| 4 | use warnings; |
| 5 | |
| 6 | my $indent_level = -1; |
| 7 | |
| 8 | sub emit { |
| 9 | my $indent = $indent_level <= 0 ? "" : " " x $indent_level; |
| 10 | printf "#%s%s", $indent, $_; |
| 11 | } |
| 12 | |
| 13 | while (<>) { |
| 14 | unless (s/^\s*#\s*//) { |
| 15 | print; |
| 16 | next; |
| 17 | } |
| 18 | |
| 19 | if (/^if/) { |
| 20 | emit($_); |
| 21 | $indent_level++; |
| 22 | } elsif (/^el/) { |
| 23 | $indent_level--; |
| 24 | emit($_); |
| 25 | $indent_level++; |
| 26 | } elsif (/^endif/) { |
| 27 | $indent_level--; |
| 28 | emit($_); |
| 29 | } else { |
| 30 | emit($_); |
| 31 | } |
| 32 | } |