#!/bin/sh

PREFIX=`dirname $0`
PREFIX="$PREFIX/.."

RMBDIR=/tmp/tmp_rmb

mkdir -p $RMBDIR || exit 1

cd $PREFIX

for file in src/*/*.[ch] src/*/*.f90 src/*/*.[ch]xx src/*/*.cu \
            tests/*.c* build-aux/*.py \
            python/code_saturne/*/*.py python/code_saturne/*/*/*.py \
            libple/*/*.[ch] preprocessor/*/*.[ch] \
            NEWS.md
do
  tmpfile=`basename $file`
  sed -e 's/ *$//' -e 's/	/        /g' $file > $RMBDIR/$tmpfile
  diff $file $RMBDIR/$tmpfile > /dev/null 2>&1
  if [ $? = 1 ]
  then
    echo $file
    mv $RMBDIR/$tmpfile $file
  fi
done

for file in docs/*/*.tex
do
  tmpfile=`basename $file`
  sed -e 's/ *$//' $file > $RMBDIR/$tmpfile
  diff $file $RMBDIR/$tmpfile > /dev/null 2>&1
  if [ $? = 1 ]
  then
    echo $file
    mv $RMBDIR/$tmpfile $file
  fi
done

\rm -rf $RMBDIR

