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 # return a filename with a changed extension
92 sub ChangeExtension($$)
96 if ($fname =~ /^(.*)\.(.*?)$/) {
102 #####################################################################
103 # a dumper wrapper to prevent dependence on the Data::Dumper module
104 # unless we actually need it
107 require Data::Dumper;
109 return Data::Dumper::Dumper($s);
112 #####################################################################
113 # see if a pidl property list contains a given property
119 if (!defined $e->{PROPERTIES}) {
123 return $e->{PROPERTIES}->{$p};
126 #####################################################################
127 # see if a pidl property matches a value
128 sub property_matches($$$)
134 if (!defined has_property($e, $p)) {
138 if ($e->{PROPERTIES}->{$p} =~ /$v/) {
145 # return 1 if the string is a C constant
149 if (defined $s && $s =~ /^\d/) {
155 # return a "" quoted string, unless already quoted
159 if (substr($str, 0, 1) eq "\"") {
162 return "\"" . $str . "\"";
165 # a hack to build on platforms that don't like negative enum values
166 my $useUintEnums = 0;
167 sub setUseUintEnums($)
169 $useUintEnums = shift;
173 return $useUintEnums;
178 my($expr,$varlist) = @_;
180 die("Undefined value in ParseExpr") if not defined($expr);
182 my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr;
185 foreach my $t (@tokens) {
186 if (defined($varlist->{$t})) {
187 $ret .= $varlist->{$t};