From: Sebastien D. <sde...@us...> - 2005-06-10 14:50:40
|
Update of /cvsroot/tslogparser/tslogparser/admin/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26318 Modified Files: tahi.mod.php Log Message: tahi.mod.php to be continued... Index: tahi.mod.php =================================================================== RCS file: /cvsroot/tslogparser/tslogparser/admin/modules/tahi.mod.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- tahi.mod.php 10 Jun 2005 12:45:43 -0000 1.1 +++ tahi.mod.php 10 Jun 2005 14:50:32 -0000 1.2 @@ -79,7 +79,78 @@ */ + +/* The following function parses the file $complete_path/INDEX and saves the + result into $tahi_tree. It returns TRUE on success and FALSE on failure. */ +function parse_INDEX(&$tahi_tree, $complete_path, $debug) +{ + /* The format of $tahi_tree is as follows: */ + + + if ($debug) + echo "parse_INDEX($complete_path)\n"; + + /* Read the file */ + $fichier = file($complete_path."/INDEX"); + + $hierarchy = "default"; + + /* Browse the file content */ + foreach ($fichier as $ligne) + { + /* Strip empty lines */ + if (!($ligne = trim($ligne))) + continue; + + /* Strip comments -- files starting with # or // as their first non-blank characters */ + if (preg_match("/^(#|\/\/)/", $ligne)) + continue; + + $match = FALSE; + //if ($debug) + // echo htmlentities($ligne)."\n"; + + /* The format should be either + &print:<B>(test category hierarchy)</B> + or + (file):(anything):(anything):(anything):(test name): + */ + $regs=array(); + if (preg_match("/^&print:\s*<B>(.*)\<\/B>$/", $ligne, $regs)) + { + $match = TRUE; + //if ($debug) + // echo "Hierarchy: ".htmlentities($regs[1])."\n"; + $hierarchy = str_replace(" ", " ", trim(strip_tags($regs[1]))); + + /* We are looking for hierarchical information: + n. <blablah> => level 1 + n.m. <blablah> => level 2 + (n) <blabla> => sublevel + */ + + // TEMP: at this time, we only keep the top of the stack + $tahi_tree[]=array( + "hierarchy" => $hierarchy + "tests" => array() + ); + } + + if (preg_match("/^([^:]+):[^:]*:[^:]*:[^:]*:([^:]+):?$/",$ligne,$regs)) + { + $match = TRUE; + //if ($debug) + // echo "Test info: ".htmlentities($regs[1]." => ".$regs[2])."\n"; + } + + if (!$match) + echo "Ignored the following line: ".htmlentities($ligne)."\n"; + } + + return FALSE; +} + class tahi { /* @@ -121,13 +192,64 @@ if ( $parent->debug ) echo "tahi->TS_parse($TS_name, $TS_description, $path)\n"; - /* Check the directory contains a coherent structure */ + $tahi_tree=array(); + $found=FALSE; + + /* Check the directory contains a coherent structure + We are looking for a file something/INDEX -- and are interested + in this something :) + + We browse each subdirectory until we find the file we + are looking for... + */ + + if (!is_dir($path) || !($dh = opendir($path))) + { + $parent->last_error="Directory '$path' is not readable -- check your archive format.\n"; + return FALSE; + } + + while (($file = readdir($dh)) !== false) + { + if (($file == ".") || ($file == "..") || ($file == "CVS") || !is_dir($path."/".$file)) + continue; + + $dh2 = opendir($path."/".$file); + if (!$dh2) + { + $parent->last_error= "Failed to open directory $path/$file for reading.\n"; + return FALSE; + } + + while (($file2 = readdir($dh2)) !== false) + { + if ($file2 != "INDEX") + continue; + + $found = TRUE; + + /* Now we found the file we were looking for: $path/$file/INDEX */ + if (! parse_INDEX($tahi_tree, $path."/".$file, $parent->debug)) + { + $parent->last_error= "Parsing of INDEX failed\n"; + return FALSE; + } + + } + closedir ($dh2); + } + closedir($dh); + + if (!$found) + { + $parent->last_error="Directory '$path' does not contain a file */INDEX -- unable to parse.\n"; + return FALSE; + } - /* Open and browse the tree */ /* We've parsed the whole tree */ if ($parent->debug > 1) - print_r($opts_tree); + print_r($tahi_tree); /* The database shall be initialized here */ if (!is_db_init()) |