:   bm# 0000001114
:   typ S
:   ver generic
:   mod generic
:  
#     SCCSID(@(#)mm.sh	1.1);


:
#
#	@(#) mm.sh 1.1 84/10/08 
#
#	Copyright (C) Microsoft Corporation, 1983
#
#	This Module contains Proprietary Information of Microsoft
#	Corporation and AT&T, and should be treated as Confidential.
#
###	mm - print documents formatted with the MM macros 
#
#	mm [ options ] [ files ]
#
#	MODIFICATION HISTORY
#	M000	28 Sep 83	barrys
#	Upgrade to 3.0
#	Removed any references to the term variable TERM
#	Commented out any references to any terminals that require
#	terminal filters.
#
#	MMSID (@(#)mm.sh	1.16)

if test $# = 0
then
	echo "Usage: mm [options] files" 
	exit 1
fi

trap 'trap 0; if test "$m" = 0; then mesg -y; fi; exit $z' 0
trap 'trap 0; if test "$m" = 0; then mesg -y; fi; exit 1' 1 2 3 15
if test -t;	then mesg >/dev/null;	m=$?;	mesg -n; else m=1; fi
PATH=/bin:/usr/bin:/usr/lbin

# M000 - all references to TERM changed to term
### TERM=${TERM-450};
term=450

t=0;  v=0;  y=0;  g="";  h="-h";  w="";	u="-cm"
while test -n "$1" -a ! -r "$1"
do case $1 in
	-T*)	term=`echo $1 | sed "s/-T//"` ;;
	-12)		y=1 ;;
	-e)		e=neqn ;;
	-t)		f=tbl ;;
	-c)		c=c ;;
	-E)		a="$a -e" ;;
	-y)		u=-mm ;;
	-)		break ;;
	*)		a="$a $1" ;;
   esac
   shift
done
if test -z "$1";	then echo "mm: no input file";		z=1;	exit;	fi

case "$term" in
	300|300s|450|37|300-12|300s-12|450-12|4000A|382|X)	;;
###	4014|tek)	g="|4014" ;;
	1620)	term=450 ;;
	1620-12)	term=450-12 ;;
###	hp|2621|2640|2645)	v=1;	c=c;	a="-u1 $a";	g="|hp";	term=hp ;;
	735|745|43|40/4|40/2)	v=1;	c=c ;;
	2631|2631-c|2631-e)	v=3;	c=c ;;
	*)	term=lp;	v=1;	c=c ;;
esac
if test \( "$y" = 1 \) -a \( "$term" = 300 -o "$term" = 300s -o "$term" = 450 \)
	then term="$term"-12
fi
if test "$c" = c
then
	case "$term" in
###		300|300s|450|4014|tek)	g="|col -f|greek -T$term" ;;
###		300-12|300s-12|450-12)	g="|col -f|greek -T$term";	w="-rW72" ;;
		37|4000A|382|X)	g="|col -f" ;;
###		hp)	g="|col|hp" ;;
		2631-c|2631-e)	g="|col -p" ;;
		735|745)	g="|col -x" ;;
		43)	g="|col -x";	w="-rW75" ;;
		40/4|40/2)	g="|col -b" ;;
		lp|2631)	g="|col" ;;
	esac
	h=""
	if test "$v" = 0;	then v=2;	fi
fi
d="$*"
if test "$d" = "-";	then shift;		d="";	fi
if test -n "$f"
	then	if test "$v" = 1 -o "$v" = 3
			then f="tbl -TX $*|"
			else f="tbl $*|"
		fi
		d=""
fi
if test -n "$e"
	then	if test -n "$f"
			then e="neqn|"
			else e="neqn $*|";	d=""
		fi
fi
if test "$term" = 4014 -o "$term" = hp;		then v=2;	fi
case "$v" in
	1)	term=lp ;;
	2)	term=37 ;;
esac
eval "$f $e nroff $u $w -T$term $h $a $d $g";	z=0;	exit
