summaryrefslogtreecommitdiff
path: root/helpers/make_export.pl
blob: 8541bca2da318b5c017e552e9afa07da4b8f6865 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl

require "getopts.pl";

&Getopts( 'o:' );

if ($#ARGV < 0) {
    die "Usage: -o <output_file> <input_files>";
}

if (!defined $opt_o) {
    $opt_o = "apr.exports";
}

open (OUTFILE, ">$opt_o") || die "Can't open $opt_o $!\n";

while ($srcfile = shift(@ARGV)) {
    my $line;
    my $count;
    my $found;

    open (FILE, $srcfile) || die "Can't open $srcfile\n";
#    print STDERR "Reading \"$srcfile\"\n";

    $count = 0;
    $found = 0;
    $line = "";
#    print OUTFILE "____$srcfile\n";
    while (<FILE>) {
        chomp;
    
        s/^\s*//;
        
        if (/\#if(def)? (APR_.*)/) {
            $count++;
            $found++;
            $macro = $2;
            $line .= "$macro\n";
            next;
        }
        elsif (/^(APR_DECLARE[^\(]*\()?[a-z_]+\)?\s+([A-Za-z0-9_]+)\(/) {
            # We only want to increase this if we are in the middle of a 
            # #if ... #endif block.
            if ($found) {
                $found++;
            }
            for (my $i=0; $i < $count; $i++) {
                $line .= "\t";
            }
            $line .= "$2\n";
            next;
        }
        elsif (/\#endif/) {
            if ($count > 0) {
                $count--;
                $line .= "\/$macro\n";
            }
            if ($found == $count + 1) {
                $found--;
                $line = "";
                next;
            }
            elsif ($found > $count + 1) {
                $found = 0;
            }
        }
        if ($line && !$found) {
            print OUTFILE "$line";
            $line = "";
        }
    }
}