#!/bin/bash

########################################################################
#                                  PLALL                               #
#                                                                      #
# This shell scripts prints a brief description of all pl-scripts.     #
#                                                                      #
# MB 2/00                                                              #
########################################################################

dir="$MCTDH_DIR/bin"
except="plall"

if [ -z "$awk1" ] ; then
   exist=`which gawk | cut -d' ' -f1 | fgrep '/bin'`
   if [ -n "$exist" ] ; then
      awk1=gawk
   fi
fi
if [ -z "$awk1" ] ; then
   exist=`which nawk | cut -d' ' -f1 | fgrep '/bin'`
   if [ -n "$exist" ] ; then
      awk1=nawk
   fi
fi
if [ -z "$awk1" ] ; then
   exist=`which awk | cut -d' ' -f1 | fgrep '/bin'`
   if [ -n "$exist" ] ; then
      awk1=awk
   fi
fi

cd $dir

if [ "$1" = "-h" ] ; then
    echo 'Purpose:  Provide an overview over all pl-scripts.'
    echo 'Usage  :  plall [ -l  -h ] '
    echo 'Options:'
    echo '        -l : (long). Print the help texts of all pl-scripts.'
    echo '        -h : print this help text.'
elif [ "$1" = "-l" ] ; then
echo " -------------------- Help texts of all pl-scripts --------------------"
    for i in pl*; do
	if [ $i != $except ] && [ -n "${i%%*\~}" ] ; then
            echo " ----------------------------------------------------------"
	    echo
	    echo "$i"
	    $i -h
	fi
    done
else

echo
echo " -------------------- Overview over all pl-scripts --------------------"
echo

for i in pl*; do
  if [ $i != $except ] && [ -n "${i%%*\~}" ]  && \
     [ -n "${i%%*_bk*}" ] && [ -n "${i%%*_md*}" ] ; then
    echo $i
    fgrep "Purpose:" $i | tr '"' ' ' | $awk1 \
       'BEGIN { FS = "Purpose:"} {print "Purpose:",$2}'
    fgrep "Usage:"   $i | tr '"' ' ' | $awk1 \
       'BEGIN { FS = "Usage:"}   {print "Usage:\t",$2}'
    echo
  fi
done

fi
echo "-----------------------------------------------------------------------"

exit 0











