#!/bin/bash
# lstp : list ECMC template files
# A.S. July 2004

if ( [ $# == 0 ] ) ; then  # print usage summary
 echo 'lstp :  lists example ECMC file(s) ; syntax:'
 echo '   lstp sc  (or lstp score11   or lstpsc) : list score11 template files '
 echo '   lstp pvc  (or lstppvc) : list pvc template files '
 echo '   lstp string : list tempalte files that include character string "string"'
 echo ' For more usage details type:   man lstp '
 exit 0
fi

  SCTPDIR="$CSLIBDIR/templates"
  PVCTPDIR="$PVCDIR/TKLA"
for i in  $* ; do
if  ( [ $i == "sc" ] || [ $i == "score11" ] ) ; then  # score11 tempalte files
  echo "List of score11 template files for Eastman Csound library instruments:"
  ls -C $SCTPDIR
  echo '    To obtain one or more of any of the files listed above type:'
  echo '        sctp filename [filename2  filenameN]'
  echo '   Example:  sctp  tsamp'

  echo "   ------------------------------------------"
  shift
elif  [ $i == "pvc" ] ; then  # pvc template files
  echo '      List of ECMC -> PVC <- template files:'
  cd  $PVCTPDIR; ls -C *template | sed -e 's/\.template//g'
  echo 'An individual template exists for each program above. To obtain a usage summary'
  echo 'for any of these  templates type the program name followed by "tp" with no arguments:'
  echo 'plainpvtp   or    pvanalysistp  or    twarptp    etc.'
  echo "   ------------------------------------------"
   shift

# ======= look for matching character strings ==================
else
  FOUND=NO
  if ( cd $SCTPDIR; ls  *$i* >& /dev/null ) ; then # Csound library score11
    echo " score11 template(s) found matching string -> $i <-  : "
    cd $SCTPDIR; ls -C *$i*  ; FOUND=YES ; shift ; fi
  if ( ls $PVCTPDIR/*$i* >& /dev/null ) ; then # PVC
    echo " PVC template file(s) found matching string -> $i <-  : "
   cd $PVCTPDIR ; ls -1 *$i* | grep -v tp | sed -e 's/\.template//g' | pr -t --columns 3; FOUND=YES ; shift ; fi

# =================================================
  if [ $FOUND == "NO" ] ; then # no match found
    echo "ERROR: No example files available for argument  -> $i <-"
   echo 'lstp syntax:'
 echo '   lstp sc  (or lstp score11   or lstpsc) : list score11 template files '
 echo '   lstp pvc  (or lstppvc) : list pvc template files '
 echo '   lstp string : list tempalte files that include character string "string"'
   echo ' For more usage details type:   man lstp '
   exit 1
  fi
fi
done

