#!/bin/sh 

# iAnywhere Solutions, Inc. One Sybase Drive, Dublin, CA 94568, USA
# Copyright (c) 2001-2008, iAnywhere Solutions, Inc. Portions copyright (c)
# 1988-2008, Sybase, Inc. All rights preserved. All unpublished rights reserved.

svc_t_init()
############
{
    NOOP=NOOP
}

svc_t_toolname()
################
{
    echo "mlsrv"`get_major_version`
}

svc_t_toolspath()
#################
# can look at $BITNESS, $BIN32, etc. here to override bitness
# 's' path is the script or shortcut path for this tool
{
    echo $SQLANYDIR/${BIN}s/`svc_t_toolname`
}

svc_t_toolpath()
################
# can look at $BITNESS, $BIN32, etc. here to override bitness
{
    echo $SQLANYDIR/$BIN/`svc_t_toolname`
}

svc_t_has_servername()
######################
{
    true
}

svc_t_need_servername()
#######################
{
    false
}

svc_t_get_servername_from_cmdline()
###################################
{
    while [ ! -z "$1" ]; do
	case $1 in
	    -zs )
		echo $2
		return
		;;
	esac
	shift
    done
}

svc_t_process_cmdline()
#######################
# in: cmdline
# out: add -zs <default> if -zs servername not already there
# out: (global) $SERVERNAME is set
{
    local MY_CMDLINE=`svc_t_process_cmdline_add_ud $*`

    # set server name to "<default>" if one is not specified
    # TODO: should be able to handle no -zs

    SAW_ZS=0
    while [ ! -z "$1" ]; do
	case $1 in
	    -zs )
		SAW_ZS=1
		SERVERNAME=$2
		;;
	esac
	shift
    done

    if [ $SAW_ZS -eq 0 ]; then
	# name the server (consistent with previous behaviour)
	SERVERNAME="<default>"
	MY_CMDLINE="$MY_CMDLINE -zs $SERVERNAME"
    fi

    # validation: unset SERVERNAME if it looks like another switch
    if [ -n "$SERVERNAME" ]; then
	TEST_SN=`echo $SERVERNAME | grep "^-"`
	[ -n "$TEST_SN" ] && SERVERNAME=""
    fi

    echo "$MY_CMDLINE"
}

svc_t_process_servername()
##########################
# in: cmdline
# out: servername
# Note: always called after process_commandline above, so there will always be a -zs
{
    local MY_CMDLINE=$*

    while [ ! -z "$1" ]; do
	case $1 in
	    -zs )
		SERVERNAME=$2
		;;
	esac
	shift
    done

    # validation: unset SERVERNAME if it looks like another switch
    if [ -n "$SERVERNAME" ]; then
	TEST_SN=`echo $SERVERNAME | grep "^-"`
	[ -n "$TEST_SN" ] && SERVERNAME=""
    fi

    if svc_t_need_servername; then
	[ -z "$SERVERNAME" ] && output_fatal_error "${ERR_REQDASHZS}"
    fi

    echo "$SERVERNAME"
}

