1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # actually geninterface |
3 | # used to automatically create accessors/mutators and method interfaces |
|
|
4 | # to C++ classes for Perl. |
4 | |
5 | |
5 | my $class = shift; |
6 | my $class = shift; |
6 | my $curclass = ""; |
7 | my $curclass = ""; |
7 | my (@scalar_member, @array_member); |
8 | my (@scalar_member, @array_member); |
|
|
9 | |
|
|
10 | # convert c member name to perl |
|
|
11 | sub c2perl($) { |
|
|
12 | local $_ = shift; |
|
|
13 | |
|
|
14 | s/^([^.]+)\.\1_/$1\_/g; # tcpi.tcpi_xxx => tcpi_xxx |
|
|
15 | |
|
|
16 | $_ |
|
|
17 | } |
8 | |
18 | |
9 | for my $file (@ARGV) { |
19 | for my $file (@ARGV) { |
10 | open my $fh, "<:utf8", $file |
20 | open my $fh, "<:utf8", $file |
11 | or die "$file: $!"; |
21 | or die "$file: $!"; |
12 | |
22 | |
13 | while (<$fh>) { |
23 | while (<$fh>) { |
|
|
24 | next if /^\s*\//; # skip lines starting with / |
14 | if ($curclass eq $class) { |
25 | if ($curclass eq $class) { |
15 | while (/ACC\s*\(R([WO])\s*,\s*([^)\]]+)(?:\[(\S+)\])?\)/g) { |
26 | while (/ACC\s*\(R([WO])\s*,\s*([^)\]]+)(?:\[(\S+)\])?\)/g) { |
16 | if ($3) { |
27 | if ($3) { |
17 | push @array_member, [$1, $2, $3]; |
28 | push @array_member, [$1, $2, $3]; |
18 | } else { |
29 | } else { |
… | |
… | |
57 | print "\tPROTOTYPE: \$;\$\n"; |
68 | print "\tPROTOTYPE: \$;\$\n"; |
58 | |
69 | |
59 | if (@scalar_member > 1) { |
70 | if (@scalar_member > 1) { |
60 | print "\tALIAS:\n"; |
71 | print "\tALIAS:\n"; |
61 | for (1 .. $#scalar_member) { |
72 | for (1 .. $#scalar_member) { |
62 | print "\t\t$scalar_member[$_][1]\t= $_\n"; |
73 | print "\t\t" . (c2perl $scalar_member[$_][1]) . "\t= $_\n"; |
63 | } |
74 | } |
64 | } |
75 | } |
65 | |
76 | |
66 | print "\tCODE:\n"; |
77 | print "\tCODE:\n"; |
67 | |
78 | |
… | |
… | |
94 | print "\tPROTOTYPE: \$;\$\n"; |
105 | print "\tPROTOTYPE: \$;\$\n"; |
95 | |
106 | |
96 | if (@array_member > 1) { |
107 | if (@array_member > 1) { |
97 | print "\tALIAS:\n"; |
108 | print "\tALIAS:\n"; |
98 | for (1 .. $#array_member) { |
109 | for (1 .. $#array_member) { |
99 | print "\t\t$array_member[$_][1]\t= $_\n"; |
110 | print "\t\t" . (c2perl $array_member[$_][1]) . "\t= $_\n"; |
100 | } |
111 | } |
101 | } |
112 | } |
102 | |
113 | |
103 | print "\tCODE:\n"; |
114 | print "\tCODE:\n"; |
104 | |
115 | |