#!/bin/sh

# This script launches an XEmacs session and an ILOG Talk session
# within it, setting the appropriate environment variables.
#
# Do not copy or move this file; it *must* remain in
# talk32/runtalk.  To simplify its use, just put a symbolic
# link to it in one of your PATH directories.
#
# Rather than using this shell script, regular users are encouraged
# to invoke talk within xemacs, after following the instructions in
# the file '$ILT_DIR/talk/$ILTPORT/START'.
#
# Usage:
#   runtalk [-verbose] [-faster] [-run <talk-exec>] [-bg dark|light]
#           [-use-port <port>] [-use-emacs <emacs>] [-usage] [-help]
#           [-port] [-silent]

RUNTALK=`basename $0`

local_which(){
WHICH_ARG="$1"
case $WHICH_ARG in
*/*) WHICH_RESULT=$WHICH_ARG
     ;;
*)
#    Intent:   WHICH_RESULT=`which $WHICH_ARG`
#    BUT, I don't trust which: some csh users have echoing .cshrc,
#    breaking which csh script for sh scripts.
     WHICH_RESULT=""
     case $PATH in
     :*) fullpath=.$PATH  ;;
     *:) fullpath=$PATH.  ;;
     *)  fullpath=$PATH   ;;
     esac
     for p in `echo $fullpath | sed -e 's/::/:.:/' | tr ':' ' '`
     do if [ -x $p/$WHICH_ARG -a -f $p/$WHICH_ARG ]
        then WHICH_RESULT=$p/$WHICH_ARG
             break
        fi
     done
     ;;
esac
case x$WHICH_RESULT in
x)    ;;
x/*)  ;;
x*)   WHICH_RESULT=`pwd`/$WHICH_RESULT
      ;;
esac
}

# STEP 1: check environment sanity

if [ -w . ]
then
  :
else
  (echo "Warning: current directory `pwd` is not writable,"
   echo "changing to /tmp") >&2
  cd /tmp
fi

# STEP 2: parse args

# talk-mode in emacs has to know if background is light or dark, but
# is currently unable to find out. So we pick an abitrary setting,
# unless caller declares if the current settings are dark or light.

DEFAULTCMD=italk

usage(){
echo "Usage: $RUNTALK [OPTION]..."
echo ""
echo "Verbosity options:"
echo "  -verbose          print comments about what $RUNTALK is doing"
echo "  -silent, -quiet   suppress comments from $RUNTALK"
echo ""
echo "Options for Talk:"
echo "  -run <talk-exec>  specify a Talk executable to run, instead of $DEFAULTCMD"
echo "  -use-port <port>  specify the Talk port name to use"
echo ""
echo "Options for Emacs:"
echo "  -use-emacs <emacs-exec>  specify an Emacs or XEmacs executable to run"
echo "  -bg dark|light    specify a preference for the background colour"
echo ""
echo "Informative output:"
echo "  -faster           learn how to start your Talk session faster"
echo "  -port             print the Talk port name used on this system"
echo "  -version          print Talk version number"
echo "  -help             print this help"
echo ""
}

DARKBG=unknown
CMD=$DEFAULTCMD

while [ $# != 0 ]
do     ARG=$1 ; shift
     case $ARG in
     -bg)     BG=$1 ; shift
          case $BG in
          dark|black|Dark|Black)
                    DARKBG=t
                    COLOR="" ;;
          light|white|Light|White)
                    DARKBG="()"
                    COLOR="" ;;
          *)          echo "** $RUNTALK error: illegal argument: " $BG     >&2
                    usage 1>&2
                    exit 1 ;;
          esac;;
     -run)     CMD=$1 ; shift ;;
     -use-emacs)   PASSEDXEMACS=$1 ; shift ;;
     -verbose) VERBOSE=yes ;;
     -faster)  FASTER=yes ;;
     -use-port)    ILTPORT=$1 ; shift ;;
     -port)    PORTASKED=yes ; SILENT=yes ;;
     -silent | -quiet) SILENT=yes ;;
     -help | --help) usage ; exit 0 ;;
     [-+][hH])    usage ; exit 0 ;;
     -usage)   usage ; exit 0 ;;
     -version | --version) echo "ILOG Talk version 3.2" ; exit 0 ;;
     *)     echo "** $RUNTALK error: illegal argument: " $ARG     >&2
          usage 1>&2
          exit 1 ;;
     esac
done

# make sense!
if [ "$VERBOSE" = "yes" ]
then SILENT=no
fi

# welcome message
if [ "$SILENT" != "yes" ]
then
echo                        >&2
echo "Welcome to ""ILOG Talk version 3.2"'!'                         >&2
fi

if [ "$VERBOSE" = "yes" -a "$FASTER" != "yes" ]
then
echo                        >&2
echo "You are using the easy start-up procedure, which launches an Emacs session"          >&2
echo "and an interactive ILOG Talk session \"$CMD\" in an Emacs buffer."          >&2
fi

if [ "$VERBOSE" = "yes" ]
then echo >&2
     usage 1>&2
     if [ "$FASTER" = "yes" ]
     then :
     else echo >&2
          echo "Call the \"runtalk\" script passing the -faster flag to learn how to" >&2
          echo "start your session faster." >&2
     fi
else if [ "$SILENT" = "yes" ]
     then :
     else if [ "$FASTER" = "yes" ]
          then echo >&2
               echo "Call the \"runtalk\" script passing the -verbose flag if you want to" >&2
               echo "learn more about its use." >&2
          else echo >&2
               echo "Call the \"runtalk\" script passing the -verbose flag if you want to" >&2
               echo "learn more about its use, or the -faster flag to learn how to start" >&2
               echo "your session faster." >&2
fi   fi   fi

if [ "$DARKBG" = "unknown" ]
then DARKBG="()"
     COLOR="-bg LightGrey -fg Black"
     if [ "$VERBOSE" = "yes" ]
     then echo                        >&2
          echo "If you prefer your own color settings for xemacs, you should"     >&2
          echo "declare whether your background is light or dark:"     >&2
          echo "   $RUNTALK -bg dark|light"     >&2
fi   fi

# find this script's filename
local_which "$0"
SCRIPTFILE=$WHICH_RESULT

if [ "$SCRIPTFILE" = "" ]
then echo                        >&2
     echo "** $RUNTALK error: something's wrong with your PATH variable." >&2
     echo "   Please call $RUNTALK specifying its path, e.g. talk32/$RUNTALK" >&2
     exit 1
fi

# get the real script filename, not a symbolic link to it
# hack: "grep ->" instead of non-standard "test -h"
while ( ls -l $SCRIPTFILE | grep " -> " > /dev/null )
do
     SCRIPTFILE=`ls -l $SCRIPTFILE | sed -e "s/.* -> //"`
     SCRIPTFILELINKED=yes
done

# STEP 3: determine the port (ILTPORT)

if [ "$ILTPORT" = "" ]
then

UNAMESRM=`uname -srm`

# that's ILTPORT when we don't know
ILTPORT=unknown

# find out which os we're running
if (echo $UNAMESRM | grep "SunOS 4" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=sparc_4_
     if (echo $UNAMESRM | grep "SunOS 4[.]1[.]3.* sun4" > /dev/null)
     then :
     else echo                        >&2
          echo "* $RUNTALK warning: You should upgrade to SunOS 4.1.3 with patch set U1." >&2
     fi
else
if (echo $UNAMESRM | grep "SunOS 5.* sun4" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=sparc_5_
else
if (echo $UNAMESRM | grep "SunOS 5.* i86pc" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=i86_sunos5_
else
if (echo $UNAMESRM | grep "HP-UX A[.]09.*/[78][0-9][0-9]" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=hp700
else
if (echo $UNAMESRM | grep "HP-UX [AB][.]10.*/[78][0-9][0-9]" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=hp_10
else
if (   (echo $UNAMESRM | grep "AIX" > /dev/null) \
    && (   (uname -v  | grep '^4$'  > /dev/null) \
        || (uname -rv | grep '^2 3$' > /dev/null)))
then
     CXXNAME=xlC
     ILTPORT=rs6000
else
if (echo $UNAMESRM | grep "IRIX 5[.]2" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=sgi_5.2_3
else
if (echo $UNAMESRM | grep "IRIX 5[.]3" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=sgi_5.3_4
else
if (echo $UNAMESRM | grep "IRIX64 6[.]2" > /dev/null)
then
     CXXNAME=CC
     ILTPORT=sgi_
else
if (echo $UNAMESRM | grep "OSF1 V3.* alpha" > /dev/null)
then
     CXXNAME=cxx
     ILTPORT=alpha_3
else
if (echo $UNAMESRM | grep "Linux .*86" > /dev/null)
then
     CXXNAME=g++
     ILTPORT=i86_linux1.2_gnu2.7
else
     echo                        >&2
     echo "** $RUNTALK error: system not supported $UNAMESRM" >&2
     echo     You may force a port using -use-port >&2
     exit 1
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi


if [ $ILTPORT = sparc_4_ -o $ILTPORT = sparc_5_ -o $ILTPORT = i86_sunos5_ ]
then

# find CXX's path

local_which "$CXXNAME"
CXXFILE=$WHICH_RESULT

# g++ ?
GXXNAME=g++
if [ "$GXXNAME" = "$CXXNAME" ]
then :
else local_which $GXXNAME
     GXXFILE=$WHICH_RESULT
     if [ "$CXXFILE" = "" ]
     then
# last chance, try g++
          if [ "$GXXFILE" = "" ]
          then :
          else CXXNAME=$GXXNAME
               CXXFILE=$GXXFILE
          fi
     else
          if [ "$GXXFILE" = "" ]
          then :
# warn that we prefered CC over g++
               else echo "* $RUNTALK warning: both $CXXNAME and $GXXNAME are available." >&2
               echo "  ILOG Talk will now use $CXXNAME.  If you want to override this choice," >&2
               echo "  pass flag -use-port ${ILTPORT}gnu to $RUNTALK." >&2
fi   fi   fi

if [ "$CXXFILE" = "" ]
then

echo                        >&2
echo "** $RUNTALK error: $CXXNAME couldn't be found in \$PATH." >&2
if [ $ILTPORT = sparc_4_ ]
then ILTPORT=sparc_4_4.0
else if [ $ILTPORT = sparc_5_ ]
     then ILTPORT=sparc_5_4.0
     else if [ $ILTPORT = i86_sunos5_ ]
          then ILTPORT=i86_sunos5_4.0
          fi
     fi
fi
echo "          Using port $ILTPORT." >&2
echo "          You may override this choice with the flag -use-port." >&2

else

case $CXXFILE in
/*)                                   ;;
*)      CXXFILE=`pwd`/$CXXFILE ;;
esac

if [ "$CXXNAME" = "g++" -a $ILTPORT != i86_sunos5_ ]
then
     ILTPORT=${ILTPORT}gnu
     SUPPORTEDCXXVERSION='2.[678]'
     BESTCXXVERSION=2.7.2
     CXXVERSION=`$CXXNAME -v 2>&1 | grep -i "gcc version" | sed -e "s/.* //" | head -1`
     if ( echo $CXXVERSION | grep "^$SUPPORTEDCXXVERSION" > /dev/null )
     then
          # OK, the default version of g++ is 2.7.x
          :
     else
          CXXOUTPUT=`$CXXNAME -V $BESTCXXVERSION -v 2>&1 | grep "^Reading specs"`
          if test -n "$CXXOUTPUT"
          then
               # OK, g++ -V $BESTCXXVERSION finds its specs file.
               :
          else
               (echo "* $RUNTALK warning: ILOG Talk supports $CXXNAME $SUPPORTEDCXXVERSION," >&2
                echo "but you are using $CXXNAME $CXXVERSION.") >&2
          fi
     fi
else
     if [ $ILTPORT = sparc_4_ ]
     then
          CCVERSION=`strings $CXXFILE | grep RELEASE | sed -e "s/.* SC//" -e "s/ .*//" | grep "^[0-9].[0-9]" | head -1`
          if ( echo $CCVERSION | grep "^1." >/dev/null )
          then CXXVERSION=2.1
          else if ( echo $CCVERSION | grep "^2." >/dev/null )
               then CXXVERSION=3.0
               else if ( echo $CCVERSION | grep "^3." >/dev/null )
                    then CXXVERSION=4.0
                    else echo                        >&2
                         echo "** $RUNTALK error: C++ compiler not supported $CXXFILE" >&2
                         strings $CXXFILE | grep RELEASE | head -3 >&2
                         echo     You may force a port using -use-port >&2
                         exit 1
          fi   fi   fi
          ILTPORT=$ILTPORT$CXXVERSION
     else
          CXXVERSION=`(if test -f null.i ; then CC -V -P /dev/null -o /tmp/foo.$$.i ; else CC -V -P /dev/null -o /tmp/foo.$$.i ; rm -f null.i ; fi ; rm -f /tmp/foo.$$.i) 2>&1 | grep C++ | sed -e "s/.*C++/ /" -e "s/ *//" -e "s/ .*//" -e "s/\([0-9][.][0-9]\).*/\1/" | head -1`
# head -1 is there for the case of license error, which introduces more "C++" lines.
          if [ "$CXXVERSION" = "" ]
          then
               (echo "** $RUNTALK error: cant tell which C++ compiler you are using."
                echo "   Apparently, CC is the command, but CC -V doesn't tell the version number;"
                echo "   please tell $RUNTALK which port to use, using the flag -use-port."
                echo "   Maybe CC is faked, and is in fact a g++ compiler -- in that case"
                echo "   pass the flag -use-port sparc_5_gnu.") >&2
               exit 1
          else
          ILTPORT=$ILTPORT$CXXVERSION
     fi   fi

fi # if [ "$CXXNAME" = "g++" -a $ILTPORT != i86_sunos5_ ] ...

fi # if [ "$CXXFILE" = "" ] ...

fi # if [ $ILTPORT = sparc_4_ -o $ILTPORT = sparc_5_ -o $ILTPORT = i86_sunos5_ ] ...

if [ $ILTPORT = sgi_ ]
then
     echo "* $RUNTALK warning: both ports sgi_5.3_4 and sgi_6.2_6.2 are available." >&2
     echo "  ILOG Talk will now use sgi_5.3_4.  If you want to override this choice," >&2
     echo "  pass flag -use-port sgi_6.2_6.2 to $RUNTALK." >&2
     ILTPORT=sgi_5.3_4
fi

fi # if [ "$ILTPORT" = "" ] ...

if [ "$ILTPORT" = "" ]
then echo "** $RUNTALK error: couldn't tell the port you should use" >&2 ; exit 1
fi

if [ "$PORTASKED" = "yes" ]
then echo $ILTPORT ; exit 0
fi


# STEP 4: set up variables

# the script directory is ILT_DIR!
ILT_DIR=`dirname $SCRIPTFILE` ; export ILT_DIR
ILT_DIR_DIR=`dirname $ILT_DIR`

# from ILT_DIR spurs other environment variable values.

# ILOG Views home directory
ILT_CLEAN_DIR=`echo $ILT_DIR | sed -e 's%/[.]$%%g' -e 's%/[.]$%%g'`

if [ "$ILVHOME" = "" ]
then ILVHOME=`dirname $ILT_CLEAN_DIR`/views22 ; export ILVHOME
     if [ -d $ILVHOME ]
     then :
     else ILVHOME=`dirname $ILT_CLEAN_DIR`/views ; export ILVHOME
     fi
     echo "* $RUNTALK warning for ILOG Views users: setting ILVHOME to $ILVHOME" >&2
     SETTINGILVHOME=yes
else
     SETTINGILVHOME=no
fi

if [ -x $ILT_DIR/talk/$ILTPORT/$DEFAULTCMD ]
then :
else echo >&2
     echo "** $RUNTALK error: ILOG Talk port to $ILTPORT is not installed." >&2
     echo "   Please tell $RUNTALK which other port to use, using the flag -use-port." >&2
     echo "   Unix ports installed are:" >&2
     ls -d $ILT_DIR/talk/*/$DEFAULTCMD | sed -e "s%/$DEFAULTCMD\$%%" -e "s%.*/%   %"
     exit 1
fi

# command search path. Adjoin iltviews path too.
PATH=$ILT_DIR/talk/$ILTPORT:$ILT_DIR/powercls/$ILTPORT:$ILT_DIR/iltviews/$ILTPORT:$ILVHOME/bin/$ILTPORT:$PATH ; export PATH

# dynamic library search path
case $ILTPORT in
  hp700 | hp_10 )
    SHLIB_PATH=$ILT_DIR/lib/$ILTPORT:$ILVHOME/lib/$ILTPORT:${SHLIB_PATH-"/lib:/usr/lib"}
    export SHLIB_PATH ;;
  rs6000 )
    LIBPATH=$ILT_DIR/lib/$ILTPORT:$ILVHOME/lib/$ILTPORT:${LIBPATH-"/lib:/usr/lib"}
    export LIBPATH ;;
  * )
    LD_LIBRARY_PATH=$ILT_DIR/lib/$ILTPORT:$ILVHOME/lib/$ILTPORT:${LD_LIBRARY_PATH-"/lib:/usr/lib"}
    export LD_LIBRARY_PATH ;;
esac

# STEP 5: locate Emacs

if [ "$PASSEDXEMACS" != "" ]
then

XEMACS=$PASSEDXEMACS

else

case $ILTPORT in
sparc_4_*) XESYS=sparc-sun-sunos4.1.3 ;;
sparc_5_*) XESYS=sparc-sun-solaris2.4 ;;
hp700)     XESYS=hppa1.1-hp-hpux9.05 ;;
hp_10)     XESYS=hppa1.0-hp-hpux10.00 ;;
rs6000)    case `uname -v` in
           3) XESYS=rs6000-ibm-aix3.2.5 ;;
           *) XESYS=rs6000-ibm-aix4.1.1 ;;
           esac ;;
