aboutsummaryrefslogtreecommitdiff
path: root/harness/tools/genintf.pl
blob: d446d835a9b2c1f5895822acd358808e32652edd (plain) (blame)
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
#!/usr/bin/env perl

$comment="";

print "#ifndef _PLUG_INTF\n";
print "#define _PLUG_INTF\n";
print "\n#include <stdint.h>\n";
print "\ntypedef void* opqst_t;\n";

while (<STDIN>) {
  if (/^\s*\/\*/) {
    $_ =~ s/^\s*//;
    $comment="$_";
    next;
  }

  if (/^\s*\*/) {
    $_ =~ s/^\s*/ /;
    $comment="$comment$_";
    next;
  }

  if (/^\s*EXPORT/) {
    my $line = "$_";
    while (not ($line =~ /;$/)) {
      my $nextline = <STDIN>;
      last unless defined $nextline;

      $line="$line$nextline";
    }

    if ($line =~ /^\s*EXPORT_INCLUDE\((.*)\)/s) {
      print "#include $1\n";
    } elsif ($line =~ /^\s*EXPORT\(\s*((?:\w|\s*\*\s*)+)\s*\(\*(\w+)\)\s*\((.*)\)\);/s) {
      print "$comment";
      print "$1 $2($3);\n\n";
      $comment="";
    } elsif ($line =~ /^\s*EXPORT\((.*)\);/s) {
      print "$1\n";
    }
  }
}
print "#endif /* _PLUG_INTF */\n";