194
|
1 #!/usr/bin/perl
|
|
2
|
|
3 # interface.cbc
|
|
4 # typedef struct Worker {
|
|
5 # int id;
|
|
6 # struct Context* contexts;
|
|
7 # enum Code execute;
|
|
8 # enum Code taskSend;
|
|
9 # enum Code taskRecive;
|
|
10 # enum Code shutdown;
|
|
11 # struct Queue* tasks;
|
|
12 # } Worker;
|
|
13
|
|
14 system "rm -rf d";
|
|
15 system "mkdir d";
|
|
16
|
|
17 while (<*.cbc>) {
|
|
18 &getDataGear($_);
|
|
19 }
|
|
20
|
|
21 &generateDataGear();
|
|
22
|
|
23 sub getDataGear {
|
|
24 my ($filename) = @_;
|
|
25 open my $fd,"<",$filename or die("can't open $filename $!");
|
|
26 while (<$fd>) {
|
|
27 if (! $inTypedef) {
|
|
28 if (/^typedef struct (\w+) {/) {
|
|
29 $inTypedef = 1;
|
|
30 $name = $1;
|
|
31 $dataGear{$name} = $_;
|
|
32 }
|
|
33 next;
|
|
34 }
|
|
35 $dataGear{$name} .= $_;
|
195
|
36 if (/(\w+);$/ and !/^} (\w+)/) {
|
|
37 $var{$name} .= $1 . "\n";
|
|
38 $tmp = $`;
|
|
39 $tmp =~ s/^\s*//;
|
|
40 $type{$name} .= $tmp . "\n";
|
|
41 }
|
194
|
42 if (/^}/) {
|
|
43 $inTypedef = 0;
|
|
44 }
|
|
45 }
|
|
46 }
|
|
47
|
|
48 sub generateDataGear {
|
|
49 open my $fd,">","d/extern.h" or die("can't open d/extern.h $!");
|
|
50 for my $name ( sort keys %dataGear ) {
|
|
51 print $fd $dataGear{$name},"\n";
|
|
52 }
|
|
53 print $fd "\n";
|
195
|
54
|
|
55 open my $fd,">","d/stub.h" or die("can't open d/stub.h $!");
|
|
56 for my $name ( sort keys %dataGear ) {
|
|
57 print $fd $var{$name},"\n";
|
|
58 }
|
|
59 for my $name ( sort keys %dataGear ) {
|
|
60 print $fd $type{$name},"\n";
|
|
61 }
|
|
62 print $fd "\n";
|
194
|
63 }
|
|
64
|
|
65 # end
|