print "<div class='header'>Selected Settings</div>\n";
parseSetAndSpec( $cgiHash{'configFile'} );
buildAncestry($setfileName);
+ #only for debug
+ $settree = $ancestryTree;
print "<div class='ancestorInfo' align='center'>";
print "inherit settings from:<br>";
- print join("<br>",@ancestryList);
+ print join( "<br>", @ancestryList );
print "</div>";
print_registers($setfile);
}
$xmltree = $settree;
}
else {
+ # we got an ancestor here
$xmltree = $parser->parse_file($xmlfile);
+ # tag all the fields with an heritage attribute
+ for my $field ($xmltree->findnodes("//field")){
+ $field->setAttribute("isHeritageFrom","$xmlfileName");
+ }
}
-
- my $ancestorFileName = $xmltree->findvalue("/MAPS/\@inheritSettingsFrom") || "";
- unless ($ancestorFileName eq ""){
- buildAncestry($ancestorFileName);
- push(@ancestryList,$ancestorFileName);
+
+ my $ancestorFileName = $xmltree->findvalue("/MAPS/\@inheritSettingsFrom")
+ || "";
+ unless ( $ancestorFileName eq "" ) {
+
+ # this block is executed when an ancestor is found
+ buildAncestry($ancestorFileName); # recursion
+ push( @ancestryList, $ancestorFileName );
+
+ #integrate the current tree into the ancestryTree, overwrite older settings
+ mergeTrees( $ancestryTree, $xmltree );
}
-
+ else {
+
+# this block is called when you are at the root of the ancestry -> you are THE Father
+# begin the ancestry tree
+
+ $ancestryTree = $xmltree;
+ }
+
}
+sub mergeTrees
+{ # give me two trees, tree1 overwrites everything in tree0 and will consequently be integrated in tree0
+ my $tree0 = $_[0];
+ my $tree1 = $_[1];
+
+ my $maps0 = $tree0->findnodes("/MAPS")->shift();
+ my $maps1 = $tree1->findnodes("/MAPS")->shift();
+
+ my @registers0 = $tree0->findnodes("/MAPS/register");
+ my @registers1 = $tree1->findnodes("/MAPS/register");
+
+ for my $register1 (@registers1) {
+ my $registerName = $register1->findvalue("./\@name");
+ if ( $registerName eq "" ) {
+ die "registerName in tree1 undefined!";
+ }
+
+ # if current register does not exist in tree0, create it
+ my $register0 =
+ $maps0->findnodes( "./register[\@name='" . $registerName . "']" )
+ ->shift();
+ if ( $register0 eq "" ) {
+ $register0 = $maps0->addNewChild( "", "register" );
+ $register0->setAttribute( "name", $registerName );
+ }
+
+ my @fields1 = $register1->findnodes("./field");
+ for my $field1 (@fields1) {
+ my $fieldName = $field1->findvalue("./\@name");
+
+ # if field with same name exists in tree0/register0 delete it!
+ my $field0 =
+ $register0->findnodes( "./field[\@name='" . $fieldName . "'" );
+ unless ( $field0 eq "" ) {
+ $register0->removeChild($field0);
+ }
+
+ # copy current field from tree1/register1 to tree0/register0
+
+ $register0->addChild($field1);
+ }
+
+ }
+}
+
sub del {
my $registerName = $_[0];