#!/bin/sh

# biditext - a script to run a program with the biditext hack

if test "x$*" = 'x'; then
  echo "$0: Error - missing program name"
  echo "Usage: biditext [--auto-refresh] program_to_run [parameters]"
  exit 1
fi

AUTO_REFRESH=0

if test "$1" = "--auto-refresh"; then
  AUTO_REFRESH=1
  shift
fi

# Set biditext by default to enabled, and neutral direction:
r2l s enable
r2l b neutral

# If BIDITEXT_FILENAME had a previous value, it is not overriden
BIDITEXT_FILENAME=`r2l p token`
export BIDITEXT_FILENAME

if test "x${LD_PRELOAD}" != 'x'; then
  LD_PRELOAD="${LD_PRELOAD}:/usr/lib/biditext.so"
else 
  LD_PRELOAD="/usr/lib/biditext.so"
fi
if test "$AUTO_REFRESH" = "1" ; then
  LD_PRELOAD="$LD_PRELOAD /usr/lib/refreshd_hook.so"
fi
export LD_PRELOAD
exec "$@"
