#!/bin/sh
#
# logar - loged wrapper to install or update a digital gate's definition.
#
# usage: logar lib.gate file.def
#          lib.gate is the gate file to be updated.
#          file.def is the definition file generated by diglog.
#
#
USAGE="usage: logar lib.gate file.def"  
prog="loged -p"

case $# in
  2) lib=$1; 
     file=$2;
     ;;
  *) echo $USAGE 
     exit 1
     ;;
esac

# check the gate file exists.
if [ ! -e $lib ]
then
  echo logar: error: gate file $lib not found 1>&2
  exit 1
fi

# check the def file exists
if [ ! -e $file ]
then 
  echo logar: error: def file $file not found 1>&2
  exit 1
fi

# produce the gate's name by cutting on the first period of the .def file name. 
name=`echo $file |cut -d'.' -f1`

# construct a here document to feed into loged's stdin
$prog $lib <<End >/dev/null
gate $name 
read $file
save $lib 
quit
End

exit 0

