#!/bin/sh

verbose=0
set_name=0

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
bindir=${exec_prefix}/bin

while test $# -gt 0; do

    case "$1" in

	-h|--help)
		echo "sdsdsp - attempt to reroute audio device to sds"
		echo " "
		echo "sdsdsp [options] player arguments"
		echo " "
		echo "options:"
		echo "-h, --help                show this help and exit"
		echo "-s, --server=HOST:PORT    contact sds server on host at port"
		echo "-v, --verbose             show parameters"
		exit 0
		;;

	-s)
		shift
		if test $# -gt 0; then
			SDSHOST=$1
			export SDSHOST
		else
			echo "no server specified"
			exit 1
		fi
		shift
		;;

	--server*)
		SDSHOST=`echo $1 | sed -e 's/^[^=]*=//g'`
		export SDSHOST
		shift
		;;

	-v|--verbose)
		verbose=1
		shift
		;;

	*)
		break
		;;
    esac
done

if test "$verbose" = 1; then
	echo "server:		$SDSHOST"
	echo "command line:	$@"
fi

LD_PRELOAD=$libdir/libsdsdsp.so.0:$LD_PRELOAD
export LD_PRELOAD

exec "$@"
