#!/usr/bin/perl

#########################################
sub trace
#########################################
{
    
#    my( $TraceLine ) = @_;
#    open (TRACE, ">>/tmp/syslst") || die "file not found: syslst\n";
#    print TRACE "$TraceLine\n";
}


#########################################
sub addDir
#########################################
{
    my( $Line, @DirList  ) = @_;
    trace "$Line";
    trace "@DirList";
    $Operated = 0;
    for ( $i=0; $i<=$#DirList; $i++ )
    {
        @ListLineItem = split /\//, $DirList[ $i ];
        @WorkLineItem = split /\//, $Line;
        
        # check first item
        if ( $ListLineItem[0] eq $WorkLineItem[0] )
        {
            $Operated = 1;
            for ( $j=1; $j<=$#ListLineItem; $j++ )
            {
                trace( "j,ListLineItem=".$j.",".$#ListLineItem );
                if ( $j == $#WorkLineItem+1 )
                {
                    # new line is shorter than existing one
                    $DirList[ $i ] = $Line;
                    last;
                }
                if (  $ListLineItem[$j] ne $WorkLineItem[$j] )
                {
                    $NewLine = $ListLineItem[0];
                    trace( "j,NewLine=".$j.",".$NewLine );
                    for ( $k=1; $k<$j; $k++ )
                    {
                        trace( "k,j=".$k.$j );
                        $NewLine = $NewLine."/".$ListLineItem[$k];
                        $DirList[ $i ] = $NewLine;
                    }
                    $DirList[ $i ] = $NewLine;
                    last;
                }
            }
        }
    }
    if ( ! $Operated )
    {
        push ( @DirList, $Line );
    }
    trace "@DirList";
    return @DirList;
}

#########################################
sub analyseCmStatus
#########################################
{
	while ( $line = <FIN> )
	{
		$Selector = $line;
		$Selector =~ s/ .*//;
		$line =~ s/.* //;
		chomp( $line );
		trace $Selector;
		if ( $Selector =~ /^U/ )
		{
		    # update processing
		    @UpdateDirs = addDir( $line, @UpdateDirs );
		}
		elsif ( $Selector =~ /^M/ )
		{
		    # checkin processing
		    @CheckinDirs = addDir( $line, @CheckinDirs );
		}
		elsif ( $Selector =~ /^D/ )
		{
		    # delete processing
		    push( @DeleteFiles, $line );
		}
		elsif ( $Selector =~ /^R/ )
		{
		    # delete repository processing
		    push( @DeleteRepository, $line );
		    @CheckinDirs = addDir( $line, @CheckinDirs  );
		}
		elsif ( $Selector =~ /^A/ )
		{
		    # add processing
		    push( @AddFiles, $line );
		    @CheckinDirs = addDir( $line, @CheckinDirs  );
		}
		elsif ( $Selector =~ /^B/ )
		{
		    # add binary processing
		    push( @BinFiles, $line );
		    @CheckinDirs = addDir( $line, @CheckinDirs  );
		}
		elsif ( $Selector =~ /^I/ )
		{
		    # ignore processing
		    push( @IgnoreFiles, $line );
		}
		else
		{
		    die( "unknown command $line" );
		}
	}
}

1;

