summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/CUtil.pm
blob: 9deb6ee1779ab3beac27f24ea734b74f8c8f6266 (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
###################################################
# C utility functions for pidl
# Copyright jelmer@samba.org 2005-2007
# released under the GNU GPL
package Parse::Pidl::CUtil;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(get_pointer_to get_value_of get_array_element);
use vars qw($VERSION);
$VERSION = '0.01';

use strict;

sub get_pointer_to($)
{
	my $var_name = shift;
	
	if ($var_name =~ /^\*(.*)$/) {
		return $1;
	} elsif ($var_name =~ /^\&(.*)$/) {
		return "&($var_name)";
	} else {
		return "&$var_name";
	}
}

sub get_value_of($)
{
	my $var_name = shift;

	if ($var_name =~ /^\&(.*)$/) {
		return $1;
	} else {
		return "*$var_name";
	}
}

sub get_array_element($$)
{
	my ($var_name, $idx) = @_;

	if ($var_name =~ /^\*.*$/) {
		$var_name = "($var_name)";
	} elsif ($var_name =~ /^\&.*$/) {
		$var_name = "($var_name)";
	}

	return "$var_name"."[$idx]";
}

1;