summaryrefslogtreecommitdiff
path: root/bin/clean_dsp.pl
blob: a3ff9be82056d9d067158f5dbb484d610991bdb4 (plain)
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
# $Id$
#   DSP cleaner

$if_depth = 0;
@saved_lines = ();
$dirty = 0;
$in_dependency = 0;

die "Not enough args" if ($#ARGV < 0);

open (FILE, "<$ARGV[0]");

loop: while  (<FILE>)
{
    # Check for dependency information 
    
    if (/^DEP/ || /^NODEP/) {
        $in_dependency = 1;
    }

    if ($in_dependency) {
        $in_dependency = 0 if (!/\\$/);
        goto loop;
    }
        
    # Check for empty !IF blocks

    if (/^\!IF/) {
        ++$if_depth;
    }

    push @saved_lines, $_ 
        if ($if_depth > 0);

    if (/^\!ENDIF/) {
        --$if_depth;
        print @saved_lines 
            if ($if_depth == 0 && $dirty == 1);
        @saved_lines = ();
        $dirty = 0;
    }
    elsif ($if_depth == 0) {
        print;
    }
  
    $dirty = 1
        if ($if_depth > 0 && !/^\!/ && !/^\s+$/);    


}

close (FILE);