#==============================================
#!/bin/sh
## We assume that we specify the probability and the primer program
## as values of SPECFLAGS in the torx-config(4) configuration file,
## as in:
##
## SPECFLAGS 0.3 /my/path/to/my/real/primer
##
## which means they will be the last values in the argument list
## given to this script.
## We store those two values in variables PROB resp. PRIMER,
## and then strip them from the list of arguments with which
## we invoke the primer.
## NOTE there should be (hopefully is) a better way to do the
## command line argument dance below.
# use: number of arguments we consume here
use=2
if [ $# -lt $use ]
then
echo "usage: script [ primer-args... ] prob primer" 1>&2
exit 1
fi
## construct command (cmd) to re-set the positional parameters
## to the list of n that we want to pass to the primer, like:
## set "$1" "$2" ... "$n"
## and set PROB and PRIMER
cmd=set
n=`expr $# - $use`
i=1
while [ $i -le $n ]
do
cmd="$cmd \"\$$i\""
i=`expr $i + 1`
done
eval PROB=\$$i
i=`expr $i + 1`
eval PRIMER=\$$i
i=`expr $i + 1`
## only eval the command to re-set the positional parameters
## if there are positional parameters to be set
## otherwise, unset the positional parameters using shift
## (old bourne shells do not allow an argument to shift)
if [ $# -gt $use ]
then
eval $cmd
else
i=1
while [ $i -le $use ]
do
shift
i=`expr $i + 1`
done
fi
## ready to start the real work
## xtorx will make sure that iochooser is in its PATH
if [ -n "$PROB" ]
then
bounds_values="${PROB}:iokind=input:1.0:iokind=output"
iochooser -s 0 $bounds_values | $PRIMER "$@"
else
$PRIMER "$@"
fi
#==============================================