#!/bin/sh
# $Id: .slocator,v 1.2 2008/01/09 08:53:43 frpasa Exp $
#################################################################
# File_Name_Id <.locator>                (c) Kalimetrix 2014
#
#       TELELOGIC PRODUCT tools variables definition
#
#################################################################
# SYS5
# this script looks for the root directory of the TELELOGIC PRODUCT
#             structure, sets up the environment
#             and calls the invoked tool
#################################################################
#
# TROOT -> installation directory
#

#
# Modify LC_* values 
#

unset LANG
unset LC_COLLATE
unset LC_MESSAGES
unset LC_MONETARY
unset LC_NUMERIC
unset LC_TIME
unset LC_CTYPE
unset LC_ALL

CTO_LANG=en
export CTO_LANG

export LANG
export LC_TIME
export LC_COLLATE
export LC_MESSAGES
export LC_MONETARY
export LC_NUMERIC
export LC_CTYPE
export LC_ALL

#--------------------------------------------------------------
# Modify PATH if necessary
#
ADD_PATH="/bin /usr/bin /usr/5bin /usr/ucb /etc /usr/ccs/bin"
for i in $ADD_PATH ;do
   case ":${PATH}:" in
   *:$i:*)  ;;
   *)       PATH=$PATH:$i
   esac
done
export PATH
 
#--------------------------------------------------------------
# Get the command name 
#--------------------------------------------------------------
cwd=`/bin/pwd`
case "$0" in
../*)   mypname="$cwd/$0" ;;
./*)    mypname="$cwd/$0" ;;
/*)     mypname="$0" ;;
*/*)    mypname="$cwd/$0" ;;
*) 	mypname="$cwd/$0" ;;
esac
#
# find the name of the tool invoked
# remove the filename, request a cd and get the pname of the
# corresponding directory

if [ -f /bin/expr ] ; then
	tool=`/bin/expr $mypname'/' : '.*[^/]//*\([^/][^/]*\)//*$'`
	export tool
	#
	mypname=`/bin/expr $mypname'/' : '\(.*[^/]\)//*[^/][^/]*//*$'`
elif [ -f /usr/bin/expr ] ; then  # Linux
	tool=`/usr/bin/expr $mypname'/' : '.*[^/]//*\([^/][^/]*\)//*$'`
	export tool
	#
	mypname=`/usr/bin/expr $mypname'/' : '\(.*[^/]\)//*[^/][^/]*//*$'`
fi

#
PWD=$cwd
export PWD

#--------------------------------------------------------------
#  Machine identification . Set up some useful variables
#--------------------------------------------------------------
#
if [ -f /bin/uname ] ; then
   mach_os=`/bin/uname -s`
   mach_ver=`/bin/uname -r`
   mach_typ=`/bin/uname -m`
elif [ -f /usr/5bin/uname ] ; then  # sunOS 4.0x
   mach_os=`/usr/5bin/uname -s`
   mach_ver=`/usr/5bin/uname -r`
   mach_typ=`/usr/5bin/uname -m`
else
   mach_os="unknown_os"
   mach_ver="unknown_ver"
   mach_typ="unknown_typ"
fi

#--------------------------------------------------------------
# selecting OS
#--------------------------------------------------------------
case "$mach_os" in

#--------------------------------------------------------------
# SunOS
#--------------------------------------------------------------
SunOS) case "$mach_ver" in
       4*) case "$mach_typ" in
            sun3*) V_WHOAMI="sun3/" ;;
            *) V_WHOAMI="sun4/" ;;
           esac
           ;;
       5*) V_WHOAMI="sun4os5/" ;;
       esac
       ;; 

#--------------------------------------------------------------
# Linux
#--------------------------------------------------------------
Linux) V_WHOAMI="linux/"
       ;; 

