#!/bin/sh
#---------------------------------------------------------------------
#- AsmGofer v. 1.1
#- Joachim Schmid (Siemens Research Munich), September 1999
#- This file is adopted from TkGofer
#---------------------------------------------------------------------
#- TkGofer v. 2.0
#- Ton Vullinghs, Koen Claessen, July 1997
#---------------------------------------------------------------------
#- asmgofer

ROOT="AsmGofer"

#---------------------------------------------------------------------
#- Variables

Prelude="$TKPRELUDE"
PreludeDir="$ROOT/Preludes"
BinDir="$ROOT/bin"
TclDir="$ROOT/Tcl"
HelpDir="$ROOT/Doc"
Args=""
ASM=""

#---------------------------------------------------------------------
#- Help?

if [ "$1" = "-?" -o "$1" = "-help" ]
then
  more "$HelpDir/asmgofer.help"
  exit
fi

#---------------------------------------------------------------------
#- Options

while [ "$1" != "" ]
do
  if [ "$1" = "-all"    \
    -o "$1" = "-mini"   \
    -o "$1" = "-conc"   \
    -o "$1" = "-noconc" \
    -o "$1" = "-std"    \
     ]
  then
    Prelude="$PreludeDir/tk.prelude$1"
  else
    if [ "$1" = "-asm" ]
    then
      ASM="$1"
    else
      if [ "$1" = "-prel" ]
      then
        Prelude="$2"
        shift
      else
        Args="$Args $1"
      fi
    fi
  fi
  shift
done

if [ "$ASM" != "" ]
then
  if [ "$Prelude" = "" ]
  then Prelude="$PreludeDir/prelude$ASM"
  else Prelude="$Prelude$ASM"
  fi
fi 

if [ "$Prelude" = "" ]
then
  Prelude="$PreludeDir/tk.prelude-all-asmH"
  ASM="-asm"
fi


#---------------------------------------------------------------------
#- Message

echo "=== AsmGofer (TkGofer v2.0) ==="
echo "AsmGofer Version 1.1 (c) Joachim Schmid 1999-2001"

head -10 "$Prelude" \
  | grep 'this prelude uses:' \
  | sed 's/-- this prelude uses/(with modules/' \
  | sed 's/.gs --/)/' \
  | sed 's/.gs/,/g' \
  | sed 's/--/-- )/g'

#---------------------------------------------------------------------
#- Start Gofer

#- Some variables

GOFER="$Prelude"                 ; export GOFER
TKGOFER=$TclDir/gofer.tcl        ; export TKGOFER

#- Editors

EDIT=${VISUAL-${EDITOR-/usr/ucb/vi}}
case `basename $EDIT` in
    emacs | vi | elvis )  EDITLINE="$EDIT +%d %s"; export EDITLINE ;;
    none               )  ;;
    *                  )  EDITLINE=$EDIT; export EDITLINE ;;
esac
export EDIT

#- Start the interpreter

MACHINE=`uname -s`-`uname -p`-`uname -m`
case $MACHINE in
  CYGWIN_NT-5.0-unknown-i686)  MACHINE=CYGWIN_NT-4.0-unknown-i686;;
  CYGWIN_NT-4.0-unknown-i686)  MACHINE=CYGWIN_NT-4.0-unknown-i686;;
  CYGWIN_98-4.10-unknown-i586) MACHINE=CYGWIN_NT-4.0-unknown-i686;;
  CYGWIN_98-4.10-unknown-i686) MACHINE=CYGWIN_NT-4.0-unknown-i686;;
  SunOS-sparc-sun4m)           MACHINE=SunOS-sparc-sun4u;;
  Linux-unknown-i586)          MACHINE=Linux-unknown-i686;;
esac
TCL_LIBRARY=AsmGofer/$MACHINE/tcl8.0
TK_LIBRARY=AsmGofer/$MACHINE/tk8.0

case $MACHINE in
  Linux-unknown-i686) TCL_LIBRARY=AsmGofer/$MACHINE/tcl8.3 
                      TK_LIBRARY=AsmGofer/$MACHINE/tk8.3;;
esac

BINARY=$BinDir/asmgoferH-$MACHINE
if [ ! -f $BINARY ]; then
  echo "cannot find binary for $MACHINE"
  echo "please compile AsmGofer (instructions in ~/sources/INSTALL)"
  exit 2
fi
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:AsmGofer/$MACHINE
export LD_LIBRARY_PATH TCL_LIBRARY TK_LIBRARY
if [ -x $BinDir/site.specific ]; then
  exec "$BinDir/site.specific" "$BINARY" $Args
else
  exec "$BINARY" $Args
fi

#---------------------------------------------------------------------
#- the end.

