#!/bin/bash

# -------------------------------------------------------
# RPC Project :
# Run RPC_convertion all files in the tree
# P. Robert, ScientiDev, Dec 2020
# -------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=0

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : convert all files from DOS to UNIX format"
   echo "$appli   require $Narg argument(s)"

   if test $hh = 1 ; then exit 0 ; fi
   echo " $appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datim1=`date +%F'  '%H':'%M':'%S `
julsec1=`date +%s`

echo " ------------------------------------------------------------------"
echo " $appli : convert all files from DOS to UNIX format"


convertion=dos2unix


for ext in .f90 .pro .c .sh .bash .cef .rff .txt .ind .in .out
    do     
    find . -type f -name "*$ext" -exec $convertion {} \;
done

   
find . -type f -name "RPC*" -exec $convertion {} \;

echo "Done !"

# end of command
# --------------

datim2=`date +%F'  '%H':'%M':'%S `
julsec2=`date +%s`
diff=`expr $julsec2 - $julsec1`

echo ""
echo " Starting time $appli : $datim1"
echo " Ending   time $appli : $datim2"
echo " Duration      $appli : $diff sec."
echo    
echo " $appli36 : NORMAL TERMINATION - time exe= $diff s." >&2 

echo " ==================================================================="

