#!/usr/bin/perl
#****************************************************************/
# $RCSfile: CM2cvs.pl,v $
# ----------------------------------------------------------------
# $Source: /ma/miwa/CvsRepository/mjm/tools/T/cm_cvs/bin/CM2cvs.pl,v $
# ----------------------------------------------------------------
# $Revision: 1.8 $
# ----------------------------------------------------------------
# $Author: miwa $
# ----------------------------------------------------------------
# $Date: 2004/09/14 07:52:08 $
#****************************************************************/

use CM_util;

#########################################
# Hauptprogramm
#########################################

# open files
open (FIN, "$ARGV[0]") || die "file not found: $ARGV[0]\n";
open (FOUT, ">$ARGV[1]") || die "file not found: $ARGV[1]\n";

# define command tables
@UpdateDirs       = ();
@CheckinDirs      = ();
@DeleteFiles      = ();
@IgnoreFiles      = ();
@DeleteRepository = ();
@AddFiles         = ();
@BinFiles         = ();

analyseCmStatus();

# build cm specific commands

foreach $Item ( @UpdateDirs )
{
    print FOUT "echo cvs up $Item\n";
    print FOUT "cvs up $Item\n\n";
}

foreach $Item ( @DeleteFiles )
{
    print FOUT "rm -r $Item\n\n";
}

foreach $Item ( @IgnoreFiles )
{
    print FOUT "echo \"$Item\" >> .cm.ignore\n\n";
}

foreach $Item ( @DeleteRepository )
{
    print FOUT "echo cvs rm $Item\n";
    print FOUT "cvs rm $Item\n\n";
}

foreach $Item ( @AddFiles )
{
    if ( $Item =~ /\// )
    {
        $Dir  = $Item;
        $Dir  =~ s/\/.*//;
        $Item =~ s/.*?\///;
        print FOUT "echo cvs add $Item\n";
        print FOUT "cd $Dir; cvs add $Item; cd ..\n\n";
    }
    else
    {
        print FOUT "echo cvs add $Item\n";
        print FOUT "cvs add $Item\n\n";
    }
}

foreach $Item ( @BinFiles )
{
    if ( $Item =~ /\// )
    {
        $Dir  = $Item;
        $Dir  =~ s/\/.*//;
        $Item =~ s/.*?\///;
        print FOUT "echo cvs add -kb $Item\n";
        print FOUT "cd $Dir; cvs add -kb $Item; cd ..\n\n";
    }
    else
    {
        print FOUT "echo cvs add -kb $Item\n";
        print FOUT "cvs add -kb $Item\n\n";
    }
}

$hostname = $ENV{'M_HOST'};

foreach $Item ( @CheckinDirs )
{
    print FOUT "echo cvs ci -m $hostname $Item\n";
    print FOUT "cvs ci -m $hostname $Item\n\n";
}

print FOUT "cvs up\n";

