################################################################################
# A set of utility routines for using VLAN device control 
#
#   $Date: 93/11/15 18:52:34 $
#   $Revision: 11.0 $
#
#   (/bin/sh syntax...)
################################################################################

################################################################################
# A helper routine for WaitForEdit( )
################################################################################
IsDone( )
{
    echo "$1\c"
    if [ "$1" = "DONE" -o "$1" = "ABORTED" ]
    then
	return 0
    else
	return 1
    fi
}

################################################################################
# Subroutine to wait for the deck to be ready by looking for an edit status of
# "DONE"
#
# args:	$1  Command to use to send VLAN commands
#	$2  Number of seconds to wait
#	$3  String to print while waiting...
#
# Returns:  0 if it gave up after $1 seconds.
#	    1 if it got the "DONE" string
################################################################################
WaitForEdit( )
{
    __send_wfe=$1
    __timeout_wfe=$2
    __string_wfe=$3
    
    __count_wfe=0
    
    while [ 0 ]
    do
	__status_wfe=`$__send_wfe ES`
	IsDone $__status_wfe
	
	if [ $? = "0" ]
	then
	    return 1
	else
	    __count_wfe=`expr $__count_wfe + 1`
	    if [ $__count_wfe -gt $__timeout_wfe ]
	    then
		return 0
	    else
		# Echo the message
		echo $__string_wfe
		
		# Wait and try again...
		sleep 1
	    fi
	fi
    done
}

