File: transform-templates

package info (click to toggle)
lemonldap-ng 2.22.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,516 kB
  • sloc: perl: 82,515; javascript: 25,474; xml: 6,473; makefile: 1,327; sh: 492; sql: 159; python: 55; php: 26
file content (36 lines) | stat: -rwxr-xr-x 657 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/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);
    }
}