Web: Demo client use now XML output

This commit is contained in:
Tim Gerundt 2012-06-02 13:56:45 +02:00
parent 33edf63085
commit ca9acc7ede
1 changed files with 15 additions and 14 deletions

View File

@ -56,29 +56,30 @@
$context = stream_context_create($opts); $context = stream_context_create($opts);
return file('http://cppcheck.sourceforge.net/cgi-bin/democlient.cgi', false, $context); return file_get_contents('http://cppcheck.sourceforge.net/cgi-bin/democlient.cgi', false, $context);
} }
/** /**
* ... * ...
* @param array $output Output lines * @param string $output Output lines
* @return array Parsed output * @return array Parsed output
*/ */
function parse_democlient_output($output) { function parse_democlient_output($output) {
$parsed = array(); try {
foreach ($output as $line) { //for each output line... $parsed = array();
$line = trim($line); $xml = simplexml_load_string($output);
if (empty($line)) { //if empty line... foreach ($xml->errors->error as $error) { //for all errors...
continue; $msg = (string)$error->attributes()->msg;
} $line = (string)$error->location->attributes()->line;
preg_match('/\[test.c:(\d+)\]: (.*)/', $line, $matches); if (!empty($msg) && !empty($line)) { //if complete error...
$lineNumber = $matches[1]; $parsed[$line][] = $msg;
$result = $matches[2]; }
if (!empty($lineNumber) && !empty($result)) { //if complete result...
$parsed[$lineNumber][] = $result;
} }
return $parsed;
}
catch (Exception $ex) {
return array();
} }
return $parsed;
} }
function cut_string($string, $length = 1024) { function cut_string($string, $length = 1024) {