|
|
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
* em_printers
*
* SYNOPSIS
* em_printers()
*
* DESCRIPTION
* em_printers emulates IBM 328x printers.
*
* ALGORITHM
* While there's something to read:
* I. Read from the comm device
* II. process the received print buffer
* A. Call emprbuf()
* III. print the processed buffer
* A. Call emprtr()
*/
#include <signal.h>
#include "local.h"
#include <bsc/bscio.h>
#include <empr.h>
#define ERROR -1
#ifndef lint
static char sccsid[] = "@(#)emprinters.c 1.10 ";
#endif
/* myscr[4096+5] makes sure there's room for characters leftover from the last
buffer processing (emprocbuf) at the beginning of this buffer. E.g.
an SBA came across in the last buffer and the 2-byte address supposed
to be attached to it didn't */
char myscr[4096+5];
/* device busy status messages */
char adbsptpt[] = {'%','R',0x02,'H',' '}; /* ascii, point-to-point */
char edbsptpt[] = {0x6c,0xd9,0x02,0xc8,0x40}; /* ebcdic, point-to-point */
char adbsmpt[] = {'%','R',0x02,0,0,'H',' '}; /* ascii, multipoint */
char edbsmpt[] = {0x6c,0xd9,0x02,0,0,0xc8,0x40};/* ebcdic, multipoint */
extern int devfd;
extern int errno;
extern int wflag;
extern char wcc;
extern char hostname[];
extern char devname[];
extern char audname[];
extern char new_audnm[];
extern char auditlock[];
extern char output[];
extern char outtype;
extern FILE *outfd;
extern FILE *aud;
extern struct bscio p; /* bsc driver parameter structure */
extern int pt_to_pt;
extern int devfd;
extern int stationid;
extern int ascii;
extern char termid;
extern char note[];
int sigint(); /* deal with signal interrupts */
void exit();
unsigned sleep();
em_printers()
{
register int len; /* number of chars read in thru devfd */
register char *myptr;
register int mylen;
register unsigned mysize;
int i; /* convenient index */
char tbuf[512]; /* temp buffer */
FILE *fopen();
FILE *popen();
#ifdef DEBUG
int f; /* debug file descriptor */
#endif
/* set signals */
if (isatty(0)) {
signal(SIGINT,sigint);
signal(SIGHUP,sigint);
} else {
signal(SIGTERM,sigint);
signal(SIGINT,SIG_IGN);
signal(SIGQUIT,SIG_IGN);
signal(SIGHUP,SIG_IGN);
}
fiximage(0);
#ifdef DEBUG
len = 0;
if (outtype == 'P') wflag = 0;
f = open("buffer",0);
/* do proper open for type of output: device, pipe, or file */
if (outtype == 'F' || outtype == 'P')
if (outtype == 'F')
outfd = fopen(output, "a");
else
outfd = popen(output, "a");
else outfd = stdout;
len=read(f,&myscr[5],sizeof myscr-5);
emprbuf(&myscr[5],len); /* process received file */
emprtr(); /* print received file */
close(f); /* close received file */
if (outtype == 'F')
fclose(outfd);
else if (outtype == 'P' && wflag)
pclose(outfd);
cleanup();
exit(0);
#else
/* do proper open for type of output: device, pipe, or file */
if (outtype == 'F' || outtype == 'P')
if (outtype == 'F')
outfd = fopen(output, "a");
else
outfd = popen(output, "a");
else
outfd = stdout;
while (1) {
myptr = &myscr[5];
mysize = sizeof myscr - 5;
mylen = 0;
READ: /* read from the comm device */
while ((len = read(devfd,myptr,mysize)) > 0) {
myptr += len;
mysize -= len;
mylen += len;
(void) sleep((unsigned)5);
read(devfd, tbuf, sizeof tbuf);
ioctl(devfd, BSCGET, &p);
break;
}
if (len < 0 && errno == EINTR && mylen != 0)
goto READ;
/* For EAGAIN, there is no data, so wait (long) while */
if (len < 0 && errno == EAGAIN) {
/***** sleep((unsigned)5); *****/
goto READ;
}
if (len < 0 ) {
(void)get_errors();
if (p.b_flags == BSCNDSR ||
p.b_flags == BSCTXTO) {
/* update the audit file */
write_aud("D", note);
cleanup();
exit(1);
}
if (p.b_flags == BSCRXTO) {
if (outtype == 'F' && outfd) {
fclose(outfd);
/* send printer status msg */
send_stat();
outfd = fopen(output,"a");
}
else if (outtype == 'P' && wflag) {
wflag =0;
pclose(outfd);
/* send printer status msg */
send_stat();
outfd = popen(output,"w");
}
continue;
}
p.b_flags = 0;
}
if (mylen) {
/* send device busy status -- we're busy processing */
if (pt_to_pt == BSCMPT) {
ioctl (devfd, BSCID, &stationid);
ioctl(devfd,BSCSOH,0); /* set SOH mode & */
ioctl(devfd,BSCLAST,0); /* LAST message flag */
if (ascii) {
adbsmpt[3] = termid; /* poll addr */
adbsmpt[4]= stationid; /* subdev addr */
i=write(devfd, adbsmpt, sizeof adbsmpt);
} else {
edbsmpt[3] = termid; /* poll addr */
edbsmpt[4] =stationid; /* subdev addr */
i=write(devfd, edbsmpt, sizeof edbsmpt);
}
} else
/* Send status message for pt-pt */
i= write(devfd,ascii?adbsptpt:edbsptpt,
sizeof adbsptpt);
ioctl(devfd,BSCNSOH,0); /* end SOH mode */
/* ignore any errors from the write */
if (i < 0) ioctl(devfd, BSCGET, &p);
emprbuf(&myscr[5],mylen); /* process buffer */
if (stprt(wcc)) /* if start print set in wcc, */
emprtr(); /* print buffer */
send_stat();
}
}
#endif
}
/* sigint -- signal interrupt processing routine. This is the only way out of
em3280 */
sigint(signum)
{
char msg[50];
sprintf(msg,"Interrupt signal %d received",signum);
/* update the audit file */
write_aud("D",msg);
cleanup();
exit(2);
}
/* send_stat() -- send printer status message */
char ascsptpt[] = {'%','R',0x02,0x42,0x20}; /* ascii, point-to-point */
char ebcsptpt[] = {0x6c,0xd9,0x02,0xc2,0x40}; /* ebcdic, point-to-point */
char ascsmpt[] = {'%','R',0x02,0,0,0x42,0x20}; /* ascii, multipoint */
char ebcsmpt[] = {0x6c,0xd9,0x02,0,0,0xc2,0x40}; /* ebcdic, multipoint */
send_stat()
{
int i = 0; /* catch write errors here */
#ifndef DEBUG
/* Send status message: SOH % R STX ..... ETX */
if (pt_to_pt == BSCMPT) {
ioctl (devfd, BSCID, &stationid);
ioctl(devfd,BSCSOH,0); /* set SOH mode */
ioctl(devfd,BSCLAST,0); /* set LAST message flag */
if (ascii) {
ascsmpt[3] = termid; /* poll addr */
ascsmpt[4] = stationid; /* subdev addr */
i = write(devfd, ascsmpt, sizeof ascsmpt);
} else {
ebcsmpt[3] = termid; /* poll addr */
ebcsmpt[4] = stationid; /* subdev addr */
i = write(devfd, ebcsmpt, sizeof ebcsmpt);
}
} else
/* Send status message for pt-pt */
i= write(devfd,ascii?ascsptpt:ebcsptpt,sizeof ascsptpt);
ioctl(devfd,BSCNSOH,0); /* end SOH mode */
/* ignore any errors from the write */
if (i < 0) ioctl(devfd, BSCGET, &p);
#endif
}
/* cleanup -- do end processing */
cleanup()
{
/* close output */
if (outfd) {
if (outtype == 'F')
fclose(outfd);
else if (outtype == 'P' && wflag)
pclose(outfd);
outfd = (FILE *)0;
wflag = 0;
}
if (devfd > 0) {
close (devfd);
devfd = -1;
disconnect(hostname,devname);
}
if (aud) {
fclose(aud);
if (link(audname, new_audnm) >= 0)
unlink(audname);
unlink(auditlock);
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.