#!/bin/bash

# ----------------------------------------------------------
# RPC Project :
# RPC_make_minidoc : make minidoc of all RPC commands
#                    result in RPC_minidoc.txt
# P. Robert, LPP, 2011-05-12
# ----------------------------------------------------------


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 : Make mini-documentation of RPC commands"
   echo "$appli   require $Narg argument(s), ex:"
   echo ""
   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`

if test -f RPC_minidoc.txt ; then rm RPC_minidoc.txt ; fi

echo $appli : make RPC_minidoc.txt file...


ligne="==============================================================================="

echo $ligne > RPC_minidoc.txt
echo >> RPC_minidoc.txt
echo "----------------------" >> RPC_minidoc.txt
echo "RPC mini documentation" >> RPC_minidoc.txt
echo "----------------------" >> RPC_minidoc.txt
echo >> RPC_minidoc.txt

if test -f $dir/toto1_$$.tmp ; then rm $dir/toto1_$$.tmp ; fi
if test -f $dir/toto2_$$.tmp ; then rm $dir/toto2_$$.tmp ; fi
if test -f $dir/toto3_$$.tmp ; then rm $dir/toto3_$$.tmp ; fi

ls -1 $RPC_DIR/bash/RPC* > toto1_$$.tmp

sed -e "s%.*/RPC%RPC%" -e "s/$/ -h ; echo $ligne /" toto1_$$.tmp > toto2_$$.tmp

sh toto2_$$.tmp >> RPC_minidoc.txt
mv RPC_minidoc.txt toto3_$$.txt
sed -e '/ -------------------------/d' -e '/^$/d' -e '/^ *$/d' toto3_$$.txt > RPC_minidoc.txt

rm toto?_$$.tmp

echo
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 " ==================================================================="

