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

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

I managed to send out the wrong version of the lex file, epf.l in
my last posting.  This one should work better.  Sorry about that...

This is a shell archive; the following should be invoked with "sh" not
"csh".
------------------------------ C U T   H E R E -------------------------
echo Creating file epf.l:
sed -e 's/^X//' > epf.l <<'END-OF-FILE_(epf.l)'
X%Start ITALIC BOLD CITALIC CBOLD
X%%
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>" "			ECHO;
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 * 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 BOLD 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)
-- 

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