Online Demo Report

$code ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); return file_get_contents('http://cppcheck.sourceforge.net/cgi-bin/democlient.cgi', false, $context); } /** * ... * @param string $output Output lines * @return array Parsed output */ function parse_democlient_output($output) { try { $parsed = array(); $xml = simplexml_load_string($output); foreach ($xml->errors->error as $error) { //for all errors... $msg = (string)$error->attributes()->msg; $line = (string)$error->location->attributes()->line; if (!empty($msg) && !empty($line)) { //if complete error... $parsed[$line][] = $msg; } } return $parsed; } catch (Exception $ex) { return array(); } } function cut_string($string, $length = 1024) { if (strlen($string) > $length) { return substr($string, 0, $length); } return $string; } if ($isCodePosted) { //if code posted... include_once '../../site/geshi/geshi.php'; $code = cut_string($_POST['code']); $geshi = new GeSHi($code, 'cpp'); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_PRE_TABLE); $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_overall_class('geshicode'); echo "

Input

\n"; echo $geshi->parse_code(); echo "

Output

\n"; $output = get_democlient_output($code); $report = parse_democlient_output($output); echo "
\n"; foreach ($report as $lineNumber => $results) { //for each line results... echo "
Line $lineNumber:
\n"; foreach ($results as $result) { //for each results... echo "
" . htmlspecialchars($result) . "
\n"; } } echo "
\n"; } else { echo "

Use the online demo page to create the report.

\n"; } ?>