File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / usr / src / usr.bin / bsc / cmd / 3270 / em3280.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
 *	em3280 - IBM 3280 printer emulator
 *
 * SYNOPSIS
 *	em3280 [<hostname>]
 *
 * DESCRIPTION
 * 	em3280 is the controlling utility of the IBM 328x printer
 *	emulator.
 *
 * ALGORITHM
 *	I. Initialization
 *		A. Set signals
 *		B. Process control parameters
 *			1. hostname - specifies control unit interface to
 *			   emulate
 *		C. Get host and printer configuration parameters
 *		D. Call connect installation exit
 *
 *	II. Emulate printer while no interrupts received
 *		A. Open the comm device
 *		B. Set device parameters
 *		C. Process a file
 *		D. Close the comm device
 */

#include "local.h"
#include <bsc/bscio.h>
#include <empr.h>
#include <errno.h>
#ifdef BSD42
#include <sys/time.h>
#else
#include <time.h>
#endif

#ifdef DEBUG
#define libpath "./"
#define spoolpath "./"
#else
#define libpath "/usr/lib/bscbatch/"
#define spoolpath "/usr/spool/bscbatch/"
#endif

#define YES 1
#define NO 0

#ifndef lint
static char sccsid[] = "@(#)em3280.c	1.8 ";
#endif

char hostname[20] = "3280";	/* contains host name */
char audname[80];		/* temp audit file pathname goes here */
char new_audnm[80];		/* real audit pathname goes here */
char auditlock[80];		/* audit lockfile pathname goes here */

char *strcpy();			/* function copies one string to another */
char *strcat();			/* function appends one string to another */
char *getenv();			/* find string in environment */

int chk_hostid;
int chk_termid;
int primary = BSCPRIM;
int rviab; 
int pt_to_pt;
int ascii;		/* ascii or ebcdic data? */
int devfd;		/* bsc device file descriptor */
int wflag;		/* set if pipe's been written to; 0 otherwise */
extern int errno;
extern char *sys_errlist[];
long atol();		/* converts ascii to long */
char devname[20];
char outtype;		/* pipe printer output to a program if this is "P",
			   write to a file or device if this is "F" */
int prtype;		/* terminal type */
int tprint;		/* text print option flag (3288 only) */
int ctype;		/* controller type - 1 for 3271, 5 for 3275 */
int buffered;		/* buffered printer flag */
int vfc;		/* vertical forms unit flag */
int linesperpage;	/* number of lines allowed per page */
int stationid;		/* subdevice id, translated appropriately */
char termid;		/* cluster address (poll) */
char note[100];		/* msg to write to AUDIT file and mail */
char emsg[80];		/* gather messages from other routines here */
char sys_admin[20] = "/dev/console";	/* mail destination */

FILE *fopen();		/* function opens files */
FILE *popen();		/* initiate I/O to form a process */
FILE *aud;		/* host AUDIT file pointer */
FILE *outfd;		/* printer output file pointer */
void exit();

struct bscio p;		/* bsc driver parameter structure */
	
main(argc,argv)
int argc; char *argv[];
{
	char cfgfile[50];	/* device file name temp area */

/* get options from command line */
	if (--argc > 1)	{
		fprintf(stderr,"em3280: too many parameters\n");
		exit(1);
	}

/* hostname */
	if (argc)	{
		++argv;
		strcpy(hostname,argv[0]);	/* take given host name */
	}

	/* get host configuration parameters */
		sprintf(cfgfile,"%s%s",libpath,hostname);
		if (get_cnfig(cfgfile))	exit (1);
		
	/* construct temp AUDIT pathname, open AUDIT file */
		sprintf(audname,"%s%s/%s",spoolpath,hostname,"AUDIT");
	/* construct default real AUDIT pathname */
		sprintf(new_audnm,"%s%s/%s",spoolpath,hostname,"AUDIT");
		if (access(audname,0) == 0)	{
			sprintf(auditlock,"%s%s/%s",spoolpath,
				hostname,"auditlock");
			if (creat(auditlock,0) < 0)
				em_audnm();
			else
				aud = fopen(audname,"a");
		}

	do	{
	/* write "ready for connect" msg to AUDIT */
		sprintf (note,"Ready for connect via <%s>",devname);
		write_aud("C",note);

	/* call connect installation exit */
		if (connect(hostname,devname))	{
		/* skip this host if there were problems */
			sprintf(note,
			"Connection aborted by installation connect exit",
				emsg);
			write_aud("C",note);

		/* tell user about it */
			fprintf(stderr,"%s\n",note);
			post();
			cleanup();
			exit(4);
		}

#ifndef DEBUG
	/* open bsc device */
		if ((devfd = open(devname,2)) == -1) {
			if (errno == EBUSY) {
				sprintf(note,
				"Open failed, device <%s> busy.",devname);
				write_aud("C", note);
				fprintf(stderr,
				"em3280 <%s>: <%s> being used.\n",
					hostname, note);
				post();
				disconnect(hostname,devname);
				continue;
			}
			/* update AUDIT file with the news */
			sprintf(note,
			"Connection failed, <%s> couldn't be opened: %s",
				devname,sys_errlist[errno]);
			fprintf(stderr,"em3280 <%s>: %s\n",hostname,note);
			write_aud("C",note);
			disconnect(hostname,devname);
			post();
			continue;
		}
#endif

	/* write "connected" message to AUDIT file */
		sprintf(note,"Connected to <%s>",devname);
		write_aud("C",note);

#ifndef DEBUG
	/* set no-delay for device reads */
		ioctl(devfd, BSCNDLY, 0);

	/* set fast-acknowlege */
		ioctl(devfd, BSCFACK, 0);

	/* set device parameters */
		ioctl(devfd, BSCSET, &p);

	/* send initial device-end status message */
		send_stat();
#endif

	/* emulate 328x printers */
		em_printers();
		
#ifndef DEBUG
	/* close bsc device */
		close(devfd);
		break;
#endif
	}	while (getnextopen() != -1);
	cleanup();
	exit(3);
}

/* post - send mail to system administrator about sad events */
post()
{
	FILE *popen(), *pptr;
	char address[50];

	sprintf(address, "mail %s", sys_admin);
	if (sys_admin[0] == '/')	{
		pptr = fopen(sys_admin, "a");
		fputs(note, pptr);
		fclose(pptr);
	} else {
		pptr = popen(address, "w");
		fputs(note, pptr);
		pclose(pptr);
	}
}

unix.superglobalmegacorp.com

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