diff options
author | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
---|---|---|
committer | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
commit | 947c78887e791596d4a5ec2d1079f8b1a049628b (patch) | |
tree | 3981e88eb8764d7180722f8466f36b756dc005af /nsframework/backup_manager/config/uniqcheck.pl | |
parent | 706ad73eb02caf8532deaf5d38995bd258725cb8 (diff) |
basesystem 0.1sandbox/ToshikazuOhiwa/basesystem
Diffstat (limited to 'nsframework/backup_manager/config/uniqcheck.pl')
-rwxr-xr-x | nsframework/backup_manager/config/uniqcheck.pl | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nsframework/backup_manager/config/uniqcheck.pl b/nsframework/backup_manager/config/uniqcheck.pl new file mode 100755 index 00000000..1470d7c8 --- /dev/null +++ b/nsframework/backup_manager/config/uniqcheck.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +use strict; +use warnings; + +my @checkxpath = ('//item/@name', '//item/@id', '//category/@name'); + +sub uniqcheck($$) +{ + my $xpath = shift(@_); + my $list = shift(@_); + my %u = (); + foreach my $key (@{$list}) { + if (exists($u{$key})) { + print "detect duplicate $xpath $key\n"; + exit 1; + } + $u{$key} = 1; + } +} + +sub getlist($$) +{ + my $xmlfile = shift(@_); + my $xpath = shift(@_); + + $xmlfile =~ s/([\[\]\*\(\)])/\\$1/g; + + open(my $rs, "xmllint --xpath \"$xpath\" $xmlfile |") or die "Cannot open $xmlfile:$!"; + my $result = join('', <$rs>); + close $rs; + $result =~ s/^ +//; + my @result_array = split(/ +/, $result); + return @result_array; +} + +if ($#ARGV < 0 || !(-f $ARGV[0])) { + print "No such file or directory.\n"; + exit 1; +} + +foreach my $xpath (@checkxpath) { + my @result_array = getlist($ARGV[0], $xpath); + uniqcheck($xpath, \@result_array); +} + +0; |