sgi_5.2*)  XESYS=mips-sgi-irix5.2 ;;
sgi_5.3* | sgi_6.2*) XESYS=mips-sgi-irix5.3 ;;
alpha_3)   XESYS=alpha-dec-osf3.2 ;;
i86_linux*) XESYS=i486-unknown-linuxelf ;;
i86_sunos5_*) XESYS=i486-pc-solaris2.4 ;;
esac

local_which xemacs
XEMACSFILE=$WHICH_RESULT

# hack: on alpha, xemacs is most often a mere emacs!
# if we found such a faked XEmacs, forget it.
if [ $XESYS = alpha-dec-osf2.1 ]
then
     local_which emacs
     EMACSFILE=$WHICH_RESULT
     if [ -x "$EMACSFILE" -a "$EMACSFILE" != "" ]
     then if ( ls -idL $XEMACSFILE $EMACSFILE | sort -u +0 -1 | wc -l | grep 1 >/dev/null )
          then XEMACSFILE=""
fi   fi   fi

if [ -x "$XEMACSFILE" -a "$XEMACSFILE" != "" ]
then XEMACS=xemacs
     if [ "$VERBOSE" = "yes" ]
     then if [ -x $ILT_DIR_DIR/xemacs/bin/$XESYS/xemacs ]
          then
               if ( ls -idL $XEMACSFILE $ILT_DIR_DIR/xemacs/bin/$XESYS/xemacs | sort -u +0 -1 | wc -l | grep -v 1 >/dev/null )
               then echo                        >&2
                    echo "Congratulations: You already have XEmacs in $XEMACSFILE." >&2
                    echo "You may can save a lot of disk space by removing the redundant" >&2
                    echo "XEmacs installation supplied with ILOG Talk in" >&2
                    echo "$ILT_DIR_DIR/xemacs" >&2
     fi   fi   fi
