colonel@sunybcs.UUCP (01/18/87)
That shell alias is a good one. Here's a shell script with more power and intelligence. Again you put the invocation on line 1 as a comment. ----------------------CUT HERE----------------------- # This is a shell archive. Remove anything before this line, then # unpack it by saving it in a file and typing "sh file". (Files # unpacked will be owned by you and have default permissions.) # # This archive contains: # off.1 off.sh echo x - off.1 sed -e 's/^X//' > "off.1" << '//E*O*F off.1//' X.ie t \{ X.ds Q `` X.ds U ''\} X.el \{ X.ds Q "" X.ds U ""\} X.de QU X\\$3\\*Q\\$1\\*U\\$2 X.. X.TH OFF 1 "December 21, 1986" X.SH NAME Xoff \- run ditroff or nroff with appropriate preprocessors X.SH SYNOPSIS X.B off X[ X.B \-m X] [ X.B \-n X] [ X.B \-P X] [ X.B \-p X] [ X.BI \-x nnn X] [ troff option ... ] [ file ... ] X.SH DESCRIPTION X.I Off Xreads the argument files, or the standard input if there are none. XIf the first line is an X.IR nroff/troff (1) Xcomment beginning with \e", .\e", or \'\e", X.I off Xtreats the remainder of the line as a shell command through which Xthe input is to be piped. XFor example, a file beginning with X.RS X.PP X\&.\e" tbl | eqn | ditroff -me X.RE X.PP Xwill be piped through X.IR tbl (1), X.IR eqn (1), Xand X.IR ditroff (1). X.PP X.I Off Xuses X.I ditroff Xas the default text processor. XNormally any word that ends in -troff or -nroff is converted to X.QU ditroff, Xand X.QU neqn Xis converted to X.QU eqn. XIf X.B \-n Xis specified, X.QU nroff Xis used instead, X.QU eqn Xis converted to X.QU neqn, Xand X.QU pic Xis suppressed unless X.B \-P Xis specified. XThe X.B \-p Xoption may be used to pipe the output through X.IR lpr (1); Xif X.I nroff Xis used, the output will first be piped through X.IR col (1) Xto remove half line feeds. XAn argument of the form X.BI \-T device, X.BI \-r aN, Xor X.BI \-o range Xis passed to X.I ditroff Xor X.I nroff; X.BI \-T device Xis also passed to X.I eqn X(but not X.IR neqn ), Xand to X.I pic Xunless X.B \-n Xis specified. XYou can use X.BI \-x nnn Xto specify multiple copies to X.I ditroff Xor X.I lpr. X.PP XThe X.B \-m Xoption causes X.I off Xto send you mail when done. X.SH DIAGNOSTICS X.QU "No invocation" Xif input does not start with a comment line, Xand complaints about unknown command options. X.SH "SEE ALSO" Xditroff(1), troff(1), bib(1), eqn(1), pic(1), refer(1), tbl(1) X.SH AUTHOR XCol. G. L. Sicherman (decvax!sunybcs!colonel) //E*O*F off.1// echo x - off.sh sed -e 's/^X//' > "off.sh" << '//E*O*F off.sh//' X: off - run off a document. X: the Colonel. 1986. X: The first input line is a comment containing the invocation. X: X: -n substitute nroff for ditroff or troff, and neqn for eqn X: no -n substitute ditroff for nroff or troff X: -p pipe to lpr X: -P use pic, even in nroff X: -xnn run nn copies /* only with -p or without -n */ X: -m send mail when done X: Arguments to nroff/ditroff: X: -om-n select pages X: -raN set number register X: -Tx specify -Tx to ditroff or nroff - X: also to pic and eqn, but not neqn X: X: Added -m. GLS, 18 Dec 1986. X: Fixed bug in use of head. GLS, 19 Dec 1986. XTMP=/usr/tmp/off$$ XTMPI=/usr/tmp/offi$$ XSEDSCRIPT=/usr/tmp/offss$$ XPOST1=/bin/cat XPOST2=/bin/cat Xtrap 'rm -f $TMP $TMPI $SEDSCRIPT; if test "$mflag"; then \ X echo off: job $$ failed | mail $USER; fi; exit 1' 1 2 Xtrap 'rm -f $TMP $TMPI $SEDSCRIPT; if test "$mflag"; then \ X echo off: job $$ completed | mail $USER; fi; exit 0' 0 XTROFFFLAGS= Xwhile test $# -gt 0 Xdo Xcase $1 in X-m) mflag=1;; X-n) nflag=1;; X-o*) TROFFFLAGS="$TROFFFLAGS $1";; X-p) POST2=lpr;; X-P) Pflag=1;; X-r*) TROFFFLAGS="$TROFFFLAGS $1";; X-T*) Tflag=$1; TROFFFLAGS="$TROFFFLAGS $1";; X-x*) xflag=$1;; X-*) echo $0: bad option $1 >&2; exit 1;; X*) break;; Xesac Xshift Xdone Xif test "$nflag" Xthen ROFF=nroff X EQN=neqn X if test "$Pflag" X then PIC="pic" X else PIC="cat" X fi X if test "$pflag" X then X POST1=col X POST2="$POST2 `echo $xflag | tr x #`" X fi Xelse X ROFF="ditroff $xflag" X EQN="eqn $TFLAG" X PIC="pic $TFLAG" Xfi Xcat $@ > $TMP Xif head -1 $TMP | grep '^['"'"'\.]*\\".*roff' > $TMPI Xthen Xcat <<ENDSED > $SEDSCRIPT Xs/[a-z]*[nt]roff/$ROFF $TROFFFLAGS/ Xs/n*eqn/$EQN/ Xs/pic/$PIC/ Xs/^['.]*\\\\"// XENDSED XINV=`sed -f $SEDSCRIPT $TMPI` Xsh -c "$INV" < $TMP | $POST1 | $POST2 Xelse Xecho $0: no invocation on $1 >&2 Xexit 1 Xfi Xexit 0 //E*O*F off.sh// exit 0 -- Col. G. L. Sicherman UU: ...{rocksvax|decvax}!sunybcs!colonel CS: colonel@buffalo-cs BI: colonel@sunybcs, csdsiche@ubvms