summaryrefslogtreecommitdiff
path: root/bin/indent_macros.perl
blob: 3429d746dbad5fe46db40b04b01b712c239b2012 (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
53
54
55
56
57
58
59
eval '(exit $?0)' && eval 'exec perl -i -S $0 ${1+"$@"}'
    & eval 'exec perl -i -S $0 $argv:q'
    if 0;

# $Id$

# This perl script re-arrange the macro indentation so it's easier to
# see the layering relationship.

$lineno = 0;
$indent = 0;

sub inc_indent
{
    $indent += 2;
}

sub dec_indent
{
    $indent -= 2;
}

sub get_indent
{
    $retv = 0;
    print STDERR "$0 (", $lineno, "): Unbalanced macro pairs\n" if ($indent < 0);
    $retv = $indent - 1 if ($indent > 0);
    $retv;
}

while (<>) {
    $lineno++;
    if (/^[ \t]*\#[ \t]*((if|el|en|).*)/)
    {
        $cont = $1;
        $temp = $2;
        if ($temp =~ /if/) {
            print "#", " " x &get_indent (), $cont,"\n";
            inc_indent ();
        }
        elsif ($temp =~ /el/) {
            dec_indent ();
            print "#", " " x &get_indent (), $cont,"\n";
            inc_indent ();
        }
        elsif ($temp =~ /en/) {
            dec_indent ();
            print "#", " " x &get_indent (), $cont,"\n";
        }
        else {
            print "#", " " x &get_indent (), $cont,"\n";
        }
    }
    else {
        print $_;
    }
}

die ("$0 (EOF): Unbalanced macro pairs\n") if ($indent != 0);