#!/usr/bin/perl -dw
#
# ci file...
#
# For all the files that we find in clearcase,  check  them  out.   At
# present  we  don't check to see whether they are checked out, so you
# will receive spurious error messages for those that you already have
# checked  out  (and valid error messages for any that are checked out
# by someone else).
#
# The exit status is the count of files that aren't found in Clearcase; 
# zero means that all went ok.

$C = "-nc";
$V = ($ENV{"V"} || $ENV{"VOB"}) || "/vobs/nm/cmagent";
$D = ($ENV{"D"} || $ENV{"DOC"}) || ($V . "/doc");
$S = ($ENV{"S"} || $ENV{"SRC"}) || ($V . "/src");
$stat = 0;

for ($a = 0; $a <= $#ARGV; ++ $a) {
	$f = $ARGV[$a];
	if ( $f eq '-c') {
		$C = "-c '$ARGV[$a+1]'";
		++$a;
	} elsif ( $f =~ m'^/') {
		$cmd = "cleartool ci -identical $C $f";
		system $cmd;
	} elsif ( -f ($F = "$S/$f")) {
		$cmd = "cleartool ci -identical $C $F";
		system $cmd;
	} elsif ( -f ($F = "$D/$f")) {
		$cmd = "cleartool ci -identical $C $F";
		system $cmd;
	} else {
		print STDERR "Can't find $f in ClearCase.\n";
		++$stat;
	}
}
exit $stat;
