function deldir($dir){ $current_dir = opendir($dir); while($entryname = readdir($current_dir)){ if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){ deldir("${dir}/${entryname}"); }elseif($entryname != "." and $entryname!=".."){ unlink("${dir}/${entryname}"); } } closedir($current_dir); rmdir(${dir}); } ?>
![]() |
Virtual Simulator: Results |
|
|
//This script submits jobs to cascade and makes the output look a bit prettier //Michael Rushton 2003 $base_filename = tempnam("/home/web/website/teaching/virtualsimulator/cache/",""); //create temporary directory for input and output files unlink($base_filename); mkdir($base_filename,0777); chdir($base_filename); $input_filename = "input.cas"; $output_filename ="output.res"; $cascade_input = fopen($input_filename,"w"); //The input from the text area seems to contain carriage returns \r, as well as \n //For cascade to accept the input it is necessary to get rid of the \r $textContents = eregi_replace("\r","",$_POST['textarea']); fwrite($cascade_input,$textContents); fclose($cascade_input); //Submit the job system("cascade < $input_filename > $output_filename"); //Display the cascade output $cascade_output = fopen($output_filename, "r"); $data = fread($cascade_output, filesize($output_filename)); fclose($cascade_output); $lines = explode("\n", $data); $highlight_colour = "#0066FF"; $error_colour = "#CB3A18"; $warning_colour = "#EC891D"; //Make the text monospaced, so it doesn't look rubbish echo " \n"; foreach($lines as $line){ if(eregi("ERROR",$line)){ $line = "$line"; } elseif (eregi("(WARNING)|(EXCESSIVE)",$line)){ $line = "$line"; } elseif (eregi("\%",$line)){ $line = "$line"; } //Add a line break $line = $line . "\n"; echo $line; } echo "\n"; //Get rid of temp files deldir($base_filename); ?> |