#!/bin/bash
#####################################################################
#                  vrdiff                                           #
# This shell script compares two MCTDH_directories and lists the    #
# remaining files (bin,install,operators,inputs,pinputs,elk_inputs) #
# that differ.  vrdiff calls ddiff. (See vsdiff and vddiff).        #
# HDM 04/00                                                         #
#####################################################################

#-----------------------------------------------------------------------
#  Definitions :
#-----------------------------------------------------------------------

mopt='-d'
purp="Purpose: Comparison of the remaining files of two MCTDH-directories."
usage="Usage  : vrdiff [ -h -d -i -s -l ] dir1 [dir2]."
help1='-h : print this help text.'
help2='-d : indicate only files that differ (default).'
help3='-i : indicate only files that are identical.'
help4='-s : indicate whether files are identical or different.'
help5='-l : long form. Let diff show the differences.'
help6='-L : similar to -l, but case and blank sensitive.'
help7='     The comparison is between dir1 and dir2.'
help8='     If dir2 is not given, $MCTDH_DIR is assumed.'

#-----------------------------------------------------------------------
#  Read the options (if any).
#-----------------------------------------------------------------------

while getopts ":hdislL" opt; do
    case $opt in
    h  ) dir1='-h' ;;
    d  ) mopt='-d' ;;
    i  ) mopt='-i' ;;
    s  ) mopt='-s' ;;
    l  ) mopt=''   ;;
    L  ) mopt='-c' ;;
    \? ) echo ' Unkown option!'
         echo $usage
         echo ' -h provides a help text.'
         exit 1 ;;
  esac
done
shift $(($OPTIND - 1))

if [ -z "$dir1" ] ; then dir1="${1:--h}" ; fi
dir2="${2:-$MCTDH_DIR}"


if [ "$dir1" = "-h" ] ; then
    echo $purp
    echo $usage
    echo ' '$help1
    echo ' '$help2
    echo ' '$help3
    echo ' '$help4
    echo ' '$help5
    echo ' '$help6
    echo ' '
    echo ' '$help7
    echo ' '$help8
    echo ' '
    exit
fi

if [ -n "${dir2%%/*}" ] ; then
    olddir=`pwd`
    cd $dir2
    dir2=`pwd`
    cd $olddir
fi

cd $dir1
dir1=`pwd`

echo '-----------------------------------------------------------------'
echo ' Working    Directory: '$dir1
echo ' Comparison Directory: '$dir2
echo ' '


#-----------------------------------------------------------------------
#  Compare the files.
#-----------------------------------------------------------------------

if [ -d $dir1/bin ] ; then
    cd $dir1/bin
    lll=`ls -d *[!~] | egrep -v '(^i686$|^obsolete$|_bk[0-9]|_md[0-9])'`
    ddiff $mopt -f $dir2/bin  $lll
else
    echo "No directory $dir1/bin"
fi

if [ -d $dir1/install ] ; then
    cd $dir1/install
    ddiff $mopt -f $dir2/install *[!~]
else
    echo "No directory $dir1/install"
fi

if [ -d $dir1/inputs ] ; then
    cd $dir1/inputs
    ddiff $mopt -f $dir2/inputs *[!~]
else
    echo "No directory $dir1/inputs"
fi

if [ -d $dir1/pinputs ] ; then
    cd $dir1/pinputs
    ddiff $mopt -f $dir2/pinputs *[!~]
else
    echo "No directory $dir1/pinputs"
fi

if [ -d $dir1/finputs ] ; then
    cd $dir1/finputs
    ddiff $mopt -f $dir2/finputs *[!~]
else
    echo "No directory $dir1/finputs"
fi

if [ -d $dir1/elk_inputs ] ; then
    cd $dir1/elk_inputs
    ddiff $mopt -f $dir2/elk_inputs *[!~]
else
    echo "No directory $dir1/elk_inputs"
fi

if [ -d $dir1/operators ] ; then
    cd $dir1/operators
    ddiff $mopt -f $dir2/operators *[!~]
else
    echo "No directory $dir1/operators"
fi

echo '########################################################################'
exit








