Re-organized sub-directory by category
[staging/basesystem.git] / service / native / backup_manager / config / uniqcheck.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my @checkxpath = ('//item/@name', '//item/@id', '//category/@name');
6
7 sub uniqcheck($$)
8 {
9   my $xpath = shift(@_);
10   my $list = shift(@_);
11   my %u = ();
12   foreach my $key (@{$list}) {
13     if (exists($u{$key})) {
14       print "detect duplicate $xpath $key\n";
15       exit 1;
16     }
17     $u{$key} = 1;
18   }
19 }
20
21 sub getlist($$)
22 {
23   my $xmlfile = shift(@_);
24   my $xpath = shift(@_);
25
26   $xmlfile =~ s/([\[\]\*\(\)])/\\$1/g;
27
28   open(my $rs, "xmllint --xpath \"$xpath\" $xmlfile |") or die "Cannot open $xmlfile:$!";
29   my $result = join('', <$rs>);
30   close $rs;
31   $result =~ s/^ +//;
32   my @result_array = split(/ +/, $result);
33   return @result_array;
34 }
35
36 if ($#ARGV < 0 || !(-f $ARGV[0])) {
37   print "No such file or directory.\n";
38   exit 1;
39 }
40
41 foreach my $xpath (@checkxpath) {
42   my @result_array = getlist($ARGV[0], $xpath);
43   uniqcheck($xpath, \@result_array);
44 }
45
46 0;