#!/bin/sh
#
# run-mp -- wrapper for the "mp" text-to-postscript translator
#    for use as an LPD "if" filter.
#
# mp is available as part of Solaris' OpenWindows distribution,
# and can also be ftp'ed from ftp.adelaide.edu.au [Australia]
# in the pub/sun/richb directory. Go for the latter -- it also
# includes a nifty GUI front-end!
#
# (update: mp has been taken off ftp.adelaide.edu.au, for some
# reason. However, you can pick up mp 3.1.8 by anonymous ftp
# from ftp.iona.ie:/pub/mp. If anyone knows richb's current
# email address, could they pass it on?).
#
# jmason@iona.ie '94.

# echo "[$*]" > /share/tmp/mp-debug 2>&1

# make sure this PATH will find "mp".
#
PATH=/usr/local/bin:/usr/openwin/bin:/bin

MPDEFAULTS=
# mp needs XAPPLRESDIR, XFILESEARCHPATH in env, even if
# they're unset, otherwise it dumps core.
export PATH LD_LIBRARY_PATH XAPPLRESDIR XFILESEARCHPATH MPDEFAULTS

jobname='(stdin)'		# some default values
user='someone'

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

# this bit is for accounting info.
#
IDENT="`date '+%H:%M %a %m/%d/%y'`: $user"
if [ -f /vmunix ] ; then
	echo -n "$IDENT: $jobname: " 1>&2
else
	echo "$IDENT: $jobname: \c" 1>&2
fi

# run mp with the appropriate settings.
# these arguments are in the later mp-3.1 format, so will not
# work with Solaris' bundled version.
#
exec mp -a4 -subject "$jobname" -alias "$user"
