#!/bin/sh
# create diff of logfiles
# (untested since June 2003, was used for web site migration of RKI)

OPTIONS=""
FILE1=""
FILE2=""

stripdate () {
   TMP=`tempfile`
   # sed "s/^[-0-9 :]*//" $1 > ${TMP}
   # Bei Zope stupid_log ist Tag und Uhrzeit durch 'T' getrennt ...
   sed "s/^[-0-9 :T]*//" $1 > ${TMP}
   touch -r $1 ${TMP}
   RET=${TMP}
}

set -x
for opt in $@ ; do
   if [ `echo $opt | grep -c "^-"` -gt 0 ] ; then
      OPTIONS="${OPTIONS} $opt"
   else 
      if [ _"${FILE1}" = _"" ] ; then
         if [ ! -f ${opt} ] ; then
            echo "Datei ${opt} kann nicht gefunden werden."
            exit
         fi
         FILE1=${opt}
      else
         if [ _"${FILE2}" = _"" ] ; then
            if [ ! -f ${opt} ] ; then
               echo "Datei ${opt} kann nicht gefunden werden."
               exit
            fi
            FILE2=${opt}
	 else
	    echo "Zu viele Dateinamen: ${FILE1}, ${FILE2} und ${opt}."
	    exit
	 fi
      fi
   fi
   shift
done

stripdate ${FILE1}
TMP1=$RET
stripdate ${FILE2}
TMP2=$RET

diff ${OPTIONS} ${TMP1} ${TMP2} | \
   sed "s?${TMP1}?${FILE1}?" | \
   sed "s?${TMP2}?${FILE2}?"

rm -f ${TMP1} ${TMP2}
