#!/bin/sh
#
# wrapper for fconvert -- sets path, etc.

FILTER_DIR=/share/spool/filters

PATH=$FILTER_DIR:/usr/local/bin:/usr/openwin/bin:/home/scripts:$PATH
MPDEFAULTS=
export PATH LD_LIBRARY_PATH XAPPLRESDIR XFILESEARCHPATH MPDEFAULTS

JOBNAME=
USERNAME=
HOSTNAME=
ACCTFILE=/dev/null
export JOBNAME HOSTNAME ACCTFILE USERNAME

# put any errors into the "errors" file; fd 3 is used for the actual
# data that we've converted.
#
exec 3>&1 > errors 2>&1

if [ $# = 0 ] ; then
    echo "usage: convert-to format [filter args ...]" 1>&2
    exit 1
fi

FORMAT=$1; shift

while [ $# -gt 0 ] ; do
  case "$1" in
    -J ) JOBNAME="$2"; shift; ;;
    -J* ) JOBNAME=`echo $1 | sed 's/^-.//'` ;;

    -n ) USERNAME="$2"; shift; ;;
    -n* ) USERNAME=`echo $1 | sed 's/^-.//'` ;;

    -h ) HOSTNAME="$2"; shift; ;;
    -h* ) HOSTNAME=`echo $1 | sed 's/^-.//'` ;;

    -*) ;;
    *)  ACCTFILE=$1 ;;
  esac
  shift
done

exec fconvert -O $FORMAT -c $FILTER_DIR/fconvert.config 1>&3
