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+)/) {
|
200
|
37 $tmp = $1 . "\n";
|
|
38 if (/{/) {
|
|
39 $tmp = "{" . $';
|
201
|
40 $tmp =~ s/;$//;
|
200
|
41 }
|
|
42 $var{$name} .= $tmp;
|
195
|
43 $tmp = $`;
|
|
44 $tmp =~ s/^\s*//;
|
|
45 $type{$name} .= $tmp . "\n";
|
|
46 }
|
194
|
47 if (/^}/) {
|
|
48 $inTypedef = 0;
|
|
49 }
|
|
50 }
|
|
51 }
|
|
52
|
|
53 sub generateDataGear {
|
|
54 open my $fd,">","d/extern.h" or die("can't open d/extern.h $!");
|
|
55 for my $name ( sort keys %dataGear ) {
|
|
56 print $fd $dataGear{$name},"\n";
|
|
57 }
|
|
58 print $fd "\n";
|
195
|
59
|
|
60 open my $fd,">","d/stub.h" or die("can't open d/stub.h $!");
|
|
61 for my $name ( sort keys %dataGear ) {
|
|
62 print $fd $var{$name},"\n";
|
|
63 }
|
|
64 for my $name ( sort keys %dataGear ) {
|
|
65 print $fd $type{$name},"\n";
|
|
66 }
|
|
67 print $fd "\n";
|
194
|
68 }
|
|
69
|
|
70 # end
|