#--------------------------------------------------------------
# Hewlett-Packard HP-UX
#--------------------------------------------------------------
HP-UX) if [ -f /bin/hp9000s400 ] ;then
          if ( /bin/hp9000s400 = 0 ) ;then
             V_WHOAMI="hp3/"
             break
          fi
       fi

       if [ -f /bin/hp9000s700 ] ;then
          if ( /bin/hp9000s700 = 0 ) ;then
             V_WHOAMI="hp8/"
             break
          fi
       fi

       # HP-UX 9000/8x7 
       if [ -f /bin/hp9000s800 ] ;then
          if ( /bin/hp9000s800 = 0 ) ;then
             case "$mach_typ" in
             *890) V_WHOAMI="hp8/" ;;  # hp9000s700 comp.
             *8*7) V_WHOAMI="hp8/" ;;  # hp9000s700 comp.
             *)    V_WHOAMI="hp8/" ;;  # hp9000s800 for real.
             esac
             break
          fi
       fi
       ;;

#--------------------------------------------------------------
# DEC Ultrix
#--------------------------------------------------------------
ULTRIX) V_WHOAMI="ultrix/"
        ;;

#--------------------------------------------------------------
# IBM Risc 6000 AIX
#--------------------------------------------------------------
AIX) V_WHOAMI="aix/"
        ;;

#--------------------------------------------------------------
# Alpha OSF1
#--------------------------------------------------------------
OSF*) V_WHOAMI="alpha/"
      if [ -f /usr/bin/uac ]; then
         uac p 0            # get rid of spurious messages
      fi
      ;;

#--------------------------------------------------------------
# Unknown ?
#--------------------------------------------------------------
*) V_WHOAMI="unknown"
   echo "Unknown OS.  Execution failed"
   echo
   exit 1
   ;;
esac
export V_WHOAMI

#--------------------------------------------------------------
# Kalimetrix TT Product stuff
#--------------------------------------------------------------
case "$mypname" in
*/.)   vinst=`echo $mypname | sed -e 's+/[^/]*/\.++'` ;;
*/..)  vinst=`echo $mypname | sed -e 's+/[^/]*/[^/]*/\.\.++'` ;;
*)     vinst=`echo $mypname | sed -e 's+/[^/]*$++'` ;;
esac
#
TROOT=$vinst
export TROOT
#
#------------------------------------------------------------
# environment variables for ObjectGEODE
#------------------------------------------------------------
AGE=$TROOT
GEODE=$TROOT
VERILOG=$TROOT/tools
VERILANG=gb
export AGE GEODE VERILANG VERILOG

#--------------------------------------------------------------
# Dynamic librairies
#--------------------------------------------------------------
LD_LIBRARY_PATH=`echo "$LD_LIBRARY_PATH" | sed -e 's+^/usr/lib[^:]*:\?++' -e 's+:/usr/lib[^:]*++g' -e 's+^/lib[^:]*:\?++' -e 's+:/lib[^:]*++g'`
export LD_LIBRARY_PATH
case "$V_WHOAMI" in
  sun4/|sun4os5/|alpha/|linux/)
	   case ":${LD_LIBRARY_PATH}:" in
	     *:$TROOT/lib/$V_WHOAMI:*) ;; # already there
	     ::) LD_LIBRARY_PATH=$TROOT/lib/$V_WHOAMI ;;
	     *) LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TROOT/lib/$V_WHOAMI ;;
	   esac
	   case ":${LD_LIBRARY_PATH}:" in
	     *:$TROOT/bin/$V_WHOAMI:*) ;; # already there
	     ::) LD_LIBRARY_PATH=$TROOT/bin/$V_WHOAMI ;;
	     *) LD_LIBRARY_PATH=$TROOT/bin/$V_WHOAMI:$LD_LIBRARY_PATH ;;
	   esac
	   DLL_SUFFIX=so
	   export DLL_SUFFIX
	   export LD_LIBRARY_PATH
	   ;;
  hp8/|hp3/)
	   case ":${SHLIB_PATH}:" in
	     *:$TROOT/lib/$V_WHOAMI:*) ;; # already there
	     ::) SHLIB_PATH=$TROOT/lib/$V_WHOAMI ;;
	     *) SHLIB_PATH=$SHLIB_PATH:$TROOT/lib/$V_WHOAMI ;;
	   esac
	   case ":${SHLIB_PATH}:" in
	     *:$TROOT/bin/$V_WHOAMI:*) ;; # already there
	     ::) SHLIB_PATH=$TROOT/bin/$V_WHOAMI ;;
	     *) SHLIB_PATH=$SHLIB_PATH:$TROOT/bin/$V_WHOAMI ;;
	   esac
	   case ":${SHLIB_PATH}:" in
	     *:/usr/lib:*) ;; # already there
	     *:/usr/lib/:*) ;; # already there
	     *) SHLIB_PATH=$SHLIB_PATH:/usr/lib ;;
	   esac
	   export SHLIB_PATH
	   ;;
  aix/)
	   case ":${LIBPATH}:" in
	     *:$TROOT/lib/$V_WHOAMI:*) ;; # already there
	     ::) LIBPATH=$TROOT/lib/$V_WHOAMI ;;
	     *) LIBPATH=$LIBPATH:$TROOT/lib/$V_WHOAMI ;;
	   esac
	   case ":${LIBPATH}:" in
	     *:$TROOT/bin/$V_WHOAMI:*) ;; # already there
	     ::) LIBPATH=$TROOT/bin/$V_WHOAMI ;;
	     *) LIBPATH=$LIBPATH:$TROOT/bin/$V_WHOAMI ;;
	   esac
	   case ":${LIBPATH}:" in
	     *:/usr/lib:*) ;; # already there
	     *:/usr/lib/:*) ;; # already there
	     *) LIBPATH=$LIBPATH:/usr/lib ;;
	   esac
	   export LIBPATH
	   ;;
  *) ;; # nothing to do
