r9078: - move charset stuff to lib/charset
[sfrench/samba-autobuild/.git] / source / build / pidl / Parse / Pidl / Ethereal / NDR / Header.pm
1 ###################################################
2 # create C header files for an IDL structure
3 # Copyright tridge@samba.org 2000
4 # Copyright jelmer@samba.org 2005
5 # released under the GNU GPL
6
7 package Parse::Pidl::Ethereal::NDR::Header;
8
9 use strict;
10
11 use Parse::Pidl::Util qw(has_property);
12
13 my($res);
14 my($tab_depth);
15
16 sub pidl ($)
17 {
18         $res .= shift;
19 }
20
21 sub tabs()
22 {
23         for (my($i)=0; $i < $tab_depth; $i++) {
24                 pidl "\t";
25         }
26 }
27
28 #####################################################################
29 # prototype a typedef
30 sub HeaderTypedefProto($)
31 {
32     my($d) = shift;
33
34     my $tf = Parse::Pidl::Ethereal::NDR::Parser::get_typefamily($d->{DATA}{TYPE});
35
36     return unless has_property($d, "public");
37
38     unless (has_property($d, "nopull")) {
39                 pidl "dcerpc_dissect_fnct_t $d->{NAME};\n";
40     }
41 }
42
43 #####################################################################
44 # parse a const
45 sub HeaderConst($)
46 {
47     my($const) = shift;
48     if (!defined($const->{ARRAY_LEN}[0])) {
49         pidl "#define $const->{NAME}\t( $const->{VALUE} )\n";
50     } else {
51         pidl "#define $const->{NAME}\t $const->{VALUE}\n";
52     }
53 }
54
55 my %headerstructs = ();
56
57 #####################################################################
58 # parse the interface definitions
59 sub HeaderInterface($)
60 {
61     my($interface) = shift;
62
63     my $count = 0;
64
65     pidl "#ifndef _HEADER_NDR_$interface->{NAME}\n";
66     pidl "#define _HEADER_NDR_$interface->{NAME}\n\n";
67
68     if (defined $interface->{PROPERTIES}->{depends}) {
69             my @d = split / /, $interface->{PROPERTIES}->{depends};
70             foreach my $i (@d) {
71                     pidl "#include \"packet-dcerpc-$i\.h\"\n";
72             }
73     }
74
75         foreach my $d (@{$interface->{CONSTS}}) {
76             HeaderConst($d);
77     }
78
79     foreach my $d (@{$interface->{TYPEDEFS}}) {
80             HeaderTypedefProto($d);
81         }
82
83     pidl "#endif /* _HEADER_NDR_$interface->{NAME} */\n";
84 }
85
86 #####################################################################
87 # parse a parsed IDL into a C header
88 sub Parse($)
89 {
90     my($idl) = shift;
91     $tab_depth = 0;
92
93         $res = "";
94     pidl "/* header auto-generated by pidl */\n\n";
95     foreach my $x (@{$idl}) {
96             if ($x->{TYPE} eq "INTERFACE") {
97                     HeaderInterface($x);
98             }
99     }
100     return $res;
101 }
102
103 1;