File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / usr.bin / bsc / cmd / 3270 / emprtr.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:26:11 2019 UTC (7 years ago) by root
Branches: bsd, MAIN
CVS tags: v121, HEAD
Power 6/32 Unix version 1.21

/*	D.L.Buck and Associates, Inc. - 8/27/84
 *
 *	COPYRIGHT NOTICE:
 *		Copyright c 8/27/84 - An unpublished work by
 *		D.L.Buck and Associates, Inc.
 *
 *	PROPRIETARY RIGHTS NOTICE:
 *		All rights reserved. This document and program contains
 *		proprietary information of D.L.Buck and Associates,Inc.
 *		of San Jose, California, U.S.A., embodying confidential
 *		information,  ideas, and expressions,  no part of which
 *		may be reproduced, or transmitted in any form or by any
 *		means,	electronic,  mechanical,  or otherwise, without
 *		the written permission of D.L.Buck and Associates, Inc.
 *
 * NAME
 *	emprtr
 *
 * SYNOPSIS
 *	emprtr()
 *
 * DESCRIPTION
 *	emprtr prints the contents of the received printer buffer.
 */

#include "empr.h"
#include <signal.h>

#define	EM	0x19
#define	NL	0x0a
#define	CR	0x0d
#define	SI	0x0f
#define	FF	0x0c
#define	YES	1
#define	NO	0

#ifndef lint
static char sccsid[] = "@(#)emprtr.c	1.9 ";
#endif
extern int wflag;	/* set if we wrote something to pipe; 0 if not */
extern int maxlen;	/* defined in emprbuf; line length from wcc */

extern int prtype;	/* printer type- 4,6,7,8,9 (3284,3286,3287,3288,3289) */
extern int buffered;	/* 0=unbuffered printer; 1=buffered printer */
extern int tprint;	/* text print option for 3288; if 1, suppress index
			   works */
extern int ctype;	/* controller type- 1,5 (3271, 3275) */
extern int linesperpage;	/* # of lines allowed per page */

extern FILE *outfd;	/* device, file, or pipe to write printer output to */
extern char outtype;


