#!/usr/bin/perl -Pdw
#
# Given a list of file names, make sure that they are in the VOB and  are  up
# to date.  By "up to date", we mean that they are identical with the version
# named on our command line (which defaults to all the source in the cwd).

#include "dbg.pl";

$V= $ENV{"V"} || '/vobs/nm/cmagent/src';
#$H = "/home1/gbs202/nmadmin/headers/csource.hdr";

if (!@ARGV) {
	@ARGV = split(/\s/,`ls *.[bhCFt]`);
}

for $f (@ARGV) {
	D "File: $f" D2;
	$F = "$V/$f";
	if (system "cleartool lsc $F") {
		D "File: $f not in VOB yet." D2;
		system "cleartool mkelem -elt text_file -c Init $F";
		D "File: $F element created." D2;
		system "cp $f $F";
		system "cleartool ci -c Init $F";
		D "File: $F checked in." D2;
	} else {
		D "File: $f in VOB already." D2;
	}
	if (system "cleardiff -sta $f $F") {
		D "File: $f differs from $F" D2;
		system "cleartool co -c Upgrade $F";
		D "File: $f checked out." D2;
		system "cp $f $F";
		system "cleartool ci -c Upgrade $F";
		D "File: $f checked in." D2;
	} else {
		D "File: $f same as $F" D2;
	}
}
