|
|
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: * NAME ! 16: * em3280 - IBM 3280 printer emulator ! 17: * ! 18: * SYNOPSIS ! 19: * em3280 [<hostname>] ! 20: * ! 21: * DESCRIPTION ! 22: * em3280 is the controlling utility of the IBM 328x printer ! 23: * emulator. ! 24: * ! 25: * ALGORITHM ! 26: * I. Initialization ! 27: * A. Set signals ! 28: * B. Process control parameters ! 29: * 1. hostname - specifies control unit interface to ! 30: * emulate ! 31: * C. Get host and printer configuration parameters ! 32: * D. Call connect installation exit ! 33: * ! 34: * II. Emulate printer while no interrupts received ! 35: * A. Open the comm device ! 36: * B. Set device parameters ! 37: * C. Process a file ! 38: * D. Close the comm device ! 39: */ ! 40: ! 41: #include "local.h" ! 42: #include <bsc/bscio.h> ! 43: #include <empr.h> ! 44: #include <errno.h> ! 45: #ifdef BSD42 ! 46: #include <sys/time.h> ! 47: #else ! 48: #include <time.h> ! 49: #endif ! 50: ! 51: #ifdef DEBUG ! 52: #define libpath "./" ! 53: #define spoolpath "./" ! 54: #else ! 55: #define libpath "/usr/lib/bscbatch/" ! 56: #define spoolpath "/usr/spool/bscbatch/" ! 57: #endif ! 58: ! 59: #define YES 1 ! 60: #define NO 0 ! 61: ! 62: #ifndef lint ! 63: static char sccsid[] = "@(#)em3280.c 1.8 "; ! 64: #endif ! 65: ! 66: char hostname[20] = "3280"; /* contains host name */ ! 67: char audname[80]; /* temp audit file pathname goes here */ ! 68: char new_audnm[80]; /* real audit pathname goes here */ ! 69: char auditlock[80]; /* audit lockfile pathname goes here */ ! 70: ! 71: char *strcpy(); /* function copies one string to another */ ! 72: char *strcat(); /* function appends one string to another */ ! 73: char *getenv(); /* find string in environment */ ! 74: ! 75: int chk_hostid; ! 76: int chk_termid; ! 77: int primary = BSCPRIM; ! 78: int rviab; ! 79: int pt_to_pt; ! 80: int ascii; /* ascii or ebcdic data? */ ! 81: int devfd; /* bsc device file descriptor */ ! 82: int wflag; /* set if pipe's been written to; 0 otherwise */ ! 83: extern int errno; ! 84: extern char *sys_errlist[]; ! 85: long atol(); /* converts ascii to long */ ! 86: char devname[20]; ! 87: char outtype; /* pipe printer output to a program if this is "P", ! 88: write to a file or device if this is "F" */ ! 89: int prtype; /* terminal type */ ! 90: int tprint; /* text print option flag (3288 only) */ ! 91: int ctype; /* controller type - 1 for 3271, 5 for 3275 */ ! 92: int buffered; /* buffered printer flag */ ! 93: int vfc; /* vertical forms unit flag */ ! 94: int linesperpage; /* number of lines allowed per page */ ! 95: int stationid; /* subdevice id, translated appropriately */ ! 96: char termid; /* cluster address (poll) */ ! 97: char note[100]; /* msg to write to AUDIT file and mail */ ! 98: char emsg[80]; /* gather messages from other routines here */ ! 99: char sys_admin[20] = "/dev/console"; /* mail destination */ ! 100: ! 101: FILE *fopen(); /* function opens files */ ! 102: FILE *popen(); /* initiate I/O to form a process */ ! 103: FILE *aud; /* host AUDIT file pointer */ ! 104: FILE *outfd; /* printer output file pointer */ ! 105: void exit(); ! 106: ! 107: struct bscio p; /* bsc driver parameter structure */ ! 108: ! 109: main(argc,argv) ! 110: int argc; char *argv[]; ! 111: { ! 112: char cfgfile[50]; /* device file name temp area */ ! 113: ! 114: /* get options from command line */ ! 115: if (--argc > 1) { ! 116: fprintf(stderr,"em3280: too many parameters\n"); ! 117: exit(1); ! 118: } ! 119: ! 120: /* hostname */ ! 121: if (argc) { ! 122: ++argv; ! 123: strcpy(hostname,argv[0]); /* take given host name */ ! 124: } ! 125: ! 126: /* get host configuration parameters */ ! 127: sprintf(cfgfile,"%s%s",libpath,hostname); ! 128: if (get_cnfig(cfgfile)) exit (1); ! 129: ! 130: /* construct temp AUDIT pathname, open AUDIT file */ ! 131: sprintf(audname,"%s%s/%s",spoolpath,hostname,"AUDIT"); ! 132: /* construct default real AUDIT pathname */ ! 133: sprintf(new_audnm,"%s%s/%s",spoolpath,hostname,"AUDIT"); ! 134: if (access(audname,0) == 0) { ! 135: sprintf(auditlock,"%s%s/%s",spoolpath, ! 136: hostname,"auditlock"); ! 137: if (creat(auditlock,0) < 0) ! 138: em_audnm(); ! 139: else ! 140: aud = fopen(audname,"a"); ! 141: } ! 142: ! 143: do { ! 144: /* write "ready for connect" msg to AUDIT */ ! 145: sprintf (note,"Ready for connect via <%s>",devname); ! 146: write_aud("C",note); ! 147: ! 148: /* call connect installation exit */ ! 149: if (connect(hostname,devname)) { ! 150: /* skip this host if there were problems */ ! 151: sprintf(note, ! 152: "Connection aborted by installation connect exit", ! 153: emsg); ! 154: write_aud("C",note); ! 155: ! 156: /* tell user about it */ ! 157: fprintf(stderr,"%s\n",note); ! 158: post(); ! 159: cleanup(); ! 160: exit(4); ! 161: } ! 162: ! 163: #ifndef DEBUG ! 164: /* open bsc device */ ! 165: if ((devfd = open(devname,2)) == -1) { ! 166: if (errno == EBUSY) { ! 167: sprintf(note, ! 168: "Open failed, device <%s> busy.",devname); ! 169: write_aud("C", note); ! 170: fprintf(stderr, ! 171: "em3280 <%s>: <%s> being used.\n", ! 172: hostname, note); ! 173: post(); ! 174: disconnect(hostname,devname); ! 175: continue; ! 176: } ! 177: /* update AUDIT file with the news */ ! 178: sprintf(note, ! 179: "Connection failed, <%s> couldn't be opened: %s", ! 180: devname,sys_errlist[errno]); ! 181: fprintf(stderr,"em3280 <%s>: %s\n",hostname,note); ! 182: write_aud("C",note); ! 183: disconnect(hostname,devname); ! 184: post(); ! 185: continue; ! 186: } ! 187: #endif ! 188: ! 189: /* write "connected" message to AUDIT file */ ! 190: sprintf(note,"Connected to <%s>",devname); ! 191: write_aud("C",note); ! 192: ! 193: #ifndef DEBUG ! 194: /* set no-delay for device reads */ ! 195: ioctl(devfd, BSCNDLY, 0); ! 196: ! 197: /* set fast-acknowlege */ ! 198: ioctl(devfd, BSCFACK, 0); ! 199: ! 200: /* set device parameters */ ! 201: ioctl(devfd, BSCSET, &p); ! 202: ! 203: /* send initial device-end status message */ ! 204: send_stat(); ! 205: #endif ! 206: ! 207: /* emulate 328x printers */ ! 208: em_printers(); ! 209: ! 210: #ifndef DEBUG ! 211: /* close bsc device */ ! 212: close(devfd); ! 213: break; ! 214: #endif ! 215: } while (getnextopen() != -1); ! 216: cleanup(); ! 217: exit(3); ! 218: } ! 219: ! 220: /* post - send mail to system administrator about sad events */ ! 221: post() ! 222: { ! 223: FILE *popen(), *pptr; ! 224: char address[50]; ! 225: ! 226: sprintf(address, "mail %s", sys_admin); ! 227: if (sys_admin[0] == '/') { ! 228: pptr = fopen(sys_admin, "a"); ! 229: fputs(note, pptr); ! 230: fclose(pptr); ! 231: } else { ! 232: pptr = popen(address, "w"); ! 233: fputs(note, pptr); ! 234: pclose(pptr); ! 235: } ! 236: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.