else XEMACS=$ILT_DIR_DIR/xemacs/bin/$XESYS/xemacs
     if [ -x $XEMACS ]
     then :
     else
          local_which lemacs
          LEMACSFILE=$WHICH_RESULT
          if [ -x "$LEMACSFILE" -a "$LEMACSFILE" != "" ]
          then XEMACS=lemacs
          else
               local_which emacs
               EMACSFILE=$WHICH_RESULT
               if [ -x "$EMACSFILE" -a "$EMACSFILE" != "" ]
               then XEMACS=emacs
               else echo                        >&2
                    echo "** $RUNTALK error: cant locate any Emacs. Please install XEmacs supplied in" >&2
                    echo "$ILT_DIR_DIR, or update variable PATH to reach you favarite Emacs" >&2
                    exit 1
fi   fi   fi   fi

fi

# STEP 6: install eval license if any


# set up TMP_ILOG_LICENSE_FILE default value if undefined
if [ "$TMP_ILOG_LICENSE_FILE" = "" ]
then
  TMP_ILOG_LICENSE_FILE=/usr/ilog/ilm/access.ilm
else
  TMP_ILOG_LICENSE_FILE=$ILOG_LICENSE_FILE
fi

# find the longest lasting talk eval license file
TALKEVALLICENSEFILE=`( echo /x/x/x/x/x/x ; ls $ILT_DIR/talk-eval-license-till-*.ilm $ILT_DIR_DIR/talk-eval-license-till-*.ilm 2>/dev/null ) | tail -1`

