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);
13 #####################################################################
14 # flatten an array of arrays into a single array
27 #####################################################################
28 # flatten an array of arrays into a single array
41 #####################################################################
42 # flatten an array of hashes into a single hash
48 for my $k (keys %{$d}) {
55 #####################################################################
56 # return the modification time of a file
59 my($filename) = shift;
60 return (stat($filename))[9];
63 #####################################################################
64 # read a file into a string
67 my($filename) = shift;
69 open(INPUTFILE, $filename) || return undef;
70 my($saved_delim) = $/;
72 my($data) = <INPUTFILE>;
78 #####################################################################
79 # write a string into a file
82 my($filename) = shift;
85 open(FILE, ">$filename") || die "can't open $filename";
90 #####################################################################
91 # a dumper wrapper to prevent dependence on the Data::Dumper module
92 # unless we actually need it
97 return Data::Dumper::Dumper($s);
100 #####################################################################
101 # see if a pidl property list contains a given property
107 if (!defined $e->{PROPERTIES}) {
111 return $e->{PROPERTIES}->{$p};
114 #####################################################################
115 # see if a pidl property matches a value
116 sub property_matches($$$)
122 if (!defined has_property($e, $p)) {
126 if ($e->{PROPERTIES}->{$p} =~ /$v/) {
133 # return 1 if the string is a C constant
137 if (defined $s && $s =~ /^\d/) {
143 # return a "" quoted string, unless already quoted
147 if (substr($str, 0, 1) eq "\"") {
150 return "\"" . $str . "\"";
153 # a hack to build on platforms that don't like negative enum values
154 my $useUintEnums = 0;
155 sub setUseUintEnums($)
157 $useUintEnums = shift;
161 return $useUintEnums;
166 my($expr,$varlist) = @_;
168 die("Undefined value in ParseExpr") if not defined($expr);
170 my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr;
173 foreach my $t (@tokens) {
174 if (defined($varlist->{$t})) {
175 $ret .= $varlist->{$t};