#! @SH@

# file: $ISIP_IFC/util/misc/isip_xterm/isip_xterm.sh
# version: $Id: isip_xterm.sh 9611 2004-07-03 18:06:03Z picone $
#
# The isip_xterm utility invokes xterm, selecting the proper type of
# xterm, creating a suitable window title, window index, etc.
#
# 07/03/04 (joe picone): updated for linux
#
# 12/27/97 (joe picone): added a source of the environment for x11r6
# 			 this has been a constant battle - xrsh on r6 does not
#			 appear to pick up the environment
#
# 8/21/94 (joe picone): added a command line option
#  it was discovered that xon likes to start a csh independent
#  of the type of shell you use. Hence, syntax like:
#
#	xon TERM=xterm isip_xterm
#
#  doesn't work. this made launching different tools from a twmrc
#  file very difficult. an option was added, "-tool foo", so that
#  a command line option exists for selecting the tool.
#

# make sure there is an isip environment - must be done at the top
#
if (test -z "$ISIP") then
    . $HOME/.bashrc;
fi

# important definitions
#
PROGRAM_NAME="isip_xterm";

ISIP_HELP_FILE="$ISIP_DEVEL/util/misc/isip_xterm/isip_xterm.help";
export ISIP_HELP_FILE;

DEFAULT_TOOL="xterm"
OPTION_TOOL_NAME="-tool";

TOOL_0="xterm";
TOOL_0_NAME="xterm";
TOOL_0_OPTIONS="-ut -n";

TOOL_1="kterm";
TOOL_1_NAME="kterm";
TOOL_1_OPTIONS="-km euc -ut -n";

TOOL_2="cterm";
TOOL_2_NAME="cterm";
TOOL_2_OPTIONS="";

TOOL_3="xterm";
TOOL_3_NAME="xterm_2";
TOOL_3_OPTIONS="";

TOOL_4="xterm";
TOOL_4_NAME="xterm_4";
TOOL_4_OPTIONS="";

# execute a generic help function:
#  force the shellscript to exit if a help option is encountered.
set -e;
isip_function_help_0 $*;
set +e;

# check for a command line option:
#  if found, save the value and shift it off
#
if (test "$1" = "$OPTION_TOOL_NAME") then
    shift;
    TERM=$1; export TERM;
    shift;
else
    TERM="$DEFAULT_TOOL";
fi

# make sure x is running
#
if (test ! "$DISPLAY") then
    echo "error($PROGRAM_NAME): $TERM must be run under X windows";
    exit $ISIP_ERROR;
fi

# establish a tool
#
if (test ! "$TERM") then
    TOOL_NAME="$DEFAULT_TOOL";
else
    TOOL_NAME="$TERM";
fi

# create a new window name
#
WINDOW_NAME=`isip_function_window_name_0 "$TOOL_NAME"`;

# invoke one of a set of user-defined tools
#
if (test "$TOOL_NAME" = "$TOOL_0") then
    exec $TOOL_0 $TOOL_0_OPTIONS "$WINDOW_NAME" $* &
elif (test "$TOOL_NAME" = "$TOOL_1") then
    exec $TOOL_1 $TOOL_1_OPTIONS "$WINDOW_NAME" $* &
elif (test "$TOOL_NAME" = "$TOOL_2") then
    exec $TOOL_2 $TOOL_2_OPTIONS "$WINDOW_NAME" $* &
elif (test "$TOOL_NAME" = "$TOOL_3") then
    exec $TOOL_3 $TOOL_3_OPTIONS "$WINDOW_NAME" $* &
elif (test "$TOOL_NAME" = "$TOOL_4") then
    exec $TOOL_4 $TOOL_4_OPTIONS "$WINDOW_NAME" $* &
else
    echo "error($PROGRAM_NAME): $TOOL_NAME is an unknown tool";
    exit $ISIP_ERROR;
fi

#
# end of file