if [ -r $TALKEVALLICENSEFILE ]
then

# check the eval license is in the license file, or append it

  EVAL_ALREADY_IN_SOME_LICENSE_FILE=no

  for MAINLICENSEFILE in `echo $TMP_ILOG_LICENSE_FILE | tr ":" " "` /x/x/x/x/x/x
  do
    if [ -r $MAINLICENSEFILE ]
    then
      if [ `sort < $MAINLICENSEFILE | comm -12 - $TALKEVALLICENSEFILE | wc -l` = 1 ]
      then EVAL_ALREADY_IN_SOME_LICENSE_FILE=yes
      fi
    fi
  done

  if [ "$EVAL_ALREADY_IN_SOME_LICENSE_FILE" = "no" ]
  then
    if [ "$ILOG_LICENSE_FILE" = "" ]
    then
      ILOG_LICENSE_FILE="$TALKEVALLICENSEFILE":$TMP_ILOG_LICENSE_FILE
      export ILOG_LICENSE_FILE
      echo "* $RUNTALK warning: setting ILOG_LICENSE_FILE file list to" >&2
      echo "  $ILOG_LICENSE_FILE" >&2
    else
      ILOG_LICENSE_FILE="$TALKEVALLICENSEFILE":"$ILOG_LICENSE_FILE"
      export ILOG_LICENSE_FILE
      echo "* $RUNTALK warning: prepending your evaluation license file" >&2
      echo "  ($TALKEVALLICENSEFILE) to ILOG_LICENSE_FILE file list"  >&2
    fi
    echo "  Maybe you should append the license file ($TALKEVALLICENSEFILE)" >&2
    echo "  contents to your regular license file ($TMP_ILOG_LICENSE_FILE)" >&2
  fi
