# build ancestry without ancestry tree outside
+# find a solution for fileLevel <=6
+
# DONE
# do not include wrong type, different specfile
# some global variables
-my $parser = XML::LibXML->new();
-my $specFile = "";
-my $configFile = "";
-my $specFileName = "";
-my $configFileName = "";
-my $specTree;
-my $configTree;
-my $configMapsType;
+our $parser = XML::LibXML->new();
+our $specFile = "";
+our $configFile = "";
+our $specFileName = "";
+our $configFileName = "";
+our $specTree;
+our $configTree;
+our $configMapsType;
-my %fileLevelHash;
+our %fileLevelHash;
-my $ancestryTree;
-my @ancestryList;
+our $ancestryTree;
+our @ancestryList;
-my $confDir = '../config';
-my $specDir = '../specs';
+our $confDir = '../config';
+our $specDir = '../specs';
# end of global variables
exit;
}
parseConfigAndSpec( $cgiHash{'configFile'} );
- buildAncestry( $configFileName, "" )
- ; #arg1: target file, # arg2: recursion parent target file
+
+
+
+## obsolete
+# buildAncestry( $configFileName, "" )
+# ; #arg1: target file, # arg2: recursion parent target file
+#
+# $configTree = $ancestryTree; # not so elegant
+## now use:
- # assignFieldColors();#obsolete
+ integrateAncestry();
- $configTree = $ancestryTree; # not so elegant
+
print_ancestorInfo();
print_registers($configFile);
## xml file operations
###############################
-sub deleteFile {
+sub deleteFile {
my $configFileName = $_[0];
my $configFile = $confDir . "/" . $configFileName;
unless ( -e $configFile ) {
unlink($configFile);
print "<p>config file was deleted</p>";
}
+#args:configFileName #globs:$confDir
-sub createFile {
+sub createFile {
my $configFileName = $_[0];
my $specFileName = $_[1]; #config file is based on this specification!
close SCHREIBEN;
}
+#args: configFileName,specFileName #globs:$confDir,$specDir,$parser
-sub parseConfigAndSpec {
+sub parseConfigAndSpec {
parseConfig( $_[0] );
$specFileName = $configTree->findvalue("/MAPS/\@specDbFile");
$specFile = $specDir . "/" . $specFileName;
}
$specTree = $parser->parse_file($specFile);
}
+#args: configFileName #globs: $specFileName,$configTree,$specFile,$specDir,$specTree,$parser #calls: parseConfig()
-sub parseConfig {
+sub parseConfig {
$configFileName = $_[0];
$configFile = $confDir . "/" . $_[0];
$configTree = $parser->parse_file($configFile);
$configMapsType = $configTree->findvalue("/MAPS/\@type");
}
+#args: configFileName #globs: $confDir,$configTree,$parser,$configFile,$configMapsType,$configFileName
-sub buildAncestry { # recursive
+sub buildAncestry {
+ # the file for which the ancestry shall be built
my $xmlfileName = $_[0];
- my $parentXmlFileName = $_[1];
+ # the file that referred $xmlfileName as its ancestor
+ # should be "" if you start building the ancestry from the bottom
+ my $descendantXmlFileName = $_[1];
+
+ # no target file, no action!
if ( $xmlfileName eq "" ) {
return;
}
# check if you are not including yourself
- if ( $parentXmlFileName eq $xmlfileName ) {
+ if ( $descendantXmlFileName eq $xmlfileName ) {
print "<p>It's a bad idea to try to include yourself!</p>";
print "<p>The faulty include directive was removed.</p>";
print "<p><input type='button' onclick='loadFile()' value='back'></p>";
print "<p>No circular includes, please!</p>";
print "<p>";
- print $parentXmlFileName. "->"
+ print $descendantXmlFileName. "->"
. join( "->", @ancestryList ) . "->"
. $configFileName;
print "</p>";
mergeTrees( $ancestryTree, $xmltree );
}
else {
-
-# this block is called when you are at the root of the ancestry -> you are THE Father
+# this block is called when you are at the root of the ancestry -> you are THE father
# begin the ancestry tree
-
$ancestryTree = $xmltree;
}
+}
+# args: xmlfileName,
+# parentXmlFileName
+# globs: @ancestryList,
+# $ancestryTree,
+# $configFileName,
+# $confDir,
+# $configTree,
+# $configMapsType,
+# %fileLevelHash
+
+# calls: changeAncestor(),
+# mergeTrees()
+
+# usage: buildAncestry($configFile,""), do not use directly, use integrateAncestry()!
+# description: recursively adds the contents of the ancestor files of $configFile to $ancestryTree
+
+
+sub integrateAncestry {
+
+ buildAncestry($configFileName,"");
+
my $counter = 1;
for my $file ( reverse(@ancestryList) ) {
$fileLevelHash{$file} = $counter;
$counter++;
}
}
-
+
+ $configTree = $ancestryTree;
}
+# globs: @ancestryList,%fileLevelHash,$configFileName,$configTree,$ancestryTree
+# description: this function extends $configTree to include all information that is held
+# by its ancestor (and ancestor's ancestor ... and so on)
sub del {
print SCHREIBEN $xmltree->toString();
close SCHREIBEN;
}
+# args: registerName,fieldName,
+# globs: $configFile,$configTree
+# description: deletes field "fieldName" in register "registerName" in $configFile
+
+
+sub save {
+
+ my $registerName = $_[0];
+ my $fieldName = $_[1];
+ my $xmlfile = $configFile;
+ my $newValue = $_[2];
+
+ my $xmltree = $configTree;
+ my $maps = $xmltree->findnodes("/MAPS")->shift();
+ my $register =
+ $xmltree->findnodes( "/MAPS/register[\@name='" . $registerName . "']" )
+ ->shift();
+
+ if ( $register eq "" ) {
+ $register = $maps->addNewChild( "", "register" );
+ $register->setAttribute( "name", $registerName );
+ }
+
+ my $field =
+ $xmltree->findnodes( "/MAPS/register[\@name='"
+ . $registerName
+ . "']/field[\@name='"
+ . $fieldName
+ . "']" )->shift();
+
+ if ( $field eq "" ) {
+ $field = $register->addNewChild( "", "field" );
+ $field->setAttribute( "name", $fieldName );
+
+ }
+
+ $field->setAttribute( "value", $newValue );
+ print $field->findvalue("./\@value");
+ open( SCHREIBEN, "> $xmlfile" )
+ or print "could not open file $xmlfile for writing: $!\n";
+
+ print SCHREIBEN $xmltree->toString();
+ close SCHREIBEN;
+}
+# args: registerName,fieldName,newValue
+# globs: $configFile,$configTree,
+# description: saves value "newValue" in field "fieldName" in register "registerName" (in the $configFile)
+# if field or register does not exist yet, it is created.
+
+sub copyDefaultRegister {
+ my $registerName = $_[0];
+ #my $configTree = $parser->parse_file($configFile);
+ #my $specTree = $parser->parse_file($specFile);
+ my $configmaps = $configTree->findnodes("/MAPS")->shift();
+ my $specmaps = $specTree->findnodes("/MAPS")->shift();
+
+ my $specRegister =
+ $specTree->findnodes( "/MAPS/register[\@name='" . $registerName . "']" )
+ ->shift();
+
+ my $configRegister = $configmaps->addNewChild( "", "register" );
+ $configRegister->setAttribute( "name", $registerName );
+
+ my @specFields = $specRegister->findnodes("./field");
+
+ for my $specField (@specFields) {
+ my $fieldName = $specField->findvalue("./\@name");
+ my $fieldValue = $specField->findvalue("./\@defaultValue");
+ my $configField = $configRegister->addNewChild( "", "field" );
+ $configField->setAttribute( "name", $fieldName );
+ $configField->setAttribute( "value", $fieldValue );
+ print $configField->findvalue("./\@value");
+ }
+ open( SCHREIBEN, "> $configFile" )
+ or print "could not open file $configFile for writing: $!\n";
+
+ print SCHREIBEN $configTree->toString();
+ close SCHREIBEN;
+}
+# args: registerName
+# globs: $config
###############################
return $t;
}
-sub save {
-
- my $registerName = $_[0];
- my $fieldName = $_[1];
- my $xmlfile = $configFile;
- my $newValue = $_[2];
-
- my $xmltree = $configTree;
- my $maps = $xmltree->findnodes("/MAPS")->shift();
-
-#my @fields = $xmltree->findnodes("/MAPS/register[\@name='".$registerName."']/field[\@name='".$fieldName."']");
- my $register =
- $xmltree->findnodes( "/MAPS/register[\@name='" . $registerName . "']" )
- ->shift();
-
- if ( $register eq "" ) {
- $register = $maps->addNewChild( "", "register" );
- $register->setAttribute( "name", $registerName );
- }
-
- my $field =
- $xmltree->findnodes( "/MAPS/register[\@name='"
- . $registerName
- . "']/field[\@name='"
- . $fieldName
- . "']" )->shift();
-
- if ( $field eq "" ) {
- $field = $register->addNewChild( "", "field" );
- $field->setAttribute( "name", $fieldName );
-
- }
-
-#my $fieldValue = ($xmltree->findnodes("/MAPS/register[\@name='".$registerName."']/field[\@name='".$fieldName."']/\@name='value'"))[0];
-#print $fieldValue->findvalue("./");
- $field->setAttribute( "value", $newValue );
- print $field->findvalue("./\@value");
- open( SCHREIBEN, "> $xmlfile" )
- or print "could not open file $xmlfile for writing: $!\n";
-
- print SCHREIBEN $xmltree->toString();
- close SCHREIBEN;
-}
-
-sub copyDefaultRegister {
- my $registerName = $_[0];
- my $configTree = $parser->parse_file($configFile);
- my $specTree = $parser->parse_file($specFile);
- my $configmaps = $configTree->findnodes("/MAPS")->shift();
- my $specmaps = $specTree->findnodes("/MAPS")->shift();
-
- my $specRegister =
- $specTree->findnodes( "/MAPS/register[\@name='" . $registerName . "']" )
- ->shift();
-
- my $configRegister = $configmaps->addNewChild( "", "register" );
- $configRegister->setAttribute( "name", $registerName );
-
- my @specFields = $specRegister->findnodes("./field");
-
- for my $specField (@specFields) {
- my $fieldName = $specField->findvalue("./\@name");
- my $fieldValue = $specField->findvalue("./\@defaultValue");
- my $configField = $configRegister->addNewChild( "", "field" );
- $configField->setAttribute( "name", $fieldName );
- $configField->setAttribute( "value", $fieldValue );
- print $configField->findvalue("./\@value");
- }
- open( SCHREIBEN, "> $configFile" )
- or print "could not open file $configFile for writing: $!\n";
-
- print SCHREIBEN $configTree->toString();
- close SCHREIBEN;
-}
-
# a sorting directive for fields and registers
sub by_name {
my $a_name = $a->findvalue("./\@name");
}
}
-
sub read_input {
my $buffer;
my @pairs;