aboutsummaryrefslogtreecommitdiffstats
path: root/tools/pidl/lib/Parse/Pidl/Samba4.pm
blob: 2d710f3eb6c11605de5f73dd6286784b33e01967 (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
###################################################
# 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);

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 -f "include/smb.h";
}

# 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 DeclLong($)
{
	my($element) = shift;
	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++;
		}
		$ret.="*" foreach (1..$numstar);
	}
	$ret.=$element->{NAME};
	foreach (@{$element->{ARRAY_LEN}}) {
		next unless (is_constant($_) and not has_property($element, "charset"));
		$ret.="[$_]";
	}

	return $ret;
}

1;