#!/bin/sh
#
# This script starts xcircuit under the Tcl interpreter,
# reading commands from a special .wishrc script which
# launches xcircuit and retains the Tcl interactive interpreter.
#

loclibdir=${XCIRCUIT_LIB_DIR:=/usr/pkg/lib/xcircuit-3.10}
export XCIRCUIT_LIB_DIR
XCIRCUIT_WISH=/usr/pkg/bin/wish
export XCIRCUIT_WISH

# Hacks for Cygwin
if [ x${TERM:=""} = x"cygwin" ]; then
   export PATH=$PATH:/usr/pkg/lib
   export DISPLAY=${DISPLAY:=":0"}
fi

TKCON=true
DNULL=
for i in $@ ; do
   case $i in
      -noc*)
	   TKCON=;;
      -now*)
	   DNULL=true
	   TKCON=;;
      --help)
	   echo "Standard usage:"
	   echo "   xcircuit [filename]"
	   echo "Online documentation:"
	   echo "   http://opencircuitdesign.com/xcircuit"
	   exit 0
	   ;;
      --version)
	   echo "XCircuit version 3.10 revision 30"
	   exit 0
	   ;;
   esac
done

if [ $TKCON ]; then

   if [ ! -f ${loclibdir}/tkcon.tcl ]; then
      loclibdir=${loclibdir}/tcl
   fi

   exec ${loclibdir}/tkcon.tcl \
	-eval "source ${loclibdir}/console.tcl" \
        -slave "package require Tk; set argc $#; set argv [list $*]; \
        source ${loclibdir}/xcircuit.tcl"
else

#
# Run the stand-in for wish (xcircexec), which acts exactly like "wish"
# except that it replaces ~/.wishrc with xcircuit.tcl.  This executable is
# *only* needed when running without the console; the console itself is
# capable of sourcing the startup script.
#
   if [ $DNULL ]; then
      exec ${loclibdir}/xcircdnull -- $@
   else
      exec ${loclibdir}/xcircexec -- $@
   fi
fi
