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,30 +56,31 @@
$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) {
try {
$parsed = array(); $parsed = array();
foreach ($output as $line) { //for each output line... $xml = simplexml_load_string($output);
$line = trim($line); foreach ($xml->errors->error as $error) { //for all errors...
if (empty($line)) { //if empty line... $msg = (string)$error->attributes()->msg;
continue; $line = (string)$error->location->attributes()->line;
} if (!empty($msg) && !empty($line)) { //if complete error...
preg_match('/\[test.c:(\d+)\]: (.*)/', $line, $matches); $parsed[$line][] = $msg;
$lineNumber = $matches[1];
$result = $matches[2];
if (!empty($lineNumber) && !empty($result)) { //if complete result...
$parsed[$lineNumber][] = $result;
} }
} }
return $parsed; return $parsed;
} }
catch (Exception $ex) {
return array();
}
}
function cut_string($string, $length = 1024) { function cut_string($string, $length = 1024) {
if (strlen($string) > $length) { if (strlen($string) > $length) {