fi


# STEP 7: chat

if [ "$VERBOSE" = "yes" ]
then

echo                        >&2
echo "The license file is:" >&2
echo "   $ILOG_LICENSE_FILE" >&2
echo                        >&2
echo "The command that runtalk will use to start its Emacs session is:" >&2
echo "   $XEMACS" >&2
echo "You can use the -use-emacs flag to override this command." >&2
echo                        >&2
echo "The command that runtalk will use to start an ILOG Talk session is:" >&2
echo "   $CMD" >&2
echo "You can use the -run flag to override this command." >&2
echo                        >&2
echo "The Talk and Views port for your system is:" >&2
echo "   $ILTPORT" >&2
echo "You can use the -use-port flag to override this value." >&2

fi

if [ "$VERBOSE" = "yes" -o "$FASTER" = "yes" ]
then

# dynamic library search path
case $ILTPORT in
  hp700 | hp_10 ) LDLPV=SHLIB_PATH ;;
  rs6000 )        LDLPV=LIBPATH ;;
  * )             LDLPV=LD_LIBRARY_PATH ;;
esac

echo                        >&2
echo "To start your ILOG Talk session faster, don't use runtalk. Instead,"     >&2
echo "type the following at a Unix shell (sh, ksh, or bash):" >&2
echo                        >&2
echo "   \$ cat >> \$HOME/.emacs << "'!'     >&2
echo "   (load-file (concat (getenv \"ILT_DIR\") \"/talk/emacs/dot-emacs\"))"     >&2
echo "   (setq tm:dark-background-p $DARKBG)"     >&2
echo "   ;; Optional: start Talk head-on"'!'     >&2
echo "   (run-talk \"$CMD\")"     >&2
echo "   "'!'     >&2
echo "   \$ ILTPORT=$ILTPORT"
echo "   \$ ILT_DIR=$ILT_DIR"     >&2
if [ $SETTINGILVHOME = yes ]
then
echo "   \$ ILVHOME=$ILVHOME"     >&2
fi
echo "   \$ PATH=\$ILT_DIR/talk/\$ILTPORT:\$PATH" >&2
echo "   \$ PATH=\$ILT_DIR/powercls/\$ILTPORT:\$PATH" >&2
echo "   \$ PATH=\$ILT_DIR/iltviews/\$ILTPORT:\$PATH" >&2
echo "   \$ PATH=\$ILVHOME/bin/\$ILTPORT:\$PATH" >&2
echo "   \$ $LDLPV=\${$LDLPV-\"/lib:/usr/lib\"}" >&2
echo "   \$ $LDLPV=\$ILT_DIR/lib/\$ILTPORT:\$$LDLPV" >&2
echo "   \$ $LDLPV=\$ILVHOME/lib/\$ILTPORT:\$$LDLPV" >&2
# echo "   \$ . $ILT_DIR/talk/$ILTPORT/iltsetup.sh"     >&2
echo "   \$ export PATH" >&2
echo "   \$ export $LDLPV" >&2
echo "   \$ export ILT_DIR"     >&2
if [ $SETTINGILVHOME = yes ]
then
echo "   \$ export ILVHOME"     >&2
fi
echo "   \$ $XEMACS $COLOR"     >&2



