1 ###################################################
2 # utility functions to support pidl
3 # Copyright tridge@samba.org 2000
4 # released under the GNU GPL
5 package Parse::Pidl::Util;
9 @EXPORT = qw(has_property property_matches ParseExpr is_constant make_str print_uuid);
10 use vars qw($VERSION);
15 #####################################################################
16 # a dumper wrapper to prevent dependence on the Data::Dumper module
17 # unless we actually need it
22 return Data::Dumper::Dumper($s);
25 #####################################################################
26 # see if a pidl property list contains a given property
32 if (!defined $e->{PROPERTIES}) {
36 return $e->{PROPERTIES}->{$p};
39 #####################################################################
40 # see if a pidl property matches a value
41 sub property_matches($$$)
47 if (!defined has_property($e, $p)) {
51 if ($e->{PROPERTIES}->{$p} =~ /$v/) {
58 # return 1 if the string is a C constant
62 if (defined $s && $s =~ /^\d/) {
68 # return a "" quoted string, unless already quoted
72 if (substr($str, 0, 1) eq "\"") {
75 return "\"" . $str . "\"";
82 my ($time_low,$time_mid,$time_hi,$clock_seq,$node) = split /-/, $uuid;
84 my @clock_seq = $clock_seq =~ /(..)/g;
85 my @node = $node =~ /(..)/g;
87 return "{0x$time_low,0x$time_mid,0x$time_hi," .
88 "{".join(',', map {"0x$_"} @clock_seq)."}," .
89 "{".join(',', map {"0x$_"} @node)."}}";
92 # a hack to build on platforms that don't like negative enum values
94 sub setUseUintEnums($)
96 $useUintEnums = shift;
100 return $useUintEnums;
105 my($expr,$varlist) = @_;
107 die("Undefined value in ParseExpr") if not defined($expr);
109 my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr;
112 foreach my $t (@tokens) {
113 if (defined($varlist->{$t})) {
114 $ret .= $varlist->{$t};