#!/bin/sh
# artsdsp - wrapper script to allow *some* binary only programs to use artsd
# based on the esddsp script

# keep this in sync with artsversion.h
#version="@RTS_VERSION@"

# default values for script variables
verbose=0
set_name=0
single_thread=0
ignore=0

# check for artsdsp options
while test $# -gt 0; do

    case "$1" in

	-h|--help)
	    echo "rts - attempt to allow rt prio rise"
	    echo " "
	    echo "rts [options] application arguments"
	    echo " "
	    echo "options:"
	    echo "-h, --help                show brief help"
#        echo "-s, --single-threaded     use the single-threaded version"
	    echo "-v, --verbose             show parameters"
#	    echo "-V, --version             show version"
	    exit 0
	    ;;


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

	-i|--ignore)
	    ignore=1
	    shift
	    ;;


#    -s|--single-threaded)
#        single_thread=1
#        shift
#        ;;

	*)
	    # no more rts options, get on with life
	    break
	    ;;
    esac
done

# echo options if verbose specified
if test "$verbose" = 1; then
    RTS_VERBOSE=1
    export RTS_VERBOSE
#    echo "rts:       $version"
#    echo "name:          $RTS_NAME"
    echo "command line:  $@"
    if test "$ignore" = 1; then
        echo "mode: ignore calls"
    else
        echo "mode: request monitor"
    fi
fi

if test "$ignore" = 1; then
    RTS_IGNORE=1
    export RTS_IGNORE
fi


# setup rts preload to hijack calls made to /dev/dsp
#prefix=@prefix@
#exec_prefix=@exec_prefix@
#libdir=@libdir@

LD_PRELOAD=librts.so.0

if test -f /lib/libdl.so.2; then
  LD_PRELOAD=$LD_PRELOAD:/lib/libdl.so.2
fi
export LD_PRELOAD

# invoke the program with the args given
exec "$@"