echo ""     >&2
echo "or, if you use csh or tcsh:"     >&2
echo                        >&2
echo "   % cat >> \$HOME/.emacs << "'!'     >&2
echo "   (load-file (concat (getenv \"ILT_DIR\") \"/talk/emacs/dot-emacs\"))"     >&2
echo "   (setq tm:dark-background-p $DARKBG)"     >&2
echo "   ;; Optional: start Talk head-on"'!'     >&2
echo "   (run-talk \"$CMD\")"     >&2
echo "   "'!'     >&2
echo "   % set ILTPORT = $ILTPORT"
echo "   % setenv ILT_DIR $ILT_DIR"     >&2
if [ $SETTINGILVHOME = yes ]
then
echo "   % setenv ILVHOME $ILVHOME"     >&2
fi
echo "   % setenv PATH \${ILT_DIR}/talk/\${ILTPORT}:\${PATH}" >&2
echo "   % setenv PATH \${ILT_DIR}/powercls/\${ILTPORT}:\$PATH" >&2
echo "   % setenv PATH \${ILT_DIR}/iltviews/\${ILTPORT}:\${PATH}" >&2
echo "   % setenv PATH \${ILVHOME}/bin/\${ILTPORT}:\${PATH}" >&2
echo "   % if (! \${?$LDLPV}) then" >&2
echo "   % setenv $LDLPV \"/lib:/usr/lib\"" >&2
echo "   % endif" >&2
echo "   % setenv $LDLPV \${ILT_DIR}/lib/\${ILTPORT}:\${$LDLPV}" >&2
echo "   % setenv $LDLPV \${ILVHOME}/lib/\${ILTPORT}:\${$LDLPV}" >&2
# echo "   % . $ILT_DIR/talk/$ILTPORT/iltsetup.sh" >&2
echo "   % $XEMACS $COLOR"     >&2

fi

# STEP 8: run!

if [ "$FASTER" != "yes" ]
then

EMACSINITFILE=/tmp/talk-emacs.$$
cat > $EMACSINITFILE << !
(load-file (concat (getenv "ILT_DIR") "/talk/emacs/dot-emacs"))
(setq tm:dark-background-p $DARKBG)
(run-talk "$CMD")
!

# launch an emacs which loads talk/emacs/dot-emacs and launches italk
$XEMACS \
  -l $EMACSINITFILE \
  $COLOR

rm $EMACSINITFILE

fi

echo                        >&2
