#! @SH@

# file: $ISIP_IFC/util/misc/shell_functions/isip_function_window_name_0.sh
# version: $Id: isip_function_window_name_0.sh 9611 2004-07-03 18:06:03Z picone $
#
# A function that updates the window index and generates a new name.
# This function returns the window name via stdout. It is usually
# executed as follows:
#
#     NEW_WINDOW_NAME=`isip_function_window_name_0.sh $TOOL_NAME`;
#
# The output is a string that looks like this:
#
#     xterm(7) on borg
#
# The first argument is the name of the tool. This is used as prefix
# in the window name.
#
# It uses the following environment variables:
#
#     ISIP_INDEX_FILE
#     ISIP_TOOL_NAME
#     ISIP_HOST
#

# important definitions
#
TOOL_NAME=$1;

# create a new index
#
if (test -f "$ISIP_INDEX_FILE") then
    NEW_WINDOW_ID=`cat $ISIP_INDEX_FILE`;

#   make sure the expression is valid
#
    if (test -z "$NEW_WINDOW_ID") then
	NEW_WINDOW_ID="0";
    else
	NEW_WINDOW_ID=`expr $NEW_WINDOW_ID + 1`;
    fi

# if the file doesn't exist, create it
#
else
    NEW_WINDOW_ID="0";
fi

echo $NEW_WINDOW_ID > "$ISIP_INDEX_FILE";

# create a new window name
#
WINDOW_NAME="$TOOL_NAME""(""$NEW_WINDOW_ID"") on ""$ISIP_HOST";
echo "$WINDOW_NAME";

#
# end of file
