summaryrefslogtreecommitdiff
path: root/source4/build/pidl/Parse/Pidl/Util.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-07-09 15:32:08 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:27 -0500
commitfa1445f4bc962efb3e639d3a4e345b1db14155b7 (patch)
tree8799d04bc9ec022569fedd636e899bcc29a57935 /source4/build/pidl/Parse/Pidl/Util.pm
parentc222331d6d3785075bb0c961315aae9380101e47 (diff)
downloadsamba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.tar.gz
samba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.tar.bz2
samba-fa1445f4bc962efb3e639d3a4e345b1db14155b7.zip
r8264: - Use standard perl package structure for pidl.
- Only "use" pidl modules in the main executable when necessary Try 'make install' in build/pidl to install the package (should work stand-alone). (This used to be commit c620095692122a65ae1c5d85ca20468d4de93c54)
Diffstat (limited to 'source4/build/pidl/Parse/Pidl/Util.pm')
-rw-r--r--source4/build/pidl/Parse/Pidl/Util.pm219
1 files changed, 219 insertions, 0 deletions
diff --git a/source4/build/pidl/Parse/Pidl/Util.pm b/source4/build/pidl/Parse/Pidl/Util.pm
new file mode 100644
index 0000000000..41fde63c25
--- /dev/null
+++ b/source4/build/pidl/Parse/Pidl/Util.pm
@@ -0,0 +1,219 @@
+###################################################
+# utility functions to support pidl
+# Copyright tridge@samba.org 2000
+# released under the GNU GPL
+package Parse::Pidl::Util;
+
+use strict;
+
+#####################################################################
+# flatten an array of arrays into a single array
+sub FlattenArray2($)
+{
+ my $a = shift;
+ my @b;
+ for my $d (@{$a}) {
+ for my $d1 (@{$d}) {
+ push(@b, $d1);
+ }
+ }
+ return \@b;
+}
+
+#####################################################################
+# flatten an array of arrays into a single array
+sub FlattenArray($)
+{
+ my $a = shift;
+ my @b;
+ for my $d (@{$a}) {
+ for my $d1 (@{$d}) {
+ push(@b, $d1);
+ }
+ }
+ return \@b;
+}
+
+#####################################################################
+# flatten an array of hashes into a single hash
+sub FlattenHash($)
+{
+ my $a = shift;
+ my %b;
+ for my $d (@{$a}) {
+ for my $k (keys %{$d}) {
+ $b{$k} = $d->{$k};
+ }
+ }
+ return \%b;
+}
+
+#####################################################################
+# traverse a perl data structure removing any empty arrays or
+# hashes and any hash elements that map to undef
+sub CleanData($)
+{
+ sub CleanData($);
+ my($v) = shift;
+ if (ref($v) eq "ARRAY") {
+ foreach my $i (0 .. $#{$v}) {
+ CleanData($v->[$i]);
+ if (ref($v->[$i]) eq "ARRAY" && $#{$v->[$i]}==-1) {
+ $v->[$i] = undef;
+ next;
+ }
+ }
+ # this removes any undefined elements from the array
+ @{$v} = grep { defined $_ } @{$v};
+ } elsif (ref($v) eq "HASH") {
+ foreach my $x (keys %{$v}) {
+ CleanData($v->{$x});
+ if (!defined $v->{$x}) { delete($v->{$x}); next; }
+ if (ref($v->{$x}) eq "ARRAY" && $#{$v->{$x}}==-1) { delete($v->{$x}); next; }
+ }
+ }
+ return $v;
+}
+
+#####################################################################
+# return the modification time of a file
+sub FileModtime($)
+{
+ my($filename) = shift;
+ return (stat($filename))[9];
+}
+
+#####################################################################
+# read a file into a string
+sub FileLoad($)
+{
+ my($filename) = shift;
+ local(*INPUTFILE);
+ open(INPUTFILE, $filename) || return undef;
+ my($saved_delim) = $/;
+ undef $/;
+ my($data) = <INPUTFILE>;
+ close(INPUTFILE);
+ $/ = $saved_delim;
+ return $data;
+}
+
+#####################################################################
+# write a string into a file
+sub FileSave($$)
+{
+ my($filename) = shift;
+ my($v) = shift;
+ local(*FILE);
+ open(FILE, ">$filename") || die "can't open $filename";
+ print FILE $v;
+ close(FILE);
+}
+
+#####################################################################
+# return a filename with a changed extension
+sub ChangeExtension($$)
+{
+ my($fname) = shift;
+ my($ext) = shift;
+ if ($fname =~ /^(.*)\.(.*?)$/) {
+ return "$1$ext";
+ }
+ return "$fname$ext";
+}
+
+#####################################################################
+# a dumper wrapper to prevent dependence on the Data::Dumper module
+# unless we actually need it
+sub MyDumper($)
+{
+ require Data::Dumper;
+ my $s = shift;
+ return Data::Dumper::Dumper($s);
+}
+
+#####################################################################
+# see if a pidl property list contains a given property
+sub has_property($$)
+{
+ my($e) = shift;
+ my($p) = shift;
+
+ if (!defined $e->{PROPERTIES}) {
+ return undef;
+ }
+
+ return $e->{PROPERTIES}->{$p};
+}
+
+#####################################################################
+# see if a pidl property matches a value
+sub property_matches($$$)
+{
+ my($e) = shift;
+ my($p) = shift;
+ my($v) = shift;
+
+ if (!defined has_property($e, $p)) {
+ return undef;
+ }
+
+ if ($e->{PROPERTIES}->{$p} =~ /$v/) {
+ return 1;
+ }
+
+ return undef;
+}
+
+# return 1 if the string is a C constant
+sub is_constant($)
+{
+ my $s = shift;
+ if (defined $s && $s =~ /^\d/) {
+ return 1;
+ }
+ return 0;
+}
+
+# return a "" quoted string, unless already quoted
+sub make_str($)
+{
+ my $str = shift;
+ if (substr($str, 0, 1) eq "\"") {
+ return $str;
+ }
+ return "\"" . $str . "\"";
+}
+
+# a hack to build on platforms that don't like negative enum values
+my $useUintEnums = 0;
+sub setUseUintEnums($)
+{
+ $useUintEnums = shift;
+}
+sub useUintEnums()
+{
+ return $useUintEnums;
+}
+
+sub ParseExpr($$)
+{
+ my($expr,$varlist) = @_;
+
+ die("Undefined value in ParseExpr") if not defined($expr);
+
+ my @tokens = split /((?:[A-Za-z_])(?:(?:(?:[A-Za-z0-9_.])|(?:->))+))/, $expr;
+ my $ret = "";
+
+ foreach my $t (@tokens) {
+ if (defined($varlist->{$t})) {
+ $ret .= $varlist->{$t};
+ } else {
+ $ret .= $t;
+ }
+ }
+
+ return $ret;
+}
+
+1;