#!/usr/bin/perl

# $Id: //depot/cad/tools/1.0/icp4-1.1/bin/p4rm#4 $
#
# CSWITCH CORPORATION CONFIDENTIAL PROPRIETARY
# 
# This file contains information which is the
# proprietary property of Cswitch Corporation.
# This file is confidential and its contents may
# not be disclosed without the expressed written
# consent of Cswitch Corporation.


use strict;
use warnings;

use FindBin qw($Bin);
use lib "$Bin/../lib";

use Icp4;
use Getopt::Std;
use File::Basename;

our (%opt, $Program);

MAIN: {

    my ($nflag, $cell, $cells);

    $Program = $FindBin::Script;

    getopts('hDni', \%opt);

    if ($opt{h} || $#ARGV < 0) {
	print "Usage: $Program [-h] [-n] [-i] cell+\n";
	print "   -h: help usage\n";
	print "   -n: show operation only\n";
	print "   -i: ignore pending changes (dangerous!)\n";
	print " cell: cell name(s)\n";
	exit;
    }

    $nflag = "-n" if ($opt{n});
    $Icp4::debug = ($opt{D}) ? 1 : 0 ;
    $Icp4::nflag = ($opt{n}) ? 1 : 0 ;

    if (!$opt{i} && &Icp4::outstanding_changes()) {
	exit -1;
    }

    $cells = "";

    foreach $cell (@ARGV) {

	if (-d $cell) {
	    $cells = $cells . " ${cell}.* ${cell}/...";
	}
    }

    if ($cells ne "") {
	print "INFO: Reverting any unmodified files (\"p4 revert $nflag -a $cells\")\n";
	system "p4 delete $nflag $cells";

	&Icp4::submit_open_files($cells, "");
    }

    exit 0;
}