1 ###################################################
2 # Common Samba4 functions
3 # Copyright jelmer@samba.org 2006
4 # released under the GNU GPL
6 package Parse::Pidl::Samba4;
10 @EXPORT = qw(is_intree choose_header NumStars ElementStars ArrayBrackets DeclLong ArrayDynamicallyAllocated);
12 use Parse::Pidl::Util qw(has_property is_constant);
13 use Parse::Pidl::NDR qw(GetNextLevel);
14 use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference);
15 use Parse::Pidl qw(fatal error);
18 use vars qw($VERSION);
22 # return true if we are using pidl within the samba source tree. This changes
23 # the names of include files, as some include files (such as ntstatus.h) have
24 # different paths when installed to the patch in the source tree
27 my $srcdir = $ENV{srcdir};
28 $srcdir = $srcdir ? "$srcdir/" : "";
29 return 1 if (-f "${srcdir}kdc/kdc.c");
30 return 1 if (-d "${srcdir}source4");
31 return 1 if (-f "${srcdir}include/smb.h");
35 # Return an #include line depending on whether this build is an in-tree
40 return "#include \"$in\"" if (is_intree());
41 return "#include <$out>";
44 sub ArrayDynamicallyAllocated($$)
47 die("Not an array") unless ($l->{TYPE} eq "ARRAY");
48 return 0 if ($l->{IS_FIXED} and not has_property($e, "charset"));
55 $d = 0 unless defined($d);
58 foreach my $l (@{$e->{LEVELS}}) {
59 next unless ($l->{TYPE} eq "POINTER");
61 my $nl = GetNextLevel($e, $l);
62 next if (defined($nl) and $nl->{TYPE} eq "ARRAY");
68 $n-- if (scalar_is_reference($e->{TYPE}));
71 foreach my $l (@{$e->{LEVELS}}) {
72 next unless ($l->{TYPE} eq "ARRAY");
73 next unless (ArrayDynamicallyAllocated($e, $l));
77 error($e->{ORIGINAL}, "Too few pointers $n < $d") if ($n < $d);
90 $n = NumStars($e, $d);
91 $res .= "*" foreach (1..$n);
101 foreach my $l (@{$e->{LEVELS}}) {
102 next unless ($l->{TYPE} eq "ARRAY");
103 next if ArrayDynamicallyAllocated($e, $l);
104 $res .= "[$l->{SIZE_IS}]";
114 $p = "" unless defined($p);
116 if (has_property($e, "represent_as")) {
117 $res .= mapTypeName($e->{PROPERTIES}->{represent_as})." ";
119 if (has_property($e, "charset")) {
120 $res .= "const char ";
122 $res .= mapTypeName($e->{TYPE})." ";
125 $res .= ElementStars($e);
127 $res .= $p.$e->{NAME};
128 $res .= ArrayBrackets($e);