#!/usr/bin/perl
# SCCS $Id: metrics,v 1.14 2004/03/09 10:45:08 dcs0mpw Exp martin $
#############################################################################
## FermaT Transformation System
## Copyright (C) 2001 Software Migrations Limited.
## Email: Martin.Ward@durham.ac.uk
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#############################################################################
#
##########
##########   metrics file.wsl [size]
##########
#

BEGIN {
  $FermaT = $ENV{'FermaT'} || "/usr/local/fermat2";
  $FermaT =~ s/\"//g;
  $ds = "/"; $ds = "\\" if ($^O eq "MSWin32");
  unshift(@INC, "$FermaT${ds}config");
}

use fermat;

($myname = $0) =~ s|(.*/)*||;   # strip path component from name
$Usage = "Usage: $myname [-my] file.wsl [size]\n";

&parse_args();

$cmds = <<END_OF_INPUT;
  (\@New_Program (\@Parse_File "$input" //T_/Statements))
  (display-list "Program Metrics for $input")
  (display-list " ")
  (display-list "Statements     " (\@Stat_Count (\@Program) ))
  (display-list "Expressions    " (\@Gen_Type_Count //T_/Expression (\@Program)))
; (display-list "Effective Size " (\@Effective_Size (\@Program)))
  (display-list "McCabe         " (\@McCabe (\@Program) ))
  (display-list "CFDF           " (\@CFDF_Metric (\@Program)))
  (display-list "Branch-Loop    " (\@BL_Metric (\@Program)))
  (display-list "Structural     " (\@Struct_Metric (\@Program)))
END_OF_INPUT

if (($output !~ /\.out$/) && ($output !~ /-\d+\.wsl$/)) {
  # Assume that an output file was given on command line:
  open(OUT, ">$output") or die "Can't write to `$output': $!\n";
  close(STDERR);
  close(STDOUT);
  open(STDOUT, ">&OUT");
  open(STDERR, ">&OUT");
}

&fermat($cmds);

exit(0);
  