esac

#--------------------------------------------------------------
# Modify PATH if necessary - Ensure Logiscope path is first
#--------------------------------------------------------------
case "${PATH}:" in
$TROOT/bin:*) ;; # already there
*) PATH=$TROOT/bin:$PATH ;;
esac
export PATH

#--------------------------------------------------------------
#  token license file
#--------------------------------------------------------------
# Modify LM_LICENSE_FILE if necessary
#--------------------------------------------------------------
case ":${LM_LICENSE_FILE}:" in
*:$TROOT/etc/license.dat:*) ;; # already there
::) LM_LICENSE_FILE=$TROOT/etc/license.dat ;;
*) LM_LICENSE_FILE=$LM_LICENSE_FILE:$TROOT/etc/license.dat ;;
esac
export LM_LICENSE_FILE

#--------------------------------------------------------------
#  Old CPU license mode
#--------------------------------------------------------------
# For a CPU license mode, set the VLG_LM_CPU variable here
#      and in the "../etc/.flexlocator" script.
# VLG_LM_CPU=on ; export VLG_LM_CPU

#--------------------------------------------------------------
#  Setting PIPE numbers
#--------------------------------------------------------------
# Pipes used between TOOL.lnc and TOOL.bin
VLG_LM_PIPE="30 31"
export VLG_LM_PIPE

#--------------------------------------------------------------
#  Setting dialect flag
#--------------------------------------------------------------
# Next value can be changed to $TROOT/ref/fr for french dialect
#
# La valeur suivante peut etre changee par $TROOT/ref/fr afin d'utiliser
# les produits logiscope en francais
LOG_MESSAGE=$TROOT/bin
export LOG_MESSAGE

#--------------------------------------------------------------
# Setting Help environment
#--------------------------------------------------------------
HELP_DIR=$TROOT/help/english
export HELP_DIR
WORLDVIEW=$TROOT/WorldView
export WORLDVIEW
if [ -z "$BROWSER" ]
then
   BROWSER=netscape
   export BROWSER
fi


#--------------------------------------------------------------
# Default commands
#--------------------------------------------------------------
# Chemin d'acces aux commandes par defaut
# Path to default commands
if [ ".$LOG_UTIL" = "." ] ; then
    LOG_UTIL=$TROOT/util
fi
export LOG_UTIL

#--------------------------------------------------------------
# X ressources
#--------------------------------------------------------------
# Chemin d'acces aux ressources X
# Path to X ressources
if [ ".$XBMLANGPATH" = "." ] ; then
   XBMLANGPATH=$TROOT/Xutil/bitmaps/%B
else
   XBMLANGPATH=$XBMLANGPATH:$TROOT/Xutil/bitmaps/%B
fi
export XBMLANGPATH

if [ ".$XFILESEARCHPATH" = "." ] ; then
	XFILESEARCHPATH=$TROOT/Xutil/%N%S
else
	XFILESEARCHPATH=$XFILESEARCHPATH:$TROOT/Xutil/%N%S
fi
export XFILESEARCHPATH

