From 543c5f40443e5396fbd64d5a9ad086cdf3e65c8d Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Wed, 3 Jul 2013 16:05:49 +0200 Subject: [PATCH] include figure cleaned up, include file selector working, circular dependencies are supressed --- xml_spielwiese/cgitest.pl | 100 ++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 32 deletions(-) diff --git a/xml_spielwiese/cgitest.pl b/xml_spielwiese/cgitest.pl index b7409c4..8bbbf0d 100755 --- a/xml_spielwiese/cgitest.pl +++ b/xml_spielwiese/cgitest.pl @@ -1,6 +1,11 @@ #!/usr/bin/perl -w print "Content-type: text/html\n\n"; +# TODO +# do not accept "..." as input file +# what happens when files are not writable? + + my $me = "cgitest.pl"; use strict; @@ -79,7 +84,7 @@ if ( $cgiHash{'print'} eq 'fileSelection' ) { if ( $cgiHash{'print'} eq 'spectree' ) { print "
Available Settings
\n"; parseSetAndSpec( $cgiHash{'configFile'} ); -"
specifications loaded from $specfileName
"; + print "
specifications loaded from $specfileName
"; print_registers($specfile); } @@ -87,21 +92,12 @@ if ( $cgiHash{'print'} eq 'spectree' ) { if ( $cgiHash{'print'} eq 'settree' ) { print "
Selected Settings
\n"; parseSetAndSpec( $cgiHash{'configFile'} ); - buildAncestry($setfileName); + buildAncestry($setfileName,""); #arg1: target file, # arg2: recursion parent target file # assignFieldColors();#obsolete $settree = $ancestryTree; # not so elegant - print ""; - print ""; - print ""; - print ""; - print "
"; print_ancestorInfo(); - print "
"; - print -"
you are editing
$setfileName
"; - print "
"; print_registers($setfile); } @@ -169,13 +165,13 @@ sub createFile { sub print_ancestorInfo { print "
"; - print "inherit settings from:
"; + #print "my ancestry:
"; + print "
"; + #print "
"; if (@ancestryList) { # if ancestry is not empty, print current ancestry as a nested table # and also a button that can unlink the heritage - print ""; + if ($fileLevelHash{$ancestor} eq "1"){ + print < X  +EOF + + } + print "
"; - my $tableNestingDepth = @ancestryList; for my $ancestor ( reverse(@ancestryList) ) { print ""; @@ -183,18 +179,26 @@ sub print_ancestorInfo { } for my $ancestor (@ancestryList) { - print "$ancestor
"; + print "$ancestor
"; } + } + else { # print an ancestor selector! + print "include settings from:
"; + print_fileSelector( "", "ancestorSelector", + "changeAncestor(this.options[this.selectedIndex].text)" ); - print "
"; - print <
 X 
-EOF - print "
"; - } else { # print an ancestor selector! - print_fileSelector("","ancestorSelector","changeAncestor(this.options[this.selectedIndex].text)"); - } + #print ""; + print ""; + print "$setfileName"; + print ""; print "
"; } @@ -223,17 +227,47 @@ sub parseSet { sub buildAncestry { # recursive my $xmlfileName = $_[0]; + my $parentXmlFileName = $_[1]; if ( $xmlfileName eq "" ) { return; } + + if ($parentXmlFileName eq $xmlfileName) { + print "

It's a bad idea to try to include yourself!

"; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; + } + + for (@ancestryList){ # suppres circular dependencies! + if ($xmlfileName eq $_) { + + + print "

No circular includes, please!

"; + print "

"; + print $parentXmlFileName."->".join("->",@ancestryList)."->".$setfileName; + print "

"; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; + #die "no circular includes please! $!"; + return; + } + } + + + + my $xmlfile = $confDir . "/" . $xmlfileName; my $xmltree; if ( $xmlfile eq $setfile ) { $xmltree = $settree; } else { - - # we got an ancestor here + # we got an ancestor here, write him to the ancestor list + unshift( @ancestryList, $xmlfileName ); $xmltree = $parser->parse_file($xmlfile); # tag all the fields with an heritage attribute @@ -247,8 +281,7 @@ sub buildAncestry { # recursive unless ( $ancestorFileName eq "" ) { # this block is executed when an ancestor is found - buildAncestry($ancestorFileName); # recursion - push( @ancestryList, $ancestorFileName ); + buildAncestry($ancestorFileName,$xmlfileName); # recursion, second argument is the target file from THIS parent recursion call #integrate the current tree into the ancestryTree, overwrite older settings mergeTrees( $ancestryTree, $xmltree ); @@ -359,11 +392,14 @@ sub del { sub print_fileSelector { my $configFile = $_[0]; - my $elementId = $_[1]; - my $action = $_[2]; + my $elementId = $_[1]; + my $action = $_[2]; opendir( DIR, $confDir ) or die $!; - print ''; print ""; my @xmlfiles; @@ -425,13 +461,13 @@ sub print_fileSelection { print ""; print ""; print ""; - print ""; print ""; print ""; print "
select config file:"; + print "selected config file:"; print "
"; - print_fileSelector($configFile,"fileSelector","loadFile()"); + print_fileSelector( $configFile, "fileSelector", "loadFile()" ); print ""; -- 2.43.0