transform-templates 657 Bytes
Newer Older
1 2 3 4
#!/usr/bin/perl

use strict;

5 6
our $cond     = 1;
our $condDone = 0;
7 8 9 10 11 12 13
our %args;
for ( my $i = 0 ; $i < @ARGV ; $i += 2 ) {
    $args{ $ARGV[$i] } =
      ( $ARGV[ $i + 1 ] and $ARGV[ $i + 1 ] ne 'no' ) ? 1 : 0;
}

while (<STDIN>) {
14
    if (m#//if:(\w+)#) {
15 16
        $cond     = $args{$1};
        $condDone = $cond;
17
    }
18 19 20 21 22 23 24 25
    elsif (m#//elsif:(\w+)#) {
        if ($condDone) {
            $cond = 0;
        }
        else {
            $cond = $args{$1};
            $condDone ||= $cond;
        }
26 27
    }
    elsif (m#//else#) {
28
        $cond = !$condDone;
29
    }
30 31
    elsif (m#//endif#) {
        $cond = 1;
32 33 34 35 36
    }
    else {
        print if ($cond);
    }
}