#!/bin/bash
# lsex : list ECMC example files
# A.S. July 2004

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

  SCEXDIR="$CSLIBDIR/ex"
  TUTDIR="$CSLIBDIR/tut/ex"
for i in  $* ; do
if  ( [ $i == "sc" ] || [ $i == "score11" ] ) ; then  # score11 example files
  echo "   (1) List of example score11 input files for TUTORIAL instrument"
  echo "    algorithms in the Eastman Csound Library:"
  ls -C $TUTDIR
  echo "           -   -    -    -    -    - "
  sleep 1 # 3
 
  echo "   (2) List of example score11 input files for (non-tutorial) instrument"
  echo  "     algorithms in the Eastman Csound Library:"
  sleep 1
  ls -C $SCEXDIR
  echo '    To obtain one or more of any of the files listed above type:'
  echo '        getex filename [filename2  filenameN]'
  echo '   Examples:  getex  tsamp1     or    getex  ex3-1 ex3-2'
  echo "   ------------------------------------------"
  shift

elif  [ $i == "pvc" ] ; then  # pvc example files
  echo '      List of ECMC -> PVC <- example files:'
  ls -C $PVCDIR/TKLAEXAMPLES
  echo '    To obtain one or more of any of the files listed above type:'   
  echo '        getex filename [filename2  filenameN]'
  echo '   Examples: getex  plainpv2    or   getex chordmapper1 chordmapper1-1 chordmapper1-2 '
  echo "   ------------------------------------------"
   shift

# ======= look for matching character strings ==================
else
  FOUND=NO
  if ( cd $SCEXDIR; ls -C *$i* >& /dev/null ) ; then # Csound library score11
    echo " score11 example files found matching string -> $i <-  : "
    cd $SCEXDIR; ls -C *$i*  ; FOUND=YES ; shift ; fi
  if ( cd $TUTDIR; ls -C *$i* >& /dev/null ) ; then # Csound tutorial score11
    echo " ECMC Csound tutorial score11 example files found matching string -> $i <-  : "
    cd $TUTDIR; ls -C *$i*  ;  FOUND=YES ; shift ; fi
  if ( cd $PVCDIR/TKLAEXAMPLES; ls -C *$i* >& /dev/null ) ; then # PVC
    echo " PVC example files found matching string -> $i <-  : "
    cd $PVCDIR/TKLAEXAMPLES; ls -C *$i*  ; FOUND=YES ; shift ; fi
  echo "   ---------------------------------"
  shift
# =================================================
  if [ $FOUND == "NO" ] ; then # no match found
    echo "ERROR: No example files available for argument  -> $i <-"
   echo 'lsex syntax:'
    echo 'lsex :  lists example ECMC file(s) ; syntax:'
    echo '   lsex score11  (or lsex sc  or lsexsc) : list score11 example files '
    echo '   lsex pvc  (or lsexpvc) : list pvc example files '
    echo '   lsex string : list example files that include characer string "string"'
   echo ' For more usage details type:   man lsex '
   exit 1
  fi
fi
done
