1 ###################################################
2 # create C header files for an IDL structure
3 # Copyright tridge@samba.org 2000
4 # released under the GNU GPL
14 for (my($i)=0; $i < $tab_depth; $i++) {
19 #####################################################################
20 # parse a properties list
21 sub HeaderProperties($)
27 foreach my $d (@{$props}) {
28 if (ref($d) ne "HASH") {
29 $res .= "/* [$d] */ ";
31 foreach my $k (keys %{$d}) {
32 $res .= "/* [$k($d->{$k})] */ ";
38 #####################################################################
39 # parse a structure element
44 if (util::has_property($element, "struct_len")) {
45 # a struct_len is an internal artifact - it is put on the
46 # wire but not exposed via the api, which means it does
47 # not appear in the header file
52 (defined $element->{PROPERTIES}) && HeaderProperties($element->{PROPERTIES});
54 HeaderType($element, $element->{TYPE}, "");
56 if ($element->{POINTERS}) {
57 my($n) = $element->{POINTERS};
58 for (my($i)=$n; $i > 0; $i--) {
62 if (defined $element->{ARRAY_LEN} && $element->{ARRAY_LEN} eq "*") {
63 # conformant arrays are ugly! I choose to implement them with
64 # pointers instead of the [1] method
67 $res .= "$element->{NAME}";
68 if (defined $element->{ARRAY_LEN} && $element->{ARRAY_LEN} ne "*") {
69 $res .= "[$element->{ARRAY_LEN}]";
74 #####################################################################
80 $res .= "struct $name {\n";
82 if (defined $struct->{ELEMENTS}) {
83 foreach my $e (@{$struct->{ELEMENTS}}) {
92 #####################################################################
93 # parse a union element
94 sub HeaderUnionElement($)
97 $res .= "/* [case($element->{CASE})] */ ";
98 HeaderElement($element->{DATA});
101 #####################################################################
107 (defined $union->{PROPERTIES}) && HeaderProperties($union->{PROPERTIES});
108 $res .= "union $name {\n";
109 foreach my $e (@{$union->{DATA}}) {
110 HeaderUnionElement($e);
115 #####################################################################
122 if (ref($data) eq "HASH") {
123 ($data->{TYPE} eq "STRUCT") &&
124 HeaderStruct($data, $name);
125 ($data->{TYPE} eq "UNION") &&
126 HeaderUnion($data, $name);
129 if ($data =~ "unistr") {
130 $res .= "const char";
131 } elsif (util::is_scalar_type($data)) {
133 } elsif (util::has_property($e, "switch_is")) {
134 $res .= "union $data";
136 $res .= "struct $data";
140 #####################################################################
144 my($typedef) = shift;
145 HeaderType($typedef, $typedef->{DATA}, $typedef->{NAME});
149 #####################################################################
151 sub HeaderFunctionInOut($$)
155 foreach my $e (@{$fn->{DATA}}) {
156 if (util::has_property($e, $prop)) {
163 #####################################################################
165 sub HeaderFunction($)
168 $res .= "struct $fn->{NAME} {\n";
171 $res .= "struct {\n";
173 HeaderFunctionInOut($fn, "in");
178 $res .= "struct {\n";
180 HeaderFunctionInOut($fn, "out");
181 if ($fn->{RETURN_TYPE} && $fn->{RETURN_TYPE} ne "void") {
183 $res .= "$fn->{RETURN_TYPE} result;\n";
187 $res .= "} out;\n\n";
192 #####################################################################
193 # parse the interface definitions
194 sub HeaderInterface($)
196 my($interface) = shift;
197 my($data) = $interface->{DATA};
198 foreach my $d (@{$data}) {
199 ($d->{TYPE} eq "TYPEDEF") &&
201 ($d->{TYPE} eq "FUNCTION") &&
207 foreach my $d (@{$data}) {
208 if ($d->{TYPE} eq "FUNCTION") {
209 $u_name = uc $d->{NAME};
210 $res .= "#define DCERPC_$u_name $count\n";
217 #####################################################################
218 # parse a parsed IDL into a C header
224 $res = "/* header auto-generated by pidl */\n\n";
225 foreach my $x (@{$idl}) {
226 ($x->{TYPE} eq "INTERFACE") &&