summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorKrzesimir Nowak <krnowak@openismus.com>2012-11-15 15:39:48 +0100
committerJens Georg <mail@jensge.org>2012-11-30 23:11:57 +0100
commit992e10ea20fafc46e2a06c20718d232709aa80b1 (patch)
tree85a6bfa304f7eed9d4cd1469326aae29aa866183 /data
parent100e8bf955b6a9d6ad3532555310ee8afbbdaf33 (diff)
downloadgupnp-dlna-992e10ea20fafc46e2a06c20718d232709aa80b1.tar.gz
Add a script that extract restriction attributes and their types
Was useful when writing GUPnPDLNA{Foo}Information classes.
Diffstat (limited to 'data')
-rwxr-xr-xdata/restriction_field_types.pl110
1 files changed, 110 insertions, 0 deletions
diff --git a/data/restriction_field_types.pl b/data/restriction_field_types.pl
new file mode 100755
index 0000000..54ca77a
--- /dev/null
+++ b/data/restriction_field_types.pl
@@ -0,0 +1,110 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use XML::Parser::Expat;
+
+my %restrictions = ();
+my @restriction_stack = [];
+
+sub start
+{
+ my ($p, $el, %atts) = @_;
+
+ if ($el eq 'restriction')
+ {
+ if (exists ($atts{'type'}))
+ {
+ my $type = $atts{'type'};
+
+ unless (exists ($restrictions{$type}))
+ {
+ $restrictions{$type} = {};
+ }
+ push (@restriction_stack, $type);
+ }
+ }
+ elsif ($el eq 'field')
+ {
+ if (exists ($atts{'name'}))
+ {
+ my $name = $atts{'name'};
+
+ if (exists ($atts{'type'}))
+ {
+ my $type = $atts{'type'};
+
+ if (@restriction_stack)
+ {
+ my $restriction_type = $restriction_stack[-1];
+ my $fields = $restrictions{$restriction_type};
+
+ if (exists $fields->{$name})
+ {
+ if ($fields->{$name} ne $type)
+ {
+ print STDERR "Field '$name' of '$restriction_type' has different types: $fields->{$name} and $type.\n";
+ }
+ }
+ else
+ {
+ $fields->{$name} = $type;
+ }
+ }
+ else
+ {
+ print STDERR "Field '$name' of type '$type' is not a part of restriction.\n";
+ }
+ }
+ else
+ {
+ print STDERR "Field '$name' has no type attribute.\n";
+ }
+ }
+ else
+ {
+ print STDERR "Unnamed field.\n";
+ }
+ }
+}
+
+sub end
+{
+ my ($p, $el) = @_;
+
+ if ($el eq 'restriction')
+ {
+ if (@restriction_stack)
+ {
+ pop (@restriction_stack);
+ }
+ else
+ {
+ print STDERR "Tried to pop a restriction but stack is empty.\n";
+ }
+ }
+}
+
+foreach my $file (@ARGV)
+{
+ my $parser = XML::Parser::Expat->new ();
+
+ $parser->setHandlers ('Start' => \&start,
+ 'End' => \&end);
+
+ $parser->parsefile ($file);
+ $parser->release ();
+}
+
+foreach my $type (sort (keys (%restrictions)))
+{
+ my $fields = $restrictions{$type};
+
+ print "Restriction type: $type\n";
+ foreach my $field (sort (keys (%{$fields})))
+ {
+ my $field_type = $fields->{$field};
+
+ print " $field [$field_type]\n";
+ }
+}