#!/bin/sh
# roff by Brian E. Litzinger
# $Header: roff,v 1.7 90/01/17 00:19:18 brian Exp $
# Contributing Authors:
#     Jeff Goldstein, Svante Lindahl, Barry Schwartz
#
# Usage:  roff [ -p prefix ] [ options ] file-name ...
# The troff-prefix is the first part of the troff command name, the
# second part being "roff".  For example, type
#	roff -f ps file
# to run the file through psroff and the appropriate filters and macros.

TROFF=eroff
PREFIX=e
TMP=/tmp/roff$$
if [ $# -lt 1 ] ; then
    echo "Usage:  `basename $0` [ -p prefix ] [options] files"
    exit 2
fi
while [ -n "$1" ] ; do
    case "$1" in
	-p)
	    shift
	    PREFIX=$1
	;;
	-*)
	    args="$args $1"
	;;
	*)
	    command_line="`sed -e 1q $1`"
	    b="`echo $command_line | cut -f2 -d' '`"
	    if [ "$b" != "exec" ] ; then
		echo "$1 not roff format file!"
		exit 2
	    fi
	    command="`echo $command_line | cut -f3- -d' '"
	    d="sed -e 1d $1 |"
	    for i in $command ; do
		if [ "$i" = '$F' ] ; then
		    true
		else
		    if [ "$i" = "$TROFF" ] ; then
			d="$d ${PREFIX}roff $args"
		    else
			d="$d $i"
		    fi
		fi
	    done
	    #echo $d
	    eval $d
	;;
    esac
    shift
done
