1 |
#! perl |
2 |
|
3 |
$file = join("",<>); |
4 |
$file=~s/[^\000]+\/\* functions \*\///; |
5 |
$file=~s/#endif\s+$//; |
6 |
foreach my $def (split(/\s*;\s*/,$file)) |
7 |
{ |
8 |
$def =~ s/\s+/ /g; |
9 |
my $paren = ($def=~s/\(([^\(\)]*)\)\s*//)?$1:''; |
10 |
my $type = ($def=~s/^([^\000]*\s+\*?)//)?$1:''; |
11 |
$type=~s/^\s+//; |
12 |
$type=~s/\s+$//; |
13 |
push(@list,{def=>$def,type=>$type,paren=>$paren}); |
14 |
} |
15 |
foreach my $s (sort {$a->{def} cmp $b->{def}} @list) |
16 |
{ |
17 |
my $def = $s->{def}; |
18 |
my $type = $s->{type}; |
19 |
my $paren=$s->{paren}; |
20 |
my $params = $paren; |
21 |
$params=~s/[\[\]\*]//g; |
22 |
$params=~s/\s+,/,/g; |
23 |
$params=~s/[^,\s]+\s+//g; |
24 |
next if ($params =~ /\.\.\./); |
25 |
next if ($def eq 'XOpenDisplay'); |
26 |
my $return = $type eq 'void' ? '':'return '; |
27 |
print " |
28 |
typedef $type (proto_$def)($paren); |
29 |
static proto_$def *func_$def = NULL; |
30 |
$type $def($paren) { |
31 |
if (!func_$def) func_$def=(proto_$def *)_loadfunc(\"$def\"); |
32 |
$return(func_$def)($params); |
33 |
} |
34 |
"; |
35 |
|
36 |
} |