summaryrefslogtreecommitdiff
path: root/source4/pidl/lib/Parse/Pidl/Util.pm
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-21 23:30:17 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:17 -0500
commit59b13f9a1d684a632c2c73352f0ec08a63bc0913 (patch)
tree14b0a564e4db3377f7ad2fa1f9671f8e04405962 /source4/pidl/lib/Parse/Pidl/Util.pm
parentefc03df292aa84edb592c22191dbf86cdf8c32d0 (diff)
downloadsamba-59b13f9a1d684a632c2c73352f0ec08a63bc0913.tar.gz
samba-59b13f9a1d684a632c2c73352f0ec08a63bc0913.tar.bz2
samba-59b13f9a1d684a632c2c73352f0ec08a63bc0913.zip
r9460: - Move pidl to lib/. This fixes standalone installation of pidl.
- Update the README - Allow building the docs stand-alone (This used to be commit b56084ce251ab7a35dd1422f38de258e8e1e1477)
Diffstat (limited to 'source4/pidl/lib/Parse/Pidl/Util.pm')
-rw-r--r--source4/pidl/lib/Parse/Pidl/Util.pm149
1 files changed, 149 insertions, 0 deletions
diff --git a/source4/pidl/lib/Parse/Pidl/Util.pm b/source4/pidl/lib/Parse/Pidl/Util.pm
new file mode 100644
index 0000000000..8854be9d74
--- /dev/null
+++ b/source4/pidl/lib/Parse/Pidl/Util.pm
@@ -0,0 +1,149 @@
+###################################################
+# utility functions to support pidl
+# Copyright tridge@samba.org 2000
+# released under the GNU GPL
+package Parse::Pidl::Util;
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT = qw(has_property property_matches ParseExpr is_constant);
+
+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;
+}
+
+#####################################################################
+# 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;