1 ###################################################
2 # create C header files for an IDL structure
3 # Copyright tridge@samba.org 2000
4 # released under the GNU GPL
16 for (my($i)=0; $i < $tab_depth; $i++) {
21 #####################################################################
22 # parse a properties list
23 sub HeaderProperties($)
29 foreach my $d (@{$props}) {
30 if (ref($d) ne "HASH") {
31 $res .= "/* [$d] */ ";
33 foreach my $k (keys %{$d}) {
34 $res .= "/* [$k($d->{$k})] */ ";
40 #####################################################################
41 # parse a structure element
46 (defined $element->{PROPERTIES}) && HeaderProperties($element->{PROPERTIES});
48 HeaderType($element, $element->{TYPE}, "");
50 if ($element->{POINTERS}) {
51 my($n) = $element->{POINTERS};
52 for (my($i)=$n; $i > 0; $i--) {
56 if (defined $element->{ARRAY_LEN} &&
57 !util::is_constant($element->{ARRAY_LEN})) {
58 # conformant arrays are ugly! I choose to implement them with
59 # pointers instead of the [1] method
62 $res .= "$element->{NAME}";
63 if (defined $element->{ARRAY_LEN} && util::is_constant($element->{ARRAY_LEN})) {
64 $res .= "[$element->{ARRAY_LEN}]";
69 #####################################################################
75 $res .= "struct $name {\n";
77 if (defined $struct->{ELEMENTS}) {
78 foreach my $e (@{$struct->{ELEMENTS}}) {
87 #####################################################################
88 # parse a union element
89 sub HeaderUnionElement($)
92 $res .= "/* [case($element->{CASE})] */ ";
93 if ($element->{TYPE} eq "UNION_ELEMENT") {
94 HeaderElement($element->{DATA});
98 #####################################################################
104 (defined $union->{PROPERTIES}) && HeaderProperties($union->{PROPERTIES});
105 $res .= "union $name {\n";
106 foreach my $e (@{$union->{DATA}}) {
107 HeaderUnionElement($e);
112 #####################################################################
119 if (ref($data) eq "HASH") {
120 ($data->{TYPE} eq "STRUCT") &&
121 HeaderStruct($data, $name);
122 ($data->{TYPE} eq "UNION") &&
123 HeaderUnion($data, $name);
126 if ($data =~ "unistr") {
127 $res .= "const char";
128 } elsif ($data =~ "nstring") {
129 $res .= "const char *";
130 } elsif ($data =~ "lstring") {
131 $res .= "const char *";
132 } elsif (util::is_scalar_type($data)) {
134 } elsif (util::has_property($e, "switch_is")) {
135 $res .= "union $data";
137 $res .= "struct $data";
141 #####################################################################
145 my($typedef) = shift;
146 HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME});
150 #####################################################################
152 sub HeaderFunctionInOut($$)
156 foreach my $e (@{$fn->{DATA}}) {
157 if (util::has_property($e, $prop)) {
164 #####################################################################
166 sub HeaderFunction($)
169 $res .= "struct $fn->{NAME} {\n";
172 $res .= "struct {\n";
174 HeaderFunctionInOut($fn, "in");
179 $res .= "struct {\n";
181 HeaderFunctionInOut($fn, "out");
182 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
184 $res .= "$fn->{RETURN_TYPE} result;\n";
188 $res .= "} out;\n\n";
193 #####################################################################
194 # parse the interface definitions
195 sub HeaderInterface($)
197 my($interface) = shift;
198 my($data) = $interface->{DATA};
202 if (defined $if_uuid) {
203 my $name = uc $interface->{NAME};
204 $res .= "#define DCERPC_$name\_UUID \"$if_uuid\"\n";
205 $res .= "#define DCERPC_$name\_VERSION $if_version\n";
206 $res .= "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n\n";
209 foreach my $d (@{$data}) {
210 if ($d->{TYPE} eq "FUNCTION") {
211 $u_name = uc $d->{NAME};
212 $res .= "#define DCERPC_$u_name $count\n";
219 foreach my $d (@{$data}) {
220 ($d->{TYPE} eq "TYPEDEF") &&
222 ($d->{TYPE} eq "FUNCTION") &&
228 #####################################################################
229 # parse the interface definitions
234 $if_uuid = $h->{PROPERTIES}->{uuid};
235 $if_version = $h->{PROPERTIES}->{version};
239 #####################################################################
240 # parse a parsed IDL into a C header
246 $res = "/* header auto-generated by pidl */\n\n";
247 foreach my $x (@{$idl}) {
248 ($x->{TYPE} eq "MODULEHEADER") &&
251 ($x->{TYPE} eq "INTERFACE") &&