File: macroseparator.pl

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (76 lines) | stat: -rwxr-xr-x 1,070 bytes parent folder | download | duplicates (20)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl

$target = $ARGV[0];
$file = $ARGV[1];
$copy = 1;
$recognized = 0;
$closed = 1;
$printed = 0;
$wslines = 0;


open(FILE, "$file");

sub wslines()
{
    return if !$printed;

    while ($wslines)
    {
        print "\n";
        $wslines--;
    }
}

while ($line = <FILE>)
{
    chomp $line;

    if ($line =~ /^<.*$target.*>\s*$/c)
    {
        $copy = 1;
        $closed = 0;
        $recognized = 1;
    }
    elsif ($line =~ /^<>\s*$/c)
    {
        $copy = 1;
        $closed = 1;
        $recognized = 0;
    }
    elsif ($line =~ /^<else>\s*$/c)
    {
        $closed = 0;
        $copy = !$recognized;
    }
    elsif ($line =~ /^<[^>]+>\s*$/c)
    {
        $closed = 0;
        $copy = 0;
    }
    elsif ($copy)
    {
        if ( $line =~ /^\s*$/ )
        {
            if ($printed)
            {            
                $wslines++;
            }
            next;
        }

        wslines();
        print "$line\n";
        $printed = 1;
    }
}

print "\n";
    
if (!$closed)
{
    warn "Maybe no close tag <> in $file\n";
}