#!/usr/local/bin/perl

$tool = $ENV{"DTOOL"} ;
if ( $tool eq "" ) {
    die "Environment not configured to run CTtools" ;
}

sub CTSanityUsage {
    print STDERR "Usage: ctsanity [-v]\n" ;
    print STDERR "Options:\n" ;
    print STDERR "  -v : sanity check the .vspec files \n" ;
    exit ;
}

if ( $#ARGV == -1 ) {
    &CTSanityUsage ;
}

$check_vspecs = 0 ;

foreach $item ( @ARGV ) {
    if ( $item eq "-v" ) {
	$check_vspecs = 1 ;
    } else {
	print STDERR "unknown option '" . $item . "'\n" ;
	$CTSanityUsage ;
    }
}

require "$tool/include/ctvspec.pl" ;

if ( $check_vspecs ) {
    local( $projs ) = &CTListAllProjects ;
    local( @projlist ) = split( / +/, $projs ) ;
    local( $item ) ;
    foreach $item ( @projlist ) {
	print STDERR "checking " . $item . ".vspec:\n" ;
	local( $ctsavedebug ) = $ctdebug ;
	$ctdebug = 1 ;
	&CTReadVSpec( $item ) ;
	$ctdebug = $ctsavedebug ;
    }
}
