#!/bin/bash -f
BIN=/usr/local/bin
CSLIBDIR=$TURNKEY/cslib
M4=$CSLIBDIR/Include
                                                                         
: Check file validity

if test $1x = x
 then
   echo No input file specified.
   echo m4orch syntax:  m4orch  inputfile
   echo '   where "inputfile" usually includes Eastman Csound Library macros'
   echo 'The command   "m4orch"  can be abbreviate   "m4o"'
   echo Example:  m4o  mar.o
   echo 'Result : File "mar.o" will be expanded into a usable Csound orchestra file named'
   echo '      orch.orc'
   echo 'The file  "orch.orc" can be abbreviated "orc" on a Csound command line'
   exit 1
fi

if test -r $1
 then
#  if ${BIN}/olibscan < $1
#   then
    /bin/rm -f orc
   m4  --include=$CSLIBDIR/Include  $CSLIBDIR/Include/im4defs.h $1 > orch.orc
      # -B ignored in GNU m4  Sept 2004
   # OLD  m4 -B8192 ${M4}/im4defs.h  $1 > orch.orc
    ln -s orch.orc orc
  echo file "" $1 "" has been expanded into Csound orchestra file "" orch.orc
#   else exit1
#  fi
  else
  echo "ERROR: No input file named \"$1\" found"
  exit 1
fi
exit 0
