use File::Basename;
use Term::ANSIColor;
use Term::ANSIColor qw(:constants);
+use Cwd;
+use Sys::Hostname;
+use File::Basename;
my $Verbose = 0; # Verbose output from this script.
my $Prog = "scan-build";
my $UseColor = (defined $TERM and $TERM eq 'xterm-color' and -t STDOUT
and defined $ENV{'SCAN_BUILD_COLOR'});
+my $UserName = HtmlEscape(getpwuid($<) || 'unknown');
+my $HostName = HtmlEscape(hostname() || 'unknown');
+my $CurrentDir = HtmlEscape(getcwd());
+my $CurrentDirSuffix = basename($CurrentDir);
+
+my $CmdArgs;
+
+my $HtmlTitle;
+
+my $Date = localtime();
+
##----------------------------------------------------------------------------##
# Diagnostics
##----------------------------------------------------------------------------##
print OUT <<ENDTEXT;
<html>
<head>
+<title>${HtmlTitle}</title>
<style type="text/css">
body { color:#000000; background-color:#ffffff }
body { font-family: Helvetica, sans-serif; font-size:9pt }
- h3 { font-size:12pt }
+ h1 { font-size: 14pt; }
+ h2 { font-size: 12pt; }
table { font-size:9pt }
table { border-spacing: 0px; border: 1px solid black }
- table thead {
+ th, table thead {
background-color:#eee; color:#666666;
font-weight: bold; cursor: default;
text-align:center;
</script>
</head>
<body>
+<h1>${HtmlTitle}</h1>
+
+<table>
+<tr><th>User:</th><td>${UserName}\@${HostName}</td></tr>
+<tr><th>Working Directory:</th><td>${CurrentDir}</td></tr>
+<tr><th>Command Line:</th><td>${CmdArgs}</td></tr>
+<tr><th>Date:</th><td>${Date}</td></tr>
+ENDTEXT
+
+print OUT "<tr><th>Version:</th><td>${BuildName} (${BuildDate})</td></tr>\n"
+ if (defined($BuildName) && defined($BuildDate));
+
+print OUT <<ENDTEXT;
+</table>
ENDTEXT
if (scalar(@files)) {
else { $Totals{$key}->[0]++; }
}
- print OUT "<h3>Bug Summary</h3>";
+ print OUT "<h2>Bug Summary</h2>";
if (defined $BuildName) {
print OUT "\n<p>Results in this analysis run are based on analyzer build <b>$BuildName</b>.</p>\n"
print OUT <<ENDTEXT;
</table>
-<h3>Reports</h3>
+<h2>Reports</h2>
<table class="sortable" style="table-layout:automatic">
<thead><tr>
if (scalar(@files)) {
print OUT <<ENDTEXT;
-<h3>Analyzer Failures</h3>
+<h2>Analyzer Failures</h2>
<p>The analyzer had problems processing the following files:</p>
This is a convenience option; one can specify this
behavior directly using build options.
+ --html-title [title] - Specify the title used on generated HTML pages.
+ --html-title=[title] If not specified, a default title will be used.
+
--status-bugs - By default, the exit status of $Prog is the same as the
executed build command. Specifying this option causes the
exit status of $Prog to be 1 if it found potential bugs
ENDTEXT
}
+##----------------------------------------------------------------------------##
+# HtmlEscape - HTML entity encode characters that are special in HTML
+##----------------------------------------------------------------------------##
+
+sub HtmlEscape {
+ # copy argument to new variable so we don't clobber the original
+ my $arg = shift || '';
+ my $tmp = $arg;
+
+ $tmp =~ s/([\<\>\'\"])/sprintf("&#%02x;", chr($1))/ge;
+
+ return $tmp;
+}
+
+##----------------------------------------------------------------------------##
+# ShellEscape - backslash escape characters that are special to the shell
+##----------------------------------------------------------------------------##
+
+sub ShellEscape {
+ # copy argument to new variable so we don't clobber the original
+ my $arg = shift || '';
+ my $tmp = $arg;
+
+ $tmp =~ s/([\!\;\\\'\"\`\<\>\|\s\(\)\[\]\?\#\$\^\&\*\=])/\\$1/g;
+
+ return $tmp;
+}
+
##----------------------------------------------------------------------------##
# Process command-line arguments.
##----------------------------------------------------------------------------##
$HtmlDir = shift @ARGV;
next;
}
+
+ if ($arg =~ /^--html-title(=(.+))?$/) {
+ shift @ARGV;
+
+ if ($2 eq '') {
+ if (!@ARGV) {
+ DieDiag("'--html-title' option requires a string.\n");
+ }
+
+ $HtmlTitle = shift @ARGV;
+ } else {
+ $HtmlTitle = $2;
+ }
+
+ next;
+ }
if ($arg eq "-k" or $arg eq "--keep-going") {
shift @ARGV;
next;
}
- if ($arg =~ /^--use-c[+][+](=(.+))?$/) {
+ if ($arg =~ /^--use-c\+\+(=(.+))?$/) {
shift @ARGV;
if ($2 eq "") {
exit 1;
}
-
+$CmdArgs = HtmlEscape(join(' ', map(ShellEscape($_), @ARGV)));
+$HtmlTitle = "${CurrentDirSuffix} - scan-build results"
+ unless (defined($HtmlTitle));
# Determine the output directory for the HTML reports.
my $BaseDir = $HtmlDir;