[net.sources] Epson-nroff filter for Unix PC

bamford@ihuxo.UUCP (Bamford) (02/25/86)

To my unending surprise, there have been several requests for the
following filter.   This is intended to take the output of nroff and
convert to epson style escape sequences.  For completeness, in my
environment, I have also translated some locally-used escape sequences
to epson equivalents (These are the CITALIC, CBOLD states).

This archive contains the manual pages for epf (the lex program) and
lpr (the "replacement" for lp) as well as the source for epf and lpr.
Enjoy.

This is a shell archive; the following should be invoked with "sh" not
"csh".
------------------------------ C U T   H E R E -------------------------
echo Creating file 1.epf:
sed -e 's/^X//' > 1.epf <<'END-OF-FILE_(1.epf)'
X
X
X
X     EEEEPPPPFFFF((((1111))))                      UUUUNNNNIIIIXXXX 5555....0000                       EEEEPPPPFFFF((((1111))))
X
X
X
X     NNNNAAAAMMMMEEEE
X          epf - Epson Print Filter
X
X     SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
X          eeeeppppffff < input > output
X
X     DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
X          _E_p_f translates certain sequences representing emboldening
X          and italicizing (as produced by nroff(1) or cpr(1)) into
X          escape codes intended for an Epson printer or a ThinkJet
X          printer in alternate (epson emulation) mode.
X
X          The sequences that nroff(1) will put out by default are
X          multiple overstrikes of the same character for emboldening,
X          and a <_><bs><char> sequence for italicizing or
X          underlining.
X
X          Cpr(1) with the "-x" option will put out escape sequences
X          indicating Roman, Italic, or Bold.  These escapes are
X          translated into Epson equivalents.
X
X     EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
X          Local line printer output with bold but no underlining:
X
X               cpr *.h *.c | epf | lp
X
X          This manual page (in all of its glory):
X
X               nroff -man epf.1 | epf | lp
X
X          With bold and italics:
X
X               cpr -x *.h *.c | epf | lp
X
X     BBBBUUUUGGGGSSSS
X          Xerox style escapes and nroff(1) sequences may not be mixed
X
X     SSSSEEEEEEEE AAAALLLLSSSSOOOO
X          _c_p_r(1), _l_p_r(1),
X
X     AAAAUUUUTTTTHHHHOOOORRRR
X          Harold E. Bamford, AT&T Bell Labs
X
X     PPPPRRRROOOOVVVVIIIIDDDDEEEERRRR
X          Harold Bamford
X
X
X
X
X
X
X
X
X
X
X     Page 1                                        (printed 10/29/85)
X
X
X
END-OF-FILE_(1.epf)
echo Creating file 1.lpr:
sed -e 's/^X//' > 1.lpr <<'END-OF-FILE_(1.lpr)'
X
X
X
X     LLLLPPPPRRRR((((1111))))                      UUUUNNNNIIIIXXXX 5555....0000                       LLLLPPPPRRRR((((1111))))
X
X
X
X     NNNNAAAAMMMMEEEE
X          lpr - epson print spooler
X
X     SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
X          llllpppprrrr [ options ] [ files ]
X
X     DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
X          _L_p_r runs the epson print filter on its input and redirects
X          the output to the print spooler, lp(1).
X
X          All options that apply to lp(1) also apply to lpr(1).
X          Lpr(1) is intended as a back end (sink) to cpr(1) or
X          nroff(1).  Anything that does not contain escape sequences
X          or nroff(1) sequences will be unchanged and treated as
X          though lp(1) were called directly.  In addition to the
X          standard llllpppp((((1111)))) options the following are also available:
X
X        OOOOppppttttiiiioooonnnnssss....
X          ----ffff _C_o_m_p_r_e_s_s_e_d
X                   Turn on the compressed output mode on the printer.
X                   The word "Compressed" may be abbreviated to 1 or
X                   more letters beginning with either a "C" or a "c".
X          ----ffff _E_x_p_a_n_d_e_d
X                   Turn on the expanded output mode on the printer.
X                   The word "Expanded" may be abbreviated to 1 or
X                   more letters beginning with either an "E" or an
X                   "e".
X
X          Cpr(1) with the "-x" option will put out escape sequences
X          indicating Roman, Italic, or Bold.  These escapes are
X          translated into Epson equivalents.
X
X     EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
X          Local line printer output with bold but no underlining:
X
X               cpr *.h *.c | lpr
X
X          This manual page (in all of its glory):
X
X               nroff -man lpr.1 | lpr
X
X          With bold and italics:
X
X               cpr -x *.h *.c | lpr
X
X          With bold and italics, in compressed mode:
X
X               cpr -x *.h *.c | lpr -f compress
X
X     BBBBUUUUGGGGSSSS
X          Xerox style escapes and nroff(1) sequences may not be mixed
X
X
X
X
X     Page 1                                        (printed 11/13/85)
X
X
X
X
X
X
X     LLLLPPPPRRRR((((1111))))                      UUUUNNNNIIIIXXXX 5555....0000                      LLLLPPPPRRRR((((1111))))
X
X
X
X     SSSSEEEEEEEE AAAALLLLSSSSOOOO
X          _c_p_r(1),
X
X     AAAAUUUUTTTTHHHHOOOORRRR
X          Harold E. Bamford, AT&T Bell Labs
X
X     PPPPRRRROOOOVVVVIIIIDDDDEEEERRRR
X          Harold Bamford
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X     Page 2                                        (printed 11/13/85)
X
X
X
END-OF-FILE_(1.lpr)
echo Creating file epf.l:
sed -e 's/^X//' > epf.l <<'END-OF-FILE_(epf.l)'
X%Start ITALIC BOLD CITALIC CBOLD
X%%
X" "				ECHO;
X<CITALIC>\033R			{ printf("\033-0"); BEGIN 0; }
X<CBOLD>\033R			{ printf("\033F");  BEGIN 0; }
X<CITALIC>\033B			{ printf("\033-0\033E"); BEGIN CBOLD; }
X<CBOLD>\033I			{ printf("\033F\033-1"); BEGIN CITALIC; }
X\033B				{ printf("\033E");  BEGIN CBOLD; }
X\033I				{ printf("\033-1"); BEGIN CITALIC; }
X\033R				{ printf("\033F\033-0"); BEGIN 0; }
X<ITALIC>_\010.			{ printf("%c",yytext[2]); }
X<ITALIC>_			{ printf(" "); }
X<ITALIC>[^_\010](\010[^_\10])+/[^\10]	{
X				printf("\033-0\033E%c",*yytext);
X				BEGIN BOLD;
X				}
X<ITALIC>.			{ printf("\033-0%c",*yytext); BEGIN 0; }
X<BOLD>_\010.			{
X				printf("\033F\033-1%c",yytext[2]);
X				BEGIN ITALIC;
X				}
X<BOLD>[^_\010](\010[^_\10])+/[^\10]	{ printf("%c",*yytext); }
X<BOLD>.				{ printf("\033F%c",*yytext); BEGIN 0; }
X_\010.				{
X				printf("\033-1%c",yytext[2]);
X				BEGIN ITALIC;
X				}
X[^_\010](\010[^_\10])+/[^\10]	{
X				printf("\033E%c",*yytext);
X				BEGIN BOLD;
X				}
X.				ECHO;
X\n				ECHO;
X%%
X
X/**********************************************************************
X * epf -- Epson Print Filter.  This filter takes standard input and looks
X * for pattern used to simulate BOLD and ITALIC (UNDERLINE) on dumb
X * printers.  These patterns are converted to escape sequences that can
X * be used by Epson printers.
X *
X * There are 3 states in this lexical analyzer:
X * 0      -- normal input
X * ITALIC -- currently putting out chars with underlining.
X * BOLD   -- currently putting out chars in boldface.
X *
X * ITALIC is performed on dumb printers with the sequence:
X *	<underscore char><bs><character>
X *      where <bs> is a backspace character
X *
X * BOLD on dumb printers with at least 1 overstrike:
X *	<char><bs><char>...<bs><char>
X *	where the pattern <bs><char> must occur at least once.
X *
X * For efficiency considerations, an underscore encountered while in
X * ITALIC mode is translated to a space.  If true italics are available
X * the underscore would look funny.  If only underlining is available,
X * then the printer's internal underlining (which may be better looking
X * than an underscore) will be used.
X *
X * Similarly, a blank encountered while in any state is just output
X * without any state change.
X *
X * The output of the nroff processor with the -T37 option is typical
X * of what epf(1) is expecting.
X *
X * In addition, epf(1) will react to escape sequences as output by
X * cpr(1) when using the -x option.  These sequences are:
X *
X *	<ESC>R	- go to Roman typeface
X *	<ESC>I	- go to Italic typeface
X *	<ESC>B	- go to Bold typeface
X *
X * The output of epf are escape sequences used by the epson printers
X * or a ThinkJet run in alternate (epson emulation) mode.  The
X * output sequences are:
X *
X *	<ESC>-0	- Turn off italic mode
X *	<ESC>-1	- Turn on italic mode
X *	<ESC>F	- Turn off bold mode
X *	<ESC>E	- Turn on bold mode
X *
X * As a general rule, BOLD and ITALIC may not exist at the same time.
X *
X * To compile this beast:
X *	lex epf.l
X *	cc -O -o epf lex.yy.c -ll
X *********************************************************************/
END-OF-FILE_(epf.l)
echo Creating file lpr:
sed -e 's/^X//' > lpr <<'END-OF-FILE_(lpr)'
X######################################################################
X# lpr - takes a file(s) and passes it through epf to translate
X# nroff(1) emboldening and italicizing sequences to escape sequences
X# for the epson printer.  Output of epf is then passed to lp(1).
X#
X# epf(1) also handles xerox escape sequences as produced by cpr -x
X#
X# options to lpr are the same as to lp.  In addition, the printing
X# width can be controlled with the "-f {Compressed|Expanded}" option
X#
X######################################################################
Xexport ARGLIST FILES PRECOND POSTCOND
XARGLIST=
XFILES=
XPRECOND=
XPOSTCOND=
Xset -- `getopt f:cd:mn:o:st:wa: $*`
Xfor i in $*
Xdo
X	case $i in
X	-c|-m|-s|-w)	ARGLIST="${ARGLIST} ${i}"; shift;;
X	-d|-n|-o|-t)	ARGLIST="${ARGLIST} $1 $2"; shift 2;;
X	-a)		ARGLIST="${ARGLIST} -aname"; shift 2;;
X	-f)		case $2 in
X			e*|E*)	# Expanded print
X				PRECOND="${PRECOND}";
X				POSTCOND="${POSTCOND}";
X				shift 2;;
X			c*|C*)	# Compressed print
X				PRECOND="${PRECOND}";
X				POSTCOND="${POSTCOND}";
X				shift 2;;
X			*)	echo "$0: unknown font type: only Compress or Expand allowed";
X				exit 2;;
X			esac;;
X	--)	shift; break;;
X	esac
Xdone
X
Xif [ "${PRECOND}" ]
Xthen
X	(echo "${PRECOND}\c"; cat $* | col -x; echo "${POSTCOND}\c") | epf | lp ${ARGLIST}
Xelse
X	cat $* | col -x | epf | lp ${ARGLIST}
Xfi
END-OF-FILE_(lpr)
-- 

				Harold Bamford
				AT&T Bell Labs
				(cornet) 8-367-1866
				Naperville, Ill
				(312) 979-1866