2014-10-05 17:28:09 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2015-03-28 20:32:59 +00:00
|
|
|
# Details in Forum #35416
|
|
|
|
|
|
|
|
if(@ARGV == 0 || ($ARGV[0] =~ m/^-/ && $ARGV[0] ne "-d")) {
|
|
|
|
print "Usage:\n".
|
|
|
|
" cd open-zwave\n".
|
|
|
|
" perl .../contrib/zwave_configconvert.pl config |\n".
|
|
|
|
" gzip > .../FHEM/lib/openzwave_deviceconfig.xml.gz\n".
|
|
|
|
"or\n".
|
|
|
|
" cd open-zwave\n".
|
|
|
|
" gzip -d < .../FHEM/lib/openzwave_deviceconfig.xml.gz |\n".
|
|
|
|
" perl .../contrib/zwave_configconvert.pl -d\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($ARGV[0] eq "-d") {
|
|
|
|
while(my $l = <STDIN>) {
|
|
|
|
next if($l !~ m/<Product sourceFile="([^"]*)"/);
|
|
|
|
my $f = $1;
|
|
|
|
next if(-f "config/$f");
|
|
|
|
print("Creating: config/$f\n");
|
|
|
|
open(FH, ">config/$f") || die("open config/$f: $!\n");
|
|
|
|
print FH $l;
|
|
|
|
while($l = <STDIN>) {
|
|
|
|
print FH $l;
|
|
|
|
last if($l =~ m,</Product>,);
|
|
|
|
}
|
|
|
|
close(FH);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
2014-10-05 17:28:09 +00:00
|
|
|
|
|
|
|
print '<?xml version="1.0" encoding="utf-8"?>', "\n";
|
|
|
|
print "<ProductList>\n";
|
|
|
|
foreach my $file (`find $ARGV[0] -name \*.xml`) {
|
|
|
|
chomp($file);
|
|
|
|
my $name = $file;
|
|
|
|
$name =~ s+.*config/++;
|
|
|
|
next if($name !~ m+/+); # Only files from subdirs
|
|
|
|
open(FH, $file) || die("$file:$!\n");
|
|
|
|
my $buffer="";
|
|
|
|
while(my $l = <FH>) {
|
|
|
|
next if($l =~ m/^<\?xml/);
|
|
|
|
chomp($l);
|
2015-03-28 20:32:59 +00:00
|
|
|
$l =~ s/^<Product.*xmlns.*/<Product sourceFile="$name">/;
|
2014-10-05 17:28:09 +00:00
|
|
|
$l =~ s/\r//g;
|
2015-03-28 20:32:59 +00:00
|
|
|
$l =~ s/\t/ /g;
|
|
|
|
#$l =~ s/^ *//g;
|
|
|
|
$l =~ s/ *$//g;
|
2014-10-05 17:28:09 +00:00
|
|
|
next if($l eq "");
|
2015-05-27 07:50:51 +00:00
|
|
|
if($l !~ m/>$/ || $l =~ m/^\s*<Help>\s*$/) { $buffer .= " ".$l; next; }
|
2014-10-05 17:28:09 +00:00
|
|
|
if($buffer && $l =~ m/>$/) { $l = "$buffer $l"; $buffer=""; }
|
|
|
|
$l =~ s/<!--.*-->//g;
|
2015-03-28 20:32:59 +00:00
|
|
|
$l =~ s/ *$//g;
|
|
|
|
print $l,"\n" if($l);
|
2014-10-05 17:28:09 +00:00
|
|
|
}
|
|
|
|
close(FH);
|
|
|
|
print $buffer if($buffer);
|
2015-03-28 20:32:59 +00:00
|
|
|
print "\n"; # One empty line between products
|
2014-10-05 17:28:09 +00:00
|
|
|
}
|
|
|
|
print "</ProductList>\n";
|