#!/tools/perl/bin/perl

#############################################################################
#
#  Usage:  statty [ -c ] basename [ + exclude-files - ] input-files
#
#  'statty' reads data files in 'ccount' output format and give statistical 
#  reports about modules, functions, blocks, control structures and 
#  expressions of C source files.
#  It executes 'stattyM', 'stattyF', 'stattyCSE' and 'stattyB' one after
#  the other. If the -c option is used, 'statty' will ask you to confirm 
#  before each report. If you answer in the negative the next report will 
#  be offered.
#  The report filenames are 'basename.M', 'basename.F', 'basename.CSE' and
#  'basename.B'.
#  See 'README.1' and 'README.2' for more details!
#
#  Author: Joerg Lawrenz, Universitaet Karlsruhe
#  Date:   93/12/1
#
#############################################################################

#
#  First get the -c option. 
#

if ($ARGV[0] eq "-c") {
   $switch = 1;
   shift;
   
 }

#
#  Exit if there are not enough arguments in the command line.
#

if (scalar(@ARGV) < 2) {
   print "Usage: statty [ -c ] basename [ + exclude-files - ] input-files\n";
   exit;
}

#
#  Now get the basename for the single report names.
#

$basename = shift;

#
#  Now start the single report tools.
#
$reportname = $basename.".M";
print "Module report...\n";
`stattyM $reportname @ARGV` if &yes;

$reportname = $basename.".F";
print "Function report...\n";
`stattyF $reportname @ARGV` if &yes;

#
#  Now delete the exclude-files from the list.
#

if ($ARGV[0] eq '+') {
   shift;
   while ($ARGV[0] ne '-') {
      shift;
    }
   shift;
}

$reportname = $basename.".CSE";
print "Control Structures & Expression report...\n";
`stattyCSE $reportname @ARGV` if &yes;

$reportname = $basename.".B";
print "Block report...\n";
`stattyB $reportname @ARGV` if &yes;


#############################################################################
#
#  'yes' is the request subroutine.
#
#############################################################################

sub yes {
  if ($switch) {
    print STDOUT "Confirm (y/n): ";
    local($answer) = scalar(<STDIN>);
    $answer =~ /^y/i;
   }
  else {
    1;
  }
}
