]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
include figure cleaned up, include file selector working, circular dependencies are...
authorMichael Wiebusch <stratomaster@gmx.net>
Wed, 3 Jul 2013 14:05:49 +0000 (16:05 +0200)
committerMichael Wiebusch <stratomaster@gmx.net>
Wed, 3 Jul 2013 14:05:49 +0000 (16:05 +0200)
xml_spielwiese/cgitest.pl

index b7409c43567ad276a0a9a31a46ba57aa8df75d3d..8bbbf0d3f37caac42fe3f4f4fa29299f8b2d76ac 100755 (executable)
@@ -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 "<div class='header'>Available Settings</div>\n";
        parseSetAndSpec( $cgiHash{'configFile'} );
-"<div class='ancestorInfo' align='center'>specifications loaded from $specfileName</div>";
+       print "<div class='ancestorInfo' align='center'>specifications loaded from $specfileName</div>";
 
        print_registers($specfile);
 }
@@ -87,21 +92,12 @@ if ( $cgiHash{'print'} eq 'spectree' ) {
 if ( $cgiHash{'print'} eq 'settree' ) {
        print "<div class='header'>Selected Settings</div>\n";
        parseSetAndSpec( $cgiHash{'configFile'} );
-       buildAncestry($setfileName);
+       buildAncestry($setfileName,""); #arg1: target file, # arg2: recursion parent target file
 
        #       assignFieldColors();#obsolete
 
        $settree = $ancestryTree;    # not so elegant
-       print "<table><tr>";
-       print "<td>";
        print_ancestorInfo();
-       print "</td>";
-       print "<td style='border-right:1px solid #000000'><br></td>";
-       print "<td>";
-       print
-"<div align='center'>you are editing<br><table><tr class='fileLevel'><td>$setfileName</td></tr></table></div>";
-       print "</td>";
-       print "</tr></table>";
 
        print_registers($setfile);
 }
@@ -169,13 +165,13 @@ sub createFile {
 sub print_ancestorInfo {
        print "<div class='ancestorInfo' align='center'>";
 
-       print "inherit settings from:<br>";
+       #print "my ancestry:<br>";
+       print "<table class='fileLevel'><tr><td>";
+       #print "<table class='fileLevel1' padding=0 spacing=0><tr><td>";
        if (@ancestryList)
        {    # if ancestry is not empty, print current ancestry as a nested table
                    # and also a button that can unlink the heritage
 
-               print "<table class='fileLevel1'><tr><td>";
-
                my $tableNestingDepth = @ancestryList;
                for my $ancestor ( reverse(@ancestryList) ) {
                        print "<table class=fileLevel" . $fileLevelHash{$ancestor} . ">";
@@ -183,18 +179,26 @@ sub print_ancestorInfo {
                }
                for my $ancestor (@ancestryList) {
 
-                       print "$ancestor</td></tr></table>";
+                       print "$ancestor</td>";
+                       if ($fileLevelHash{$ancestor} eq "1"){
+                                               print <<EOF;
+<td class='button_move' title='unlink includes' onclick='changeAncestor("")'>&nbsp;X&nbsp;</td>
+EOF
+
+                       }
+                       print "</tr></table>";
                }
+       }
+       else {    # print an ancestor selector!
+               print "include settings from:<br>";
+               print_fileSelector( "", "ancestorSelector",
+                       "changeAncestor(this.options[this.selectedIndex].text)" );
 
-               print "</td><td valign='bottom'>";
-               print <<EOF;
-<table><tr><td class='button_move' onclick='changeAncestor("")'>&nbsp;X&nbsp;</td></tr></table>
-EOF
-               print "</td></tr></table>";
-       } else { # print an ancestor selector!
-                       print_fileSelector("","ancestorSelector","changeAncestor(this.options[this.selectedIndex].text)");
-                       
        }
+       #print "</td></tr></table>";
+       print "</td></tr><tr><td>";
+       print "$setfileName";
+       print "</td></tr></table>";
        print "</div>";
 }
 
@@ -223,17 +227,47 @@ sub parseSet {
 
 sub buildAncestry {    # recursive
        my $xmlfileName = $_[0];
+       my $parentXmlFileName = $_[1];
        if ( $xmlfileName eq "" ) {
                return;
        }
+       
+       if ($parentXmlFileName 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>";
+                       changeAncestor(""); # break the evil circle where it was closed!
+                       exit;
+       }
+       
+       for (@ancestryList){ # suppres circular dependencies!
+               if ($xmlfileName eq $_) {
+
+
+                       print "<p>No circular includes, please!</p>";
+                       print "<p>";
+                       print $parentXmlFileName."->".join("->",@ancestryList)."->".$setfileName;
+                       print "</p>";
+                       print "<p>The faulty include directive was removed.</p>";
+                       print "<p><input type='button' onclick='loadFile()' value='back'></p>";
+                       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 '<select name="fileSelectionDropdown" id="'.$elementId.'" onchange="'.$action.'">';
+       print '<select name="fileSelectionDropdown" id="'
+         . $elementId
+         . '" onchange="'
+         . $action . '">';
 
        print "<option value='...'>...</option>";
        my @xmlfiles;
@@ -425,13 +461,13 @@ sub print_fileSelection {
        print "<tr><td>";
        print "<table>";
        print "<tr>";
-       print "<td>select config file:<td>";
+       print "<td>selected config file:<td>";
        print "</tr>";
 
        print "<tr>";
 
        print "<td>";
-       print_fileSelector($configFile,"fileSelector","loadFile()");
+       print_fileSelector( $configFile, "fileSelector", "loadFile()" );
        print "</td>";
 
        print "<td>";