2012-09-18 18:51:47 +02:00
|
|
|
<?php
|
|
|
|
$isCodePosted = isset($_POST['code']) && !empty($_POST['code']);
|
|
|
|
$isXmlOutput = isset($_POST['xml']) && $_POST['xml'] == '1';
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
* @param string $code Source code
|
|
|
|
* @return string Output lines
|
|
|
|
*/
|
|
|
|
function get_democlient_output($code) {
|
|
|
|
$postdata = http_build_query(
|
|
|
|
array(
|
|
|
|
'code' => $code
|
|
|
|
)
|
|
|
|
);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
$opts = array('http' =>
|
|
|
|
array(
|
|
|
|
'method' => 'POST',
|
|
|
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
|
|
|
'content' => $postdata
|
|
|
|
)
|
|
|
|
);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
$context = stream_context_create($opts);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
return @file_get_contents('http://cppcheck.sourceforge.net/cgi-bin/democlient.cgi', false, $context);
|
|
|
|
}
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
function cut_string($string, $length = 1024) {
|
|
|
|
if (strlen($string) > $length) {
|
|
|
|
return substr($string, 0, $length);
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
// XML output...
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
if ($isXmlOutput) { //if XML output...
|
|
|
|
header('Content-Type: text/xml');
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
if (!$isCodePosted) { //if NO code posted...
|
|
|
|
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results></results>\n";
|
|
|
|
exit;
|
|
|
|
}
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
$output = get_democlient_output(cut_string($_POST['code']));
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
if ($output === false) { //if NO demo client output...
|
|
|
|
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results></results>\n";
|
|
|
|
exit;
|
|
|
|
}
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 18:51:47 +02:00
|
|
|
echo $output;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
?>
|
2012-05-20 14:21:17 +02:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
|
|
<title>Online Demo Report - Cppcheck</title>
|
2012-09-26 13:44:45 +02:00
|
|
|
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Orbitron&text=Cppcheck" />
|
2012-11-29 16:02:25 +01:00
|
|
|
<link rel="stylesheet" type="text/css" href="/site/css/pack.css" />
|
2012-05-20 14:21:17 +02:00
|
|
|
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
|
2013-07-06 17:13:25 +02:00
|
|
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
|
2013-07-31 13:39:39 +02:00
|
|
|
<script type="text/javascript">
|
|
|
|
//<![CDATA[
|
|
|
|
window.jQuery || document.write('<script type="text/javascript" src="/site/js/jquery-1.10.2.min.js"><\/script>')
|
|
|
|
//]]>
|
|
|
|
</script>
|
2012-11-29 16:02:25 +01:00
|
|
|
<script src="/site/js/pack.js" type="text/javascript"></script>
|
2013-10-12 16:26:57 +02:00
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("#resultsTable").tableFilter();
|
|
|
|
});
|
|
|
|
</script>
|
2012-05-20 14:21:17 +02:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="header">
|
|
|
|
<div class="wrap">
|
2013-07-18 17:34:28 +02:00
|
|
|
<h1><a href="/">Cppcheck</a></h1>
|
2012-05-20 14:21:17 +02:00
|
|
|
<p>A tool for static C/C++ code analysis</p>
|
|
|
|
</div> <!-- .wrap -->
|
|
|
|
</div> <!-- #header -->
|
|
|
|
<div id="tabs">
|
|
|
|
<div class="wrap">
|
|
|
|
<ul>
|
|
|
|
<li><a href="/">Home</a></li>
|
|
|
|
<li><a href="http://sourceforge.net/apps/mediawiki/cppcheck/">Wiki</a></li>
|
|
|
|
<li><a href="http://sourceforge.net/apps/phpbb/cppcheck/">Forum</a></li>
|
2012-07-12 21:24:46 +02:00
|
|
|
<li><a href="http://sourceforge.net/apps/trac/cppcheck/">Issues</a></li>
|
2012-05-20 14:21:17 +02:00
|
|
|
<li><a href="/devinfo/" title="Developer Information">Developer Info</a></li>
|
|
|
|
<li><em><a href="/demo/">Online Demo</a></em></li>
|
|
|
|
<li><a href="http://sourceforge.net/projects/cppcheck/">Project page</a></li>
|
|
|
|
</ul>
|
|
|
|
</div> <!-- .wrap -->
|
|
|
|
</div> <!-- #tabs -->
|
|
|
|
<div id="content">
|
|
|
|
<div class="wrap">
|
|
|
|
<h2>Online Demo Report</h2>
|
|
|
|
<?php
|
2012-05-27 15:41:18 +02:00
|
|
|
/**
|
|
|
|
* ...
|
2012-06-02 13:56:45 +02:00
|
|
|
* @param string $output Output lines
|
2012-05-27 15:41:18 +02:00
|
|
|
* @return array Parsed output
|
|
|
|
*/
|
|
|
|
function parse_democlient_output($output) {
|
2012-06-02 13:56:45 +02:00
|
|
|
try {
|
|
|
|
$parsed = array();
|
|
|
|
$xml = simplexml_load_string($output);
|
|
|
|
foreach ($xml->errors->error as $error) { //for all errors...
|
2012-06-02 15:38:33 +02:00
|
|
|
$severity = (string)$error->attributes()->severity;
|
2012-06-02 13:56:45 +02:00
|
|
|
$msg = (string)$error->attributes()->msg;
|
|
|
|
$line = (string)$error->location->attributes()->line;
|
2012-06-02 15:38:33 +02:00
|
|
|
if (!empty($severity) && !empty($msg) && !empty($line)) { //if complete error...
|
|
|
|
$parsed[] = array('severity' => $severity, 'msg' => $msg, 'line' => $line);
|
2012-06-02 13:56:45 +02:00
|
|
|
}
|
2012-05-27 15:41:18 +02:00
|
|
|
}
|
2012-06-02 13:56:45 +02:00
|
|
|
return $parsed;
|
|
|
|
}
|
|
|
|
catch (Exception $ex) {
|
|
|
|
return array();
|
2012-05-27 15:41:18 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-20 14:21:17 +02:00
|
|
|
if ($isCodePosted) { //if code posted...
|
2012-05-21 19:52:01 +02:00
|
|
|
include_once '../../site/geshi/geshi.php';
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-27 14:32:52 +02:00
|
|
|
$code = cut_string($_POST['code']);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-27 14:32:52 +02:00
|
|
|
$geshi = new GeSHi($code, 'cpp');
|
2012-05-23 19:34:18 +02:00
|
|
|
$geshi->enable_classes();
|
2012-05-21 19:52:01 +02:00
|
|
|
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
|
|
|
|
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
|
|
|
|
$geshi->set_overall_class('geshicode');
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-20 14:21:17 +02:00
|
|
|
echo "<h3>Input</h3>\n";
|
2012-05-21 19:52:01 +02:00
|
|
|
echo $geshi->parse_code();
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-20 14:21:17 +02:00
|
|
|
echo "<h3>Output</h3>\n";
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-05-27 15:41:18 +02:00
|
|
|
$output = get_democlient_output($code);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 15:21:14 +02:00
|
|
|
if (!$output === false) {
|
|
|
|
$results = parse_democlient_output($output);
|
2012-09-24 21:40:00 +02:00
|
|
|
|
2012-09-18 15:21:14 +02:00
|
|
|
if (!empty($results)) {
|
|
|
|
echo "<table id=\"resultsTable\">\n";
|
|
|
|
echo "<thead>\n";
|
|
|
|
echo " <tr><th class=\"center\" filter-type=\"ddl\">Line</th><th class=\"center\" filter-type=\"ddl\">Severity</th><th>Message</th></tr>\n";
|
|
|
|
echo "</thead>\n";
|
|
|
|
echo "<tbody>\n";
|
|
|
|
foreach ($results as $result) { //for each result...
|
|
|
|
echo " <tr><td class=\"center\">" . htmlspecialchars($result['line']) . "</td><td class=\"center\">" . htmlspecialchars($result['severity']) . "</td><td>" . htmlspecialchars($result['msg']) . "</td></tr>\n";
|
|
|
|
}
|
|
|
|
echo "</tbody>\n";
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "<p>No errors found.</p>\n";
|
2012-05-20 14:21:17 +02:00
|
|
|
}
|
2012-06-02 15:38:33 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-09-18 15:21:14 +02:00
|
|
|
echo "<p>Problem with demo client. Please try again.</p>\n";
|
2012-05-20 14:21:17 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-18 15:21:14 +02:00
|
|
|
else { //if NO code posted...
|
2012-05-20 14:21:17 +02:00
|
|
|
echo "<p>Use the <a href=\"/demo/\">online demo</a> page to create the report.</p>\n";
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</div> <!-- .wrap -->
|
|
|
|
</div> <!-- #content -->
|
2013-08-01 09:35:52 +02:00
|
|
|
<?php include_once("../../analyticstracking.php") ?>
|
2012-05-20 14:21:17 +02:00
|
|
|
</body>
|
|
|
|
</html>
|