#!/usr/bin/perl -w

# parameters
my $cws = shift @ARGV;
my $outfile = shift @ARGV;
if (!defined $outfile) {
    $outfile = "cws-$cws.diff";
}

$ENV{SRC_ROOT} || die "Havn't sourced the environment";
-f "sal/CVS/Root" || die "Doesn't look like a live OO.o cvs checkout to me";

my $cvsroot = `cat sal/CVS/Root`;
$cvsroot =~ s/\n/ /g;
$cvsroot =~ s/\s*$//;

my $modules = `CWS_WORK_STAMP=$cws cwsquery modules`;
$modules =~ s/\r\n//g;
$modules =~ s/\n/ /g;
$modules =~ s/  / /g;

my @mod_list = split (/ /, $modules);
print STDERR "Modules: '" . join (",", @mod_list) . "'\n";

for my $module (@mod_list) {
    my $tag = "cws_src680_$cws";
    my $anchor = uc ("$tag" . "_ANCHOR");
    print STDERR "cvs -d '$cvsroot' diff -kk -upN -r$anchor -r$tag $module >> $outfile 2>&1\n";
    system ("cvs -d '$cvsroot' diff -kk -upN -r$anchor -r$tag $module >> $outfile 2>&1");
}
