Web: Group online demo report by line numbers

This commit is contained in:
Tim Gerundt 2012-05-27 15:41:18 +02:00
parent fdfa6444ea
commit 33edf63085
2 changed files with 36 additions and 7 deletions

View File

@ -39,7 +39,7 @@
* @param string $code Source code
* @return string Output lines
*/
function get_democlient_outout($code) {
function get_democlient_output($code) {
$postdata = http_build_query(
array(
'code' => $code
@ -59,6 +59,28 @@
return file('http://cppcheck.sourceforge.net/cgi-bin/democlient.cgi', false, $context);
}
/**
* ...
* @param array $output Output lines
* @return array Parsed output
*/
function parse_democlient_output($output) {
$parsed = array();
foreach ($output as $line) { //for each output line...
$line = trim($line);
if (empty($line)) { //if empty line...
continue;
}
preg_match('/\[test.c:(\d+)\]: (.*)/', $line, $matches);
$lineNumber = $matches[1];
$result = $matches[2];
if (!empty($lineNumber) && !empty($result)) { //if complete result...
$parsed[$lineNumber][] = $result;
}
}
return $parsed;
}
function cut_string($string, $length = 1024) {
if (strlen($string) > $length) {
return substr($string, 0, $length);
@ -82,14 +104,17 @@
echo "<h3>Output</h3>\n";
$lines = get_democlient_outout($code);
foreach ($lines as $line) { //for each output line...
$line = trim($line);
if (empty($line)) { //if empty line...
continue;
$output = get_democlient_output($code);
$report = parse_democlient_output($output);
echo "<dl>\n";
foreach ($report as $lineNumber => $results) { //for each line results...
echo " <dt>Line $lineNumber:</dt>\n";
foreach ($results as $result) { //for each results...
echo " <dd>" . htmlspecialchars($result) . "</dd>\n";
}
echo "<p>" . htmlspecialchars($line) . "</p>\n";
}
echo "</dl>\n";
}
else {
echo "<p>Use the <a href=\"/demo/\">online demo</a> page to create the report.</p>\n";

View File

@ -6,6 +6,10 @@ body {
background: #eee;
}
dt {
font-weight:bold;
}
/* Default link style */
a:link { color:#036; text-decoration:underline; }
a:visited { color:#036; text-decoration:underline; }