#!/bin/sh

TABLE=
INFODIR=${XEMPDIR-${HOME}/xemp}/info.t

[ $# -eq 0 ] &&
{
	echo "usage: $0 [-m] [-t] [-<xv>] files"
	echo "where          -m  create the macro-files"
	echo "               -t  create a table of contents"
	echo "               -x  xtroff"
	echo "               -v  vi (no control / pages)"

	exit
}

[ x$1 = x-m ] &&
{
	shift
	cwd=`pwd`
	cd ${INFODIR}
	echo -n "more.xxx  +  all.mac -> more.mac    "
	cat more.xxx all.mac > more.mac
	echo "[Done]"
	echo -n "doc.xxx   +  all.mac -> doc.mac     "
	cat doc.xxx all.mac > doc.mac
	echo "[Done]"
	echo -n "troff.xxx +  all.mac -> troff.mac   "
	cat troff.xxx all.mac > troff.mac
	echo "[Done]"
	cd $cwd
	[ x$1 = x ] && exit
}


[ x$1 = x-t ] &&
{
	TABLE=" ${INFODIR}/index.T"
	shift
}

case x$1 in

	x-x)
		shift
		xtroff -command "tbl $* | troff -ms \
			${INFODIR}/troff.mac - ${TABLE}"
		;;
	
	x-d)
		shift
		echo "Please specify the printer command."
		echo "Example: tbl ${files} | troff -ms -Tp4p | dip -Tp4p"
		echo -n "tbl ${files} | troff -ms "
		read command
		eval 'tbl $* | troff -ms '"${INFODIR}/troff.mac"${command}
		exit
		;;

	x-v)
		shift

		#	A simple sed script to convert the control
		#	characters used by colcrt

		tbl $* | nroff -ms ${INFODIR}/doc.mac - ${TABLE} |
			sed -e "/8/s/_/-/g" \
			    -e "s/|8|/|/" \
			    -e "s/9 //" \
			    -e "s/_\(.\)/\1/g" \
			    -e "s/|7\(.*\)/77|7\1\\
/" \
			    -e "s/8//" | 
			colcrt - > /tmp/show.$$
		vi /tmp/show.$$
		;;
	
	x*)
		tbl $* | nroff -ms ${INFODIR}/more.mac - ${TABLE} |
					col -hp | more
		;;
esac
