summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/Samba4.pm
blob: e11bd6a5ffdb89a09e19f863a449ccd6d5099320 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
###################################################
# Common Samba4 functions
# Copyright jelmer@samba.org 2006
# released under the GNU GPL

package Parse::Pidl::Samba4;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(is_intree choose_header DeclLong DeclLong_cli IsUniqueOut);

use Parse::Pidl::Util qw(has_property is_constant);
use Parse::Pidl::Typelist qw(mapType scalar_is_reference);
use strict;

use vars qw($VERSION);
$VERSION = '0.01';

sub is_intree()
{
	return 4 if (-f "kdc/kdc.c");
	return 3 if (-f "include/smb.h");
	return 0;
}

# Return an #include line depending on whether this build is an in-tree
# build or not.
sub choose_header($$)
{
	my ($in,$out) = @_;
	return "#include \"$in\"" if (is_intree());
	return "#include <$out>";
}

sub IsUniqueOut($)
{
    my ($e) = shift;

    return grep(/out/, @{$e->{DIRECTION}}) &&
	((($e->{LEVELS}[0]->{TYPE} eq "POINTER") &&
	  ($e->{LEVELS}[0]->{POINTER_TYPE} eq "unique")) ||
	 ($e->{LEVELS}[0]->{TYPE} eq "ARRAY"));
}

sub DeclLong_int($$)
{
	my($element,$cli) = @_;
	my $ret = "";

	if (has_property($element, "represent_as")) {
		$ret.=mapType($element->{PROPERTIES}->{represent_as})." ";
	} else {
		if (has_property($element, "charset")) {
			$ret.="const char";
		} else {
			$ret.=mapType($element->{TYPE});
		}

		$ret.=" ";
		my $numstar = $element->{ORIGINAL}->{POINTERS};
		if ($numstar >= 1) {
			$numstar-- if scalar_is_reference($element->{TYPE});
		}
		foreach (@{$element->{ORIGINAL}->{ARRAY_LEN}})
		{
			next if is_constant($_) and 
				not has_property($element, "charset");
			$numstar++;
		}
		if ($cli && IsUniqueOut($element)) {
			$numstar++;
		}
		$ret.="*" foreach (1..$numstar);
	}
	$ret.=$element->{NAME};
	foreach (@{$element->{ARRAY_LEN}}) {
		next unless (is_constant($_) and not has_property($element, "charset"));
		$ret.="[$_]";
	}

	return $ret;
}

sub DeclLong($)
{
    return DeclLong_int($_, 0);
}

sub DeclLong_cli($)
{
    return DeclLong_int($_, 1);
}

1;