#--------------------------------------------------------------
# UID ressources
#--------------------------------------------------------------
# Chemin d'acces aux ressources uid
# Path to uid resssources
if [ ".$UIDPATH" = "." ] ; then
	UIDPATH=$TROOT/Xutil/uid/$V_WHOAMI/%U:$TROOT/Xutil/uid/%U:./%U
else
	UIDPATH=$UIDPATH:$TROOT/Xutil/uid/$V_WHOAMI/%U:$TROOT/Xutil/uid/%U:./%U
fi
export UIDPATH

#XAPPLRESDIR=$TROOT/Xutil
#export XAPPLRESDIR
#

#------------------------------------------------------------
# build the command invoked
#
# possibly :
#       tool.cmd tool.lnc tool.bin      or
#       tool.cmd tool.lnc               or
#       tool.cmd                        or
#       tool.cmd tool.bin               or
#       tool.lnc tool.bin               or
#       tool.bin
#------------------------------------------------------------
#
#--------------------------------------------------------------
# Starting the application
#--------------------------------------------------------------
PATH_TOOL=$TROOT/bin/$V_WHOAMI$tool
export PATH_TOOL

PATH_BIN=$TROOT/bin/$V_WHOAMI
export PATH_BIN

#
# Host specific: Is there any .cmd script ?
#
if [ -r "$PATH_TOOL.cmd" ]
then
   TOOL_CMD=$PATH_TOOL.cmd
else
   if [ -r $TROOT/bin/$tool.cmd ]
   then
        TOOL_CMD=$TROOT/bin/$tool.cmd
   else
        TOOL_CMD=""
   fi
fi

#------------------------------------------------------------
# LG_ALI --> MetricBase.ali file
# LG_RENF --> LpjApi.ren
#------------------------------------------------------------
LG_ALI=$TROOT/Ref/MetricBase.ali
LG_RENF=$TROOT/Ref/LpjApi.ren
export LG_ALI
export LG_RENF

#------------------------------------------------------------
# looking for a file .bin
#------------------------------------------------------------

if [ -r $PATH_TOOL.exe ]
then
       	TOOL_BIN=$PATH_TOOL.exe
else
if [ -r $PATH_TOOL.bin ]
then
        TOOL_BIN=$PATH_TOOL.bin
else
        if [ ".$TOOL_CMD" = "." ]
        then
                /bin/echo "*** This Kalimetrix Product software is not correctly installed."
                /bin/echo "    Can't find the tool to invoke: $TROOT/bin/$tool"
                /bin/echo "    Please, consult your system administrator."
                exit
        else
                TOOL_BIN=""
        fi
fi
fi
export TOOL_BIN
if [ ".$TOOL_BIN" != "." ]
then
    interp=`$TROOT/bin/linux/patchelf --print-interpreter "$TOOL_BIN" 2>/dev/null`
    if [ $? -ne 0 ]
    then
            /bin/echo "*** This Kalimetrix Product software has been moved."
            /bin/echo "    (patchelf existed in error)."
            /bin/echo "    Please, run setup_path to set the correct ELF"
            /bin/echo "    interpreter to $TROOT/misc/linux/ld-linux.so.2."
            exit 1
    elif [ "x$interp" != "x" ]
    then
	if [ ! -f "`dirname $interp`/ldlog" ]
	then
            /bin/echo "*** This Kalimetrix Product software has been moved."
            /bin/echo "    ELF interpreter $interp is not correct."
            /bin/echo "    Please, run setup_path to set the correct ELF"
            /bin/echo "    interpreter to $TROOT/misc/linux/ld-linux.so.2."
            exit 1
	fi
    fi
fi
#------------------------------------------------------------
# looking for a file .lnc
#------------------------------------------------------------

if [ -r $PATH_TOOL.lnc ]
then
        TOOL_LNC="$PATH_TOOL.lnc -Lnoquery"
else
        TOOL_LNC=""
fi

#------------------------------------------------------------
# running the command
#------------------------------------------------------------
if [ "$#" = "0" ]
then
  exec $TOOL_CMD $TOOL_LNC $TOOL_BIN
else
  exec $TOOL_CMD $TOOL_LNC $TOOL_BIN "$@"
fi
#------------------------------------------------------------