#! /bin/sh
#     modify
#     modifies a dictionary or a grammar
# -- rewrite NTN 4/15/97
clear
echo "          MEDICAL LANGUAGE PROCESSING"
echo "          GRAMMAR/DICTIONARY UPDATE"
echo
GRAMIN=$CRLS
export GRAMIN
# if test -f $LSPLIB/rls.sym
# then
#    GRAMIS="$LSPLIB/rls.sym"
#    export GRAMIS
# fi
gram=$1
upd=$2
if test "$gram" = ""
then
   echo ">>> Source grammar/dictionary [.obg/.wdo assumed]: \c"
   read gram
fi
if test "$upd" = ""
then
   echo ">>> Update to source [.upd assumed]: \c"
   read upd
fi
if test "$gram" = ""
then
   echo "... Exit no source..."
   exit
fi
if test "$upd" = ""
then
   echo "... Exit no update text..."
   exit
fi
echo
kinc=`grep "^\*include" $upd.upd`
if test "$kinc" = ""
then
   gupd=$upd
else
   \rm new$upd.upd
   $LSPBIN/graminserts $upd.upd > new$upd.upd
   echo "     **$kinc into $upd.upd***"
   gupd=new$upd
fi
if test -f $gram.obg
then
     \rm $upd.obg $upd.sym
     echo "     Source grammar:            " $gram.obg
     GRINUP="$gram.obg"
     GRAMOT="$upd.obg"
     echo "     New grammar:               " $upd.obg
else
	 if test -f $gram.wdo
     then
          \rm $upd.wdo
          echo "     Source dictionary:         " $gram.wdo
          GRINUP="$gram.wdo"
          GRAMOT="$upd.wdo"
          echo "     New dictionary:            " $upd.wdo
     fi
fi
# ------ If source has symbol table, make one for update also.
if test -f $gram.sym
then
     GRSIUP="$gram.sym"
     export GRSIUP
     echo "     Source symbol table:       " $gram.sym
     GRAMOS="$upd.sym"
     export GRAMOS
     echo "     New symbol table:          " $upd.sym
fi
echo "     and Update Trace listing:  " $upd.lis
echo "     created from Update file:  " $gupd.upd
echo
export GRINUP
export GRAMOT
PARINP="$gupd.upd"
export PARINP
\rm $upd.lis
echo "... Modification in progress, please wait...\c"
$COMPILER > $upd.lis
echo
if test -f $upd.obg -o $upd.wdo
then
   echo
   echo "... Modification completed ..."
else
   echo " >>>> $upd.obg or $upd.wdo does not exist !"
fi
chmod $upd.{lis,obg,sym}
echo "*** Run chkcomp $upd to verify results ***"
