#!/bin/bash
#
# Description: Script used to run the program for a ProgramPresentationTask task.
#
# Change log:
#
# 10/06/2006 Kurt Schroeder  -01 Check X server access before running the task.
# 10/12/2006 Kurt Schroeder  -02 Set LANG environment variable based on the user's locale.

traceIt() {
   actzTrace "XFRMPGTF: $1"
}

tracePipe() {
   while read line;
   do
      traceIt "$line";
   done
}

addr="$1";
locale="$2";  #-02
xflag="$3";   #-02
cmd="$4";     #-02
traceIt "Number of parameters is: $#"
traceIt "Client address is: $addr"
traceIt "Client locale is: $locale"   #-02
traceIt "X windows flag is: $xflag"
traceIt "Command to execute is: $cmd"

export DISPLAY="${addr}:0"
traceIt "DISPLAY=$DISPLAY"

#-02 start
export LANG="${locale}"
traceIt "LANG=$LANG"
ls foo 2>&1 | tracePipe
#-02 end

xrc=0;
if [ "$xflag" == "yes" ]; then
   xset -q >/dev/null 2>&1;
   xrc="$?";
   if [ "$xrc" != 0 ]; then
      traceIt "xset command failed; returning with an error";
   else
      traceIt "xset worked; running the program";
   fi
fi

if [ "$xrc" == "0" ]; then
   shift 4   #-02
   traceIt "program arguments are: [$@]"
   $cmd "$@" 2>&1 | tracePipe
fi
exit $xrc