char *scrnptr;	/* points to character being processed now */
char *lptr;		/* pointer into line */
char line[256];		/* construct lines here */
emprtr()
{
	register int lctr = 0;	/* number of lines on page so far	*/
	register int dflag = 0;	/* set if line `dirty' - non-white stuff*/
	register char *scrnend = &scrn_image[MAXSCREENSIZE];

	scrnptr = scrn_image;
	lptr = line;
	cursaddr = 0;
	curfield = scrn_xref[cursaddr];

	while (scrnptr != scrnend)	{ /* build lines while not screen end */
	    switch(*scrnptr)		{
		/* CR Order (3287, 3289 Printers): ref. pf 2-23
		 *	Executed only by 3287 and 3289 printers, in
		 *	unformatted mode and in displayable/printable field.
		 *	Otherwise print as space.
		 */
		case CR:	/* Carriage Return			*/
			if ((prtype == 7 || prtype == 9) &&
			    (maxlen == 132) && !invis_attr(fldattr[curfield])) {
				*lptr++ = '\r';
				*lptr = '\0';
				if (dflag)
					fputs (line,outfd);
				lptr = line;
				break;
			}
			/* Print as space				*/
			*lptr++ = ' ';
			break;

		/* EM Order (All Printers): ref. pg 2-22.
		 *	Executed only in unformatted (132 col mode) printout and
		 *	when not in nondisplay/nonprint field.
		 *	In nondisplay/nonprint field, it prints as blank.
		 *	In formatted output, it "is printed by the 3284, 3286,
		 *	3287, and 3288 printers as the graphic `9,' and by the
		 *	3230, 3262, 3268, 3287, and 3289 printers as a space
		 *	character." (sic)
		 *	So, who knows what the 3287 really does ...
		 *	we print a `9'.
		 */
		case EM:	/* end of media */
			if (maxlen == 132 &&
			    !invis_attr(fldattr[curfield])) 	{
				if (lptr != line)	{
					*lptr++ = '\n';
					*lptr = '\0';
					fputs(line, outfd);
					++lctr;
				}
				goto way_out;
			}

			if (invis_attr(fldattr[curfield]) ||
			    (prtype == 9 && maxlen < 132))
				*lptr++ = ' ';
			else if (prtype != 9)	{
				*lptr++ = '9';
				++dflag;
			}
			break;

		/* FF Order (3287, 3288, 3289 Printers): ref. pg 2-22
		 *	Executed by the above printers during either
		 *	formatted or unformatted operations, when at
		 *	beginning of line.  At other than beginning of
		 *	line, it prints as "<" or blank on the 3288 printer
		 *	depending on whether the field is printable or not.
		 *	If the printer is at top-of-form on a 3287 or 3289
		 *	the skip is not performed.
		 */
		case FF:	/* form feed */
			if (prtype < 7 || prtype > 9 || lptr != line) {
				if (invis_attr(fldattr[curfield]))
					*lptr++ = ' ';
				else	{
					*lptr++ = '<';
					dflag = 1;
				}
				break;
			}

			/* At beginning of line				*/
			if ((prtype == 7 || prtype == 9) &&
			    (lctr == 0))
				break;	/* Don't skip again		*/
			fputs("\f\r",outfd);
			*lptr++ = ' ';
			lctr = 0;
			break;

		/* NL Order (All Printers): ref. pg 2-22
		 *	Executed only in unformatted print (132 col) mode,
		 *	in displayable/printable field.
		 *	When not executed, `it is printed by the 3284, 3286,
		 *	3287, and 3288 printers as the graphic "5", and by
		 *	the 3230, 3262, 3268, 3287, and 3289 printers as a
		 *	space character.' (sic)
		 *	So, who knows what the 3287 really does ...
		 *	we print a `5'.
		 */
	
		case NL:
			if (invis_attr(fldattr[curfield]) || maxlen != 132) {
				if (invis_attr(fldattr[curfield]) ||
				    prtype == 9)
					*lptr++ = ' ';
				else	{
					*lptr++ = '5';
					++dflag;
				}
				break;
			}

			*lptr++ = '\n';
			*lptr = '\0';
			fputs(line, outfd);
			++lctr;
			dflag = 0;
			lptr = line;
			*lptr = '\0';
			break;

	/* SI -- suppress index; works like a carriage return, but only on
	   3288 printers which have the text print option */
		case SI:
			if (prtype != 8 || tprint == NO) break;
			*lptr++ = '\r';
			*lptr = '\0';
			fputs(line, outfd);
			lptr = line;
			break;

		case ' ':
		case '\0':
		case (char)ATTRCODE:
			*lptr++ = ' ';
			break;

		default:
			if (invis_attr(fldattr[curfield]))
				*lptr++ = ' ';
			else 	{
				*lptr++ = *scrnptr;
				++dflag;
			}
			break;
		};	/* End of SWITCH				*/

		/* Check for end of line.				*/
		if ((lptr - line) >= maxlen)	{
			if (dflag)	{	/* Line is `dirty'	*/
				*lptr++ = '\n'; *lptr = '\0';
				fputs(line, outfd);
				++lctr;
			}
			dflag = 0;
			lptr = line;
			*lptr = '\0';
		}

chk_eop:	/* Check for end of page.				*/
		if (lctr >= linesperpage)	{
			fputs("\f\r",outfd);
			lctr = 0;
		}

		++scrnptr;
		if (++cursaddr >= MAXSCREENSIZE)
			cursaddr = 0;
		curfield = scrn_xref[cursaddr];
	}

	/* End of Screen Buffer ... Finish up				*/
	if (dflag) {	/* Finish with last line			*/
		*lptr++ = '\n';
		*lptr = '\0';
		fputs(line,outfd);
		if (++lctr >= linesperpage)	{
			fputs("\f\r",outfd);
			lctr = 0;
		}
	}
way_out:
	/* If writing to pipe, mark that we wrote to it			*/
	if (outtype == 'P')
		++wflag;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.