#!/usr/bin/perl

if ($#ARGV < 0) {
    exit print "Usage: cttimewarp [-clear] label [time]\n" ;
}

@arglist = @ARGV ;

$clear = 0 ;

if ( $arglist[0] =~ /^-c/ ) {
    $clear = 1 ;
    shift( @arglist ) ;
}

if ( @arglist == () ) {
    if ( $clear ) {
	exit print "Usage: cttimewarp -clear label\n" ;
    } else {
	exit print "Usage: cttimewarp label time\n" ;
    }
}

$label = $arglist[0] ;
shift( @arglist ) ;

if (( ! $clear ) && ( @arglist == () )) {
    exit print "Usage: cttimewarp label time\n" ;
}

$time = $arglist[0] ;

if ( $clear ) {
    $cmd = "cleartool find . -version \"lbtype(" . $label .
           ")\" -exec 'cleartool rmlabel -c \"untimewarping\" " . $label .
           ' $CLEARCASE_XPN' . "'\n" ;
    system( $cmd ) ;
} else {
    $cmd = "cleartool mklabel -replace -recurse -c \"rolling time back to " .
           $time . "\" -version /main/'{\!created_since(" . $time . ")}' " .
           $label . " .\n" ;
    system( $cmd ) ;
}
