Revision 6e5fe91459b67cc8cb42e5cf7756c1546f9dc9dd authored by Christophe Maudoux on 18 January 2019, 22:33:34 UTC, committed by Christophe Maudoux on 18 January 2019, 22:33:47 UTC
1 parent 72705b1
Raw File
transform-templates
#!/usr/bin/perl

use strict;

our $cond     = 1;
our $condDone = 0;
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>) {
    if (m#//if:(\w+)#) {
        $cond     = $args{$1};
        $condDone = $cond;
    }
    elsif (m#//elsif:(\w+)#) {
        if ($condDone) {
            $cond = 0;
        }
        else {
            $cond = $args{$1};
            $condDone ||= $cond;
        }
    }
    elsif (m#//else#) {
        $cond = !$condDone;
    }
    elsif (m#//endif#) {
        $cond = 1;
    }
    else {
        print if ($cond);
    }
}
back to top