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);
23 my $srcdir = $ENV{srcdir};
24 $srcdir = $srcdir ? "$srcdir/" : "";
25 return 4 if (-f "${srcdir}kdc/kdc.c");
26 return 3 if (-f "${srcdir}include/smb.h");
30 # Return an #include line depending on whether this build is an in-tree
35 return "#include \"$in\"" if (is_intree());
36 return "#include <$out>";
39 sub ArrayDynamicallyAllocated($$)
42 die("Not an array") unless ($l->{TYPE} eq "ARRAY");
43 return 0 if ($l->{IS_FIXED} and not has_property($e, "charset"));
50 $d = 0 unless defined($d);
53 foreach my $l (@{$e->{LEVELS}}) {
54 next unless ($l->{TYPE} eq "POINTER");
56 my $nl = GetNextLevel($e, $l);
57 next if (defined($nl) and $nl->{TYPE} eq "ARRAY");
63 $n-- if (scalar_is_reference($e->{TYPE}));
66 foreach my $l (@{$e->{LEVELS}}) {
67 next unless ($l->{TYPE} eq "ARRAY");
68 next unless (ArrayDynamicallyAllocated($e, $l));
72 error($e->{ORIGINAL}, "Too few pointers $n < $d") if ($n < $d);
85 $n = NumStars($e, $d);
86 $res .= "*" foreach (1..$n);
96 foreach my $l (@{$e->{LEVELS}}) {
97 next unless ($l->{TYPE} eq "ARRAY");
98 next if ArrayDynamicallyAllocated($e, $l);
99 $res .= "[$l->{SIZE_IS}]";
110 if (has_property($e, "represent_as")) {
111 $res .= mapTypeName($e->{PROPERTIES}->{represent_as})." ";
113 if (has_property($e, "charset")) {
114 $res .= "const char ";
116 $res .= mapTypeName($e->{TYPE})." ";
119 $res .= ElementStars($e);
122 $res .= ArrayBrackets($e);