Annotation of cci/usr/src/usr.bin/bsc/cmd/3270/emprinters.c, revision 1.1

1.1     ! root        1: /*     D.L.Buck and Associates, Inc. - 8/27/84
        !             2:  *
        !             3:  *     COPYRIGHT NOTICE:
        !             4:  *             Copyright c 8/27/84 - An unpublished work by
        !             5:  *             D.L.Buck and Associates, Inc.
        !             6:  *
        !             7:  *     PROPRIETARY RIGHTS NOTICE:
        !             8:  *             All rights reserved. This document and program contains
        !             9:  *             proprietary information of D.L.Buck and Associates,Inc.
        !            10:  *             of San Jose, California, U.S.A., embodying confidential
        !            11:  *             information,  ideas, and expressions,  no part of which
        !            12:  *             may be reproduced, or transmitted in any form or by any
        !            13:  *             means,  electronic,  mechanical,  or otherwise, without
        !            14:  *             the written permission of D.L.Buck and Associates, Inc.
        !            15:  *
        !            16:  * NAME
        !            17:  *     em_printers
        !            18:  *
        !            19:  * SYNOPSIS
        !            20:  *     em_printers()
        !            21:  *
        !            22:  * DESCRIPTION
        !            23:  *     em_printers emulates IBM 328x printers. 
        !            24:  *
        !            25:  * ALGORITHM
        !            26:  *     While there's something to read:
        !            27:  *              I. Read from the comm device
        !            28:  *             II. process the received print buffer
        !            29:  *                     A. Call emprbuf()
        !            30:  *             III. print the processed buffer
        !            31:  *                     A. Call emprtr()
        !            32:  */
        !            33: #include <signal.h>
        !            34: #include "local.h"
        !            35: #include <bsc/bscio.h>
        !            36: #include <empr.h>
        !            37: 
        !            38: #define ERROR -1
        !            39: 
        !            40: #ifndef lint
        !            41: static char sccsid[] = "@(#)emprinters.c       1.10 ";
        !            42: #endif
        !            43: 
        !            44: /* myscr[4096+5] makes sure there's room for characters leftover from the last 
        !            45:    buffer processing (emprocbuf) at the beginning of this buffer. E.g.
        !            46:    an SBA came across in the last buffer and the 2-byte address supposed
        !            47:    to be attached to it didn't */
        !            48: char myscr[4096+5];
        !            49: 
        !            50: /* device busy status messages */
        !            51: char adbsptpt[] = {'%','R',0x02,'H',' '};      /* ascii, point-to-point */
        !            52: char edbsptpt[] = {0x6c,0xd9,0x02,0xc8,0x40};  /* ebcdic, point-to-point */
        !            53: char adbsmpt[] = {'%','R',0x02,0,0,'H',' '};   /* ascii, multipoint    */
        !            54: char edbsmpt[] = {0x6c,0xd9,0x02,0,0,0xc8,0x40};/* ebcdic, multipoint  */
        !            55: 
        !            56: extern int devfd;
        !            57: extern int errno;
        !            58: extern int wflag;
        !            59: extern char wcc;
        !            60: extern char hostname[];
        !            61: extern char devname[];
        !            62: extern char audname[];
        !            63: extern char new_audnm[];
        !            64: extern char auditlock[];
        !            65: extern char output[];
        !            66: extern char outtype;
        !            67: extern FILE *outfd;
        !            68: extern FILE *aud;
        !            69: 
        !            70: extern struct bscio p;         /* bsc driver parameter structure */
        !            71: extern int pt_to_pt;
        !            72: extern int devfd;
        !            73: extern int stationid;
        !            74: extern int ascii;
        !            75: extern char termid;
        !            76: extern char note[];
        !            77: 
        !            78: int sigint();                  /* deal with signal interrupts */
        !            79: void exit();
        !            80: unsigned sleep();
        !            81: 
        !            82: em_printers()
        !            83: {
        !            84:        register int len;               /* number of chars read in thru devfd */
        !            85:        register char *myptr;
        !            86:        register int mylen;
        !            87:        register unsigned mysize;
        !            88:        int i;                          /* convenient index */
        !            89: 
        !            90:        char tbuf[512];                 /* temp buffer */
        !            91:        FILE *fopen();
        !            92:        FILE *popen();
        !            93: #ifdef DEBUG
        !            94:        int f;          /* debug file descriptor */
        !            95: #endif
        !            96: 
        !            97: /* set signals */
        !            98:        if (isatty(0))  {
        !            99:                signal(SIGINT,sigint);
        !           100:                signal(SIGHUP,sigint);
        !           101:        } else  {
        !           102:                signal(SIGTERM,sigint);
        !           103:                signal(SIGINT,SIG_IGN);
        !           104:                signal(SIGQUIT,SIG_IGN);
        !           105:                signal(SIGHUP,SIG_IGN);
        !           106:        }
        !           107: 
        !           108:        fiximage(0);
        !           109: #ifdef DEBUG
        !           110:        len = 0;
        !           111:        if (outtype == 'P') wflag = 0;
        !           112:        f = open("buffer",0);
        !           113: 
        !           114: /* do proper open for type of output: device, pipe, or file */
        !           115:        if (outtype == 'F' || outtype == 'P')
        !           116:                if (outtype == 'F')
        !           117:                        outfd = fopen(output, "a");
        !           118:                else
        !           119:                        outfd = popen(output, "a");
        !           120:        else outfd = stdout;
        !           121: 
        !           122:        len=read(f,&myscr[5],sizeof myscr-5);
        !           123: 
        !           124:        emprbuf(&myscr[5],len);         /* process received file */
        !           125:        emprtr();                       /* print received file */
        !           126:        close(f);                       /* close received file */
        !           127:        if (outtype == 'F')
        !           128:                fclose(outfd);
        !           129:        else if (outtype == 'P' && wflag)
        !           130:                pclose(outfd);
        !           131:        cleanup();
        !           132:        exit(0);
        !           133: #else
        !           134:        /* do proper open for type of output: device, pipe, or file */
        !           135:                if (outtype == 'F' || outtype == 'P')
        !           136:                        if (outtype == 'F')
        !           137:                                outfd = fopen(output, "a");
        !           138:                        else
        !           139:                                outfd = popen(output, "a");
        !           140:                else
        !           141:                        outfd = stdout;
        !           142: 
        !           143:        while (1)       {
        !           144:                myptr = &myscr[5];
        !           145:                mysize = sizeof myscr - 5;
        !           146:                mylen = 0;
        !           147: 
        !           148: READ:          /* read from the comm device */
        !           149:                while ((len = read(devfd,myptr,mysize)) > 0) {
        !           150:                        myptr += len;
        !           151:                        mysize -= len;
        !           152:                        mylen += len;
        !           153: 
        !           154:                        (void) sleep((unsigned)5);
        !           155:                        read(devfd, tbuf, sizeof tbuf);
        !           156:                        ioctl(devfd, BSCGET, &p);
        !           157:                        break;
        !           158:                }
        !           159: 
        !           160:                if (len < 0 && errno == EINTR && mylen != 0)
        !           161:                        goto READ;
        !           162: 
        !           163:                /* For EAGAIN, there is no data, so wait (long) while */
        !           164:                if (len < 0 && errno == EAGAIN) {
        !           165:                /*****  sleep((unsigned)5);  *****/
        !           166:                        goto READ;
        !           167:                }
        !           168: 
        !           169:                if (len < 0 )   {
        !           170:                        (void)get_errors();
        !           171:                        if (p.b_flags == BSCNDSR ||
        !           172:                            p.b_flags == BSCTXTO) {
        !           173:                                /* update the audit file */
        !           174:                                        write_aud("D", note);
        !           175:                                        cleanup();
        !           176:                                        exit(1);
        !           177:                        }
        !           178:                        
        !           179:                        if (p.b_flags == BSCRXTO)       {
        !           180:                                if (outtype == 'F' && outfd)    {
        !           181:                                        fclose(outfd);
        !           182:                                /* send printer status msg */
        !           183:                                        send_stat();
        !           184:                                        outfd = fopen(output,"a");
        !           185:                                }
        !           186:                                else if (outtype == 'P' && wflag)       {
        !           187:                                                wflag =0;
        !           188:                                                pclose(outfd);
        !           189:                                        /* send printer status msg */
        !           190:                                                send_stat();
        !           191:                                                outfd = popen(output,"w");
        !           192:                                }
        !           193:                                continue;
        !           194:                        }
        !           195:                        p.b_flags = 0;
        !           196:                }
        !           197: 
        !           198:                if (mylen)      {
        !           199:                /* send device busy status -- we're busy processing */
        !           200:                        if (pt_to_pt == BSCMPT) {
        !           201:                                ioctl (devfd, BSCID, &stationid);
        !           202:                                ioctl(devfd,BSCSOH,0);  /* set SOH mode & */
        !           203:                                ioctl(devfd,BSCLAST,0); /* LAST message flag */
        !           204:                                if (ascii) {
        !           205:                                        adbsmpt[3] = termid;    /* poll addr */
        !           206:                                        adbsmpt[4]= stationid; /* subdev addr */
        !           207:                                        i=write(devfd, adbsmpt, sizeof adbsmpt);
        !           208:                                } else {
        !           209:                                        edbsmpt[3] = termid;    /* poll addr */
        !           210:                                        edbsmpt[4] =stationid; /* subdev addr */
        !           211:                                        i=write(devfd, edbsmpt, sizeof edbsmpt);
        !           212:                                }
        !           213:                         } else
        !           214:                        /* Send status message for pt-pt */
        !           215:                                i= write(devfd,ascii?adbsptpt:edbsptpt,
        !           216:                                         sizeof adbsptpt);
        !           217: 
        !           218:                        ioctl(devfd,BSCNSOH,0); /* end SOH mode */
        !           219:                /* ignore any errors from the write */
        !           220:                        if (i < 0) ioctl(devfd, BSCGET, &p);
        !           221:                        emprbuf(&myscr[5],mylen);       /* process buffer */
        !           222:                        if (stprt(wcc))         /* if start print set in wcc, */
        !           223:                                emprtr();       /* print buffer */
        !           224:                        send_stat();
        !           225:                }
        !           226:        }
        !           227: #endif
        !           228: }
        !           229: 
        !           230: /* sigint -- signal interrupt processing routine. This is the only way out of 
        !           231:    em3280 */
        !           232: sigint(signum)
        !           233: {
        !           234:        char msg[50];
        !           235:        sprintf(msg,"Interrupt signal %d received",signum);
        !           236: /* update the audit file */
        !           237:        write_aud("D",msg);
        !           238:        cleanup();
        !           239:        exit(2);
        !           240: }
        !           241: 
        !           242: /* send_stat() -- send printer status message */
        !           243: char ascsptpt[] = {'%','R',0x02,0x42,0x20};    /* ascii, point-to-point */
        !           244: char ebcsptpt[] = {0x6c,0xd9,0x02,0xc2,0x40};  /* ebcdic, point-to-point */
        !           245: char ascsmpt[] = {'%','R',0x02,0,0,0x42,0x20}; /* ascii, multipoint */
        !           246: char ebcsmpt[] = {0x6c,0xd9,0x02,0,0,0xc2,0x40};       /* ebcdic, multipoint */
        !           247: 
        !           248: send_stat()
        !           249: {
        !           250:        int i = 0;      /* catch write errors here */
        !           251: #ifndef DEBUG
        !           252: /* Send status message: SOH % R STX ..... ETX */
        !           253:        if (pt_to_pt == BSCMPT) {
        !           254:                ioctl (devfd, BSCID, &stationid);
        !           255:                ioctl(devfd,BSCSOH,0);  /* set SOH mode */
        !           256:                ioctl(devfd,BSCLAST,0); /* set LAST message flag */
        !           257:                if (ascii) {
        !           258:                        ascsmpt[3] = termid;    /* poll addr */
        !           259:                        ascsmpt[4] = stationid; /* subdev addr */
        !           260:                        i = write(devfd, ascsmpt, sizeof ascsmpt);
        !           261:                } else {
        !           262:                        ebcsmpt[3] = termid;    /* poll addr */
        !           263:                        ebcsmpt[4] = stationid; /* subdev addr */
        !           264:                        i = write(devfd, ebcsmpt, sizeof ebcsmpt);
        !           265:                }
        !           266:         } else
        !           267:        /* Send status message for pt-pt */
        !           268:                i= write(devfd,ascii?ascsptpt:ebcsptpt,sizeof ascsptpt);
        !           269: 
        !           270:        ioctl(devfd,BSCNSOH,0); /* end SOH mode */
        !           271: /* ignore any errors from the write */
        !           272:        if (i < 0) ioctl(devfd, BSCGET, &p);
        !           273: #endif
        !           274: }
        !           275: 
        !           276: /* cleanup -- do end processing */
        !           277: cleanup()
        !           278: {
        !           279: /* close output */
        !           280:        if (outfd) {
        !           281:                if (outtype == 'F')
        !           282:                        fclose(outfd);
        !           283:                else if (outtype == 'P' && wflag)
        !           284:                        pclose(outfd);
        !           285:                outfd = (FILE *)0;
        !           286:                wflag = 0;
        !           287:        }
        !           288:        if (devfd > 0) {
        !           289:                close (devfd);
        !           290:                devfd = -1;
        !           291:                disconnect(hostname,devname);
        !           292:        }
        !           293: 
        !           294:        if (aud)        {
        !           295:                fclose(aud);
        !           296:                if (link(audname, new_audnm) >= 0)
        !           297:                        unlink(audname);
        !           298:                unlink(auditlock);
        !           299:        }
        !           300: }

unix.superglobalmegacorp.com

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