}
}
+sub ErrorDiag {
+ if ($UseColor) {
+ print STDERR BOLD, RED "$Prog: ";
+ print STDERR RESET, RED @_;
+ print STDERR RESET;
+ } else {
+ print STDERR "$Prog: @_";
+ }
+}
+
sub DiagCrashes {
my $Dir = shift;
Diag ("The analyzer encountered problems on some source files.\n");
sub DieDiag {
if ($UseColor) {
- print BOLD, RED "$Prog: ";
- print RESET, RED @_;
- print RESET;
+ print STDERR BOLD, RED "$Prog: ";
+ print STDERR RESET, RED @_;
+ print STDERR RESET;
}
else {
- print "$Prog: ", @_;
+ print STDERR "$Prog: ", @_;
}
- exit(0);
+ exit 1;
}
##----------------------------------------------------------------------------##
my ($sign, $name, @text) = split ' ', $_;
print $name, $/ if $sign eq '+';
}
- exit 1;
+ exit 0;
}
##----------------------------------------------------------------------------##
my $OutputFormat = "html";
my $AnalyzerStats = 0;
my $MaxLoop = 0;
+my $RequestDisplayHelp = 0;
+my $ForceDisplayHelp = 0;
+my $AnalyzerDiscoveryMethod;
if (!@ARGV) {
- DisplayHelp();
- exit 1;
+ $ForceDisplayHelp = 1
}
-
-my $displayHelp = 0;
-my $AnalyzerDiscoveryMethod;
-
while (@ARGV) {
# Scan for options we recognize.
my $arg = $ARGV[0];
if ($arg eq "-h" or $arg eq "--help") {
- $displayHelp = 1;
+ $RequestDisplayHelp = 1;
shift @ARGV;
next;
}
last;
}
-if (!@ARGV and $displayHelp == 0) {
- Diag("No build command specified.\n\n");
- $displayHelp = 1;
+if (!@ARGV and !$RequestDisplayHelp) {
+ ErrorDiag("No build command specified.\n\n");
+ $ForceDisplayHelp = 1;
}
# Find 'clang'
$Clang = Cwd::realpath("$RealBin/clang");
}
if (!defined $Clang || ! -x $Clang) {
- if (!$displayHelp) {
+ if (!$RequestDisplayHelp && !$ForceDisplayHelp) {
DieDiag("error: Cannot find an executable 'clang' relative to scan-build." .
" Consider using --use-analyzer to pick a version of 'clang' to use for static analysis.\n");
}
}
}
-if ($displayHelp) {
+if ($ForceDisplayHelp || $RequestDisplayHelp) {
DisplayHelp();
- exit 1;
+ exit $ForceDisplayHelp;
}
$ClangCXX = $Clang;