#!/usr/bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# cmdtext720 src/cmdtext/usr/bin/mm/mm.sh 1.18 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1989,1994 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#   @(#)66	1.18  src/cmdtext/usr/bin/mm/mm.sh, cmdtext, cmdtext720 8/25/08 07:13:53 
# COMPONENT_NAME: (CMDTEXT) Text Formatting Services
#
# FUNCTIONS:
#
# ORIGINS: 54,27,28
#
# (C) COPYRIGHT International Business Machines Corp. 1989,1994
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#	Copyright (c) 1984 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#		Copyright (c) 1984 AT&T
#		  All Rights Reserved
#     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#   The copyright notice above does not evidence any actual
#   or intended publication of such source code.
#
#	VARIABLE  DEFINITIONS

#	v   -	If "v" is set > 1, a call is made to tbl -TX
#		which compensates for fractional line motions in
#		printers that don't support such.
#	c  -    Invokes a call to col to format possible multiple
#		columns, fractional and reverse linefeeds for printers
#		that can't backspace lines and or characters.
#	a  -    Sets overstrike option for Nroff.
#	g  -	Invokes a call to interpreter which handles special
#		functions for specific hardware devices(e.g.,4014).
#	y  -	Set to 12 pitch for certain printers.
#	h  -  	Nroff option, replaces 8 spaces with a tab.
#	w  -	Sets page width if $TERM is 43.
#	u  -	Sets Nroff option -mm.
#	e  -    Nroff call to neqn.
#	f  -	Invokes a call to tbl.
#	d  -    Input file name. Final command line argument, if it is a file.
#	t  -	Set to 0, not ever used.


PATH=/usr/bin:/usr/sbin
export PATH
if test $# = 0;
then
dspmsg mm.cat 1 "Usage: %s [options] files where options are:\n\
 12	=> 12-pitch (effective only with DASI terminals)\n\
 -e	=> neqn\n\
 -t	=> tbl\n\
 -c	=> col\n\
 -E	=> -e option of NROFF (not effective with -c)\n\
 -Tterm	=> where term is the desired terminal type, e.g., -Thp.  (Cat\n\
	   /usr/pub/terminals for a list of available terminal types.)\n\
	   If no -T option is given then \$TERM is used if it has a value\n\
	   otherwise the default is lp.\n\
 -	=> instead of 'files' inside a pipeline.\n\
Other options as required by NROFF and/or MM.\n" $0

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 1;	then mesg >/dev/null;	m=$?;	mesg -n; else m=1; fi
PATH=$PATH:/bin:/usr/bin
TERM=${TERM-450};  t=0;  v=0;  y=0;  g="";  h="-h";  w="";  u="-mm"
a= c= e= f=
while test -n "$1" -a ! -f "$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 dspmsg mm.cat 2 "%s: no input file\n" $0 >&2;	z=1;	exit;	fi
case "$TERM" in
	300|300s|450|37|300-12|300s-12|450-12|4000a|382)	;;
	X)		v=4;;
	hplj|ibm4019)	v=0;TERM="hplj";;
	4014)		g="|4014" ;;
	1620)		TERM=450 ;;
	1620-12)	TERM=450-12 ;;
	ppds)		v=0;	c=c;;
	ibm3816|ibm3812)	v=0;;
	ibm5575|ibm5577)	v=0;;
	2631|2631-c|2631-e)	v=3;	c=c ;;
	8510)	v=0;	c=c;	TERM=8510 ;;
	*)	TERM=lp;	v=2;	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)	g="|col -f|greek -T$TERM" ;;
		300-12|450-12)	g="|col -f|greek -T$TERM";	w="-rW72" ;;
		300s-12)	g="|col|greek -T$TERM";	w="-rW72" ;;
		37|4000a|382)	g="|col -f" ;;
		X)		g="|col -f";;
		2631-c|2631-e)	g="|col -p" ;;
		43)		g="|col -x";	w="-rW75" ;;
		40/4|40/2)	g="|col -b" ;;
		8510)	g="|col -xp" ;;
		ppds) g="|col -f";;
		lp|2631)	g="|col" ;;
		hplj)	g="|col";;
		ibm3816|ibm3812)	g="|col -f" ;;
		ibm5577|ibm5575)	g="|col -f";;
	esac
	h=""
	if test "$v" = 0;	then v=1;	fi
fi
d="$*"
if test "$d" = "-";	then shift;		d="";	fi
if test -n "$f"
	then	if test "$v" -gt 1
			then f="tbl -TX $*|"
			else f="tbl $*|"
		fi
		d=""
fi
if test -n "$e"
	then	if test -n "$f"
			then e="neqn /usr/pub/eqnchar -|"
			else	if test -z "$*"
					then e="neqn /usr/pub/eqnchar -|"
					else e="neqn /usr/pub/eqnchar $*|"
				fi;
			d=""
		fi
fi
#Add TERM variable for col
if [ -n "$g" ]
then 
	g="$g -T$TERM"
fi
#echo "$f $e nroff $u $w -T$TERM $h $a $d $g";	z=0;	exit
eval "$f $e nroff $u $w -T$TERM $h $a $d $g";	z=0;	exit