r17930: Merge noinclude branch:
[jelmer/samba4-debian.git] / source / pidl / lib / Parse / Pidl / Samba4.pm
1 ###################################################
2 # Common Samba4 functions
3 # Copyright jelmer@samba.org 2006
4 # released under the GNU GPL
5
6 package Parse::Pidl::Samba4;
7
8 require Exporter;
9 @ISA = qw(Exporter);
10 @EXPORT = qw(is_intree choose_header DeclLong);
11
12 use Parse::Pidl::Util qw(has_property is_constant);
13 use Parse::Pidl::Typelist qw(mapType scalar_is_reference);
14 use strict;
15
16 use vars qw($VERSION);
17 $VERSION = '0.01';
18
19 sub is_intree()
20 {
21         return -f "kdc/kdc.c";
22 }
23
24 # Return an #include line depending on whether this build is an in-tree
25 # build or not.
26 sub choose_header($$)
27 {
28         my ($in,$out) = @_;
29         return "#include \"$in\"" if (is_intree());
30         return "#include <$out>";
31 }
32
33 sub DeclLong($)
34 {
35         my($element) = shift;
36         my $ret = "";
37
38         if (has_property($element, "represent_as")) {
39                 $ret.=mapType($element->{PROPERTIES}->{represent_as})." ";
40         } else {
41                 if (has_property($element, "charset")) {
42                         $ret.="const char";
43                 } else {
44                         $ret.=mapType($element->{TYPE});
45                 }
46
47                 $ret.=" ";
48                 my $numstar = $element->{ORIGINAL}->{POINTERS};
49                 if ($numstar >= 1) {
50                         $numstar-- if scalar_is_reference($element->{TYPE});
51                 }
52                 foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}})
53                 {
54                         next if is_constant($_) and 
55                                 not has_property($element, "charset");
56                         $numstar++;
57                 }
58                 $ret.="*" foreach (1..$numstar);
59         }
60         $ret.=$element->{NAME};
61         foreach (@{$element->{ARRAY_LEN}}) {
62                 next unless (is_constant($_) and not has_property($element, "charset"));
63                 $ret.="[$_]";
64         }
65
66         return $ret;
67 }
68
69 1;