#!/bin/bash
####################################################################
#                  vddiff                                          #
# This shell script compares two MCTDH_directories and lists the   #
# doc files that differ.  vddiff calls ddiff                       #
# HDM 04/00                                                        #
####################################################################

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

mopt='-d'
purp="Purpose: Comparison of the documentation two MCTDH-directories."
usage="Usage  : vddiff [ -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 ' '


#-----------------------------------------------------------------------

cd $dir1/doc

for i in  mctdh code potfit analyse
do
    if [ -d $i ] ; then
	cd $i
	ddiff $mopt -f $dir2/doc/$i *.html
	cd ..
    else
	echo "No directory $dir1/doc/$i"
    fi
done

for i in latex  guide  guide/include
do
    if [ -d $i ] ; then
	cd $i
	ddiff $mopt -f $dir2/doc/$i *.tex
	cd ..
    else
	echo "No directory $dir1/doc/$i"
    fi
done


if [ -d $dir1/doc/guide/examples ] ; then
    cd $dir1/doc/guide/examples
    ddiff $mopt -f $dir2/doc/guide/examples *
else
    echo "No directory $dir1/doc/guide/examples"
fi

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

