Exemple #1
0
function runProb()
{
    global $pname, $uOutput, $filename, $uDir, $pDir, $language, $inputFile, $input;
    $filename = "code";
    if (isset($pname)) {
        $filename = $pname;
    }
    // Write *input* file
    $userInputFile = $uDir . $filename . ".in";
    write2File($uDir, $userInputFile, $input);
    $tag = "pre";
    $uOutput = "";
    // User's test case
    $output = runCode($language, $filename, $userInputFile);
    $uOutput = $uOutput . "<tr><td><" . $tag . ">";
    $uOutput = $uOutput . $input;
    $uOutput = $uOutput . "</" . $tag . "></td>";
    $uOutput = $uOutput . "<td><" . $tag . ">";
    $uOutput = $uOutput . "Whatever you wanted it to output.";
    $uOutput = $uOutput . "</" . $tag . "></td>";
    $uOutput = $uOutput . "<td><" . $tag . ">";
    $uOutput = $uOutput . $output;
    $uOutput = $uOutput . "</" . $tag . "></td></tr>";
    // Go through all test cases
    /*
    $allTestCases = getDirectoryList($pDir."testCases/in/",false);
    foreach ($allTestCases as $t)
    {
    
    	// Read *input* file
    	$allTestCases = getDirectoryList($pDir."testCases/in/",false);
    	$inputFile = $pDir."/testCases/in/".($t);
    	$probInput = readCode($pDir,$inputFile);
    	// Read *output* file
    	$outputFile = $pDir."/testCases/out/".($t);
    	$probOutput = readCode($pDir,$outputFile);
    	// Run code
    	$output = runCode($language,$filename,$inputFile);
    	// Check if $output is equal to correct $probOutput
    	if ($output == $probOutput) { $s = "color:green;font-weight:bold;"; } else { $s = "color:red;font-style:italic;"; }
    	// Display data
    	$uOutput = $uOutput."<tr style='".$s."' ><td><".$tag.">";
    	$uOutput = $uOutput.$probInput;
    	$uOutput = $uOutput."</".$tag."></td>";
    	$uOutput = $uOutput."<td><".$tag.">";
    	$uOutput = $uOutput.$probOutput;
    	$uOutput = $uOutput."</".$tag."></td>";
    	$uOutput = $uOutput."<td><".$tag.">";
    	$uOutput = $uOutput.$output;		
    	$uOutput = $uOutput."</".$tag."></td></tr>";	
    }
    */
}
Exemple #2
0
     $code = preg_replace('#(\\r?\\n|\\r\\n?)#', $newLineBreak, $code);
 }
 ob_start();
 $memBefore = memory_get_usage(true);
 $start = microtime(true);
 $melodyPlugin = new MelodyPlugin();
 if ($melodyPlugin->isMelodyScript($code)) {
     if ($melodyPlugin->isScriptingSupported()) {
         $melodyPlugin->runScript($code, $options['bootstrap']);
     } else {
         throw new Exception('php-console misses required dependencies to run melody scripts.');
     }
 } else {
     // Important: replace only line by line, so the generated source lines will map 1:1 to the initial user input!
     $code = preg_replace('{^\\s*<\\?(php)?\\s*}i', '', $code);
     runCode($code, $options['bootstrap']);
 }
 // compare with peak, because regular memory could be free'd already
 $end = microtime(true);
 $memAfter = memory_get_peak_usage(true);
 $debugOutput .= ob_get_clean();
 if (isset($_GET['js'])) {
     header('Content-Type: text/plain');
     $memory = sprintf('%.3f', ($memAfter - $memBefore) / 1024.0 / 1024.0);
     // in MB
     $rendertime = sprintf('%.3f', ($end - $start) * 1000);
     // in ms
     header('X-Memory-Usage: ' . $memory);
     header('X-Rendertime: ' . $rendertime);
     echo $debugOutput;
     die('#end-php-console-output#');
function runProb()
{
    global $pname, $uOutput, $filename, $uDir, $pDir, $language, $inputFile, $input;
    $filename = "code";
    if (isset($pname)) {
        $filename = $pname;
    }
    // Write *input* file
    $userInputFile = $uDir . $filename . ".in";
    write2File($uDir, $userInputFile, $input);
    // Go through all test cases
    $uOutput = "";
    // User's test case
    $output = runCode($language, $filename, $userInputFile);
    $uOutput = $uOutput . "<tr><td><pre>";
    $uOutput = $uOutput . $input;
    $uOutput = $uOutput . "</pre></td>";
    $uOutput = $uOutput . "<td><pre>";
    $uOutput = $uOutput . "Whatever you wanted it to output.";
    $uOutput = $uOutput . "</pre></td>";
    $uOutput = $uOutput . "<td><pre>";
    $uOutput = $uOutput . $output;
    $uOutput = $uOutput . "</pre></td></tr>";
    // FOR EACH {
    //$output = runCode($language,$filename,$inputFile);
    // }
    /*
    <table border="1" id="output">
    	<tr>
    	<th>Input</th>
    	<th>Desired Output</th>
    	<th>Actual Output</th>
    	</tr>
    	<tr>
    	<td><pre><?PHP echo $probInput; ?></pre></td>
    	<td><pre><?PHP echo $probOutput; ?></pre></td>
    	<td><pre><?PHP echo $uOutput; ?></pre></td>
    	</tr>
    	<tr>
    	<td>Input2</td>
    	<td>Output2</td>
    	<td>UserOutput2</td>
    	</tr>
    	</table>
    */
}
 /**
  * @NoAdminRequired
  */
 public function code()
 {
     require_once 'shorten/lib/code.php';
     return runCode();
 }