1 ###################################################
2 # create C header files for an IDL structure
3 # Copyright tridge@samba.org 2000
4 # released under the GNU GPL
18 for (my($i)=0; $i < $tab_depth; $i++) {
23 #####################################################################
24 # parse a properties list
25 sub HeaderProperties
($)
31 foreach my $d (@
{$props}) {
32 if (ref($d) ne "HASH") {
33 $res .= "/* [$d] */ ";
35 foreach my $k (keys %{$d}) {
36 $res .= "/* [$k($d->{$k})] */ ";
42 #####################################################################
43 # parse a structure element
48 (defined $element->{PROPERTIES
}) && HeaderProperties
($element->{PROPERTIES
});
50 HeaderType
($element, $element->{TYPE
}, "");
52 if ($element->{POINTERS
}) {
53 my($n) = $element->{POINTERS
};
54 for (my($i)=$n; $i > 0; $i--) {
58 if (defined $element->{ARRAY_LEN
} &&
59 !util
::is_constant
($element->{ARRAY_LEN
})) {
60 # conformant arrays are ugly! I choose to implement them with
61 # pointers instead of the [1] method
64 $res .= "$element->{NAME}";
65 if (defined $element->{ARRAY_LEN
} && util
::is_constant
($element->{ARRAY_LEN
})) {
66 $res .= "[$element->{ARRAY_LEN}]";
71 #####################################################################
77 $res .= "struct $name {\n";
79 if (defined $struct->{ELEMENTS
}) {
80 foreach my $e (@
{$struct->{ELEMENTS
}}) {
89 #####################################################################
90 # parse a union element
91 sub HeaderUnionElement
($)
94 $res .= "/* [case($element->{CASE})] */ ";
95 if ($element->{TYPE
} eq "UNION_ELEMENT") {
96 HeaderElement
($element->{DATA
});
100 #####################################################################
106 (defined $union->{PROPERTIES
}) && HeaderProperties
($union->{PROPERTIES
});
107 $res .= "union $name {\n";
108 foreach my $e (@
{$union->{DATA
}}) {
109 HeaderUnionElement
($e);
114 #####################################################################
121 if (ref($data) eq "HASH") {
122 ($data->{TYPE
} eq "STRUCT") &&
123 HeaderStruct
($data, $name);
124 ($data->{TYPE
} eq "UNION") &&
125 HeaderUnion
($data, $name);
128 if ($data =~ "unistr") {
129 $res .= "const char";
130 } elsif ($data =~ "nstring") {
131 $res .= "const char *";
132 } elsif ($data =~ "lstring") {
133 $res .= "const char *";
134 } elsif (util
::is_scalar_type
($data)) {
136 } elsif (util
::has_property
($e, "switch_is")) {
137 $res .= "union $data";
139 $res .= "struct $data";
143 #####################################################################
147 my($typedef) = shift;
148 HeaderType
($typedef, $typedef->{DATA
}, $typedef->{NAME
});
152 #####################################################################
154 sub HeaderFunctionInOut
($$)
158 foreach my $e (@
{$fn->{DATA
}}) {
159 if (util
::has_property
($e, $prop)) {
166 #####################################################################
168 sub HeaderFunction
($)
171 $res .= "struct $fn->{NAME} {\n";
174 $res .= "struct {\n";
176 HeaderFunctionInOut
($fn, "in");
181 $res .= "struct {\n";
183 HeaderFunctionInOut
($fn, "out");
184 if ($fn->{RETURN_TYPE
} && $fn->{RETURN_TYPE
} ne "void") {
186 $res .= "$fn->{RETURN_TYPE} result;\n";
190 $res .= "} out;\n\n";
195 #####################################################################
196 # parse the interface definitions
197 sub HeaderInterface
($)
199 my($interface) = shift;
200 my($data) = $interface->{DATA
};
204 if (defined $if_uuid) {
205 my $name = uc $interface->{NAME
};
206 $res .= "#define DCERPC_$name\_UUID \"$if_uuid\"\n";
207 $res .= "#define DCERPC_$name\_VERSION $if_version\n";
208 $res .= "#define DCERPC_$name\_NAME \"$interface->{NAME}\"\n\n";
211 foreach my $d (@
{$data}) {
212 if ($d->{TYPE
} eq "FUNCTION") {
213 my $u_name = uc $d->{NAME
};
214 $res .= "#define DCERPC_$u_name $count\n";
221 foreach my $d (@
{$data}) {
222 ($d->{TYPE
} eq "TYPEDEF") &&
224 ($d->{TYPE
} eq "FUNCTION") &&
230 #####################################################################
231 # parse the interface definitions
236 $if_uuid = $h->{PROPERTIES
}->{uuid
};
237 $if_version = $h->{PROPERTIES
}->{version
};
241 #####################################################################
242 # parse a parsed IDL into a C header
248 $res = "/* header auto-generated by pidl */\n\n";
249 foreach my $x (@
{$idl}) {
250 ($x->{TYPE
} eq "MODULEHEADER") &&
253 ($x->{TYPE
} eq "INTERFACE") &&