|
|
1.1 ! root 1: /* ! 2: * lpd - Printronix line printer daemon dispatcher ! 3: */ ! 4: ! 5: #include <ctype.h> ! 6: #include <sys/ttyio.h> ! 7: #include <sys/filio.h> ! 8: ! 9: #define SPIDER 0 ! 10: #define PHONE 0 ! 11: #define LPD 1 ! 12: ! 13: #include "daemon.c" ! 14: ! 15: /* ! 16: * The remaining part is the line printer interface. ! 17: */ ! 18: ! 19: FILE *lpf = NULL; ! 20: ! 21: #define LINESIZE 1000 ! 22: ! 23: char buf[LINESIZE], ubuf[LINESIZE]; ! 24: int ulen, blen; ! 25: ! 26: dem_con() ! 27: { ! 28: return(0); ! 29: } ! 30: ! 31: dem_dis() ! 32: { ! 33: FCLOSE(lpf); ! 34: FCLOSE(dfb); ! 35: } ! 36: ! 37: dem_open(file) ! 38: char *file; ! 39: { ! 40: struct sgttyb tb; ! 41: struct ttydevb grime; ! 42: static char iobuf[BUFSIZ]; ! 43: int ld = 0; ! 44: extern int tty_ld; ! 45: ! 46: if((lpf = fopen(lp, "w")) == NULL) ! 47: trouble("Can't open %s", lp); ! 48: if (ioctl(fileno(lpf), FIOLOOKLD, &ld)<0 || ld!=tty_ld) ! 49: ioctl(fileno(lpf), FIOPUSHLD, &tty_ld); ! 50: if (ioctl(fileno(lpf), TIOCGETP, &tb) < 0) ! 51: trouble("Can't do gtty(%s)\n", lp); ! 52: ioctl(fileno(lpf), TIOCGDEV, &grime); ! 53: tb.sg_ispeed = tb.sg_ospeed = B9600; /* obsolescent */ ! 54: tb.sg_flags &= ~ALLDELAY; ! 55: tb.sg_flags |= XTABS; ! 56: if (ioctl(fileno(lpf), TIOCSETP, &tb) < 0) ! 57: trouble("Can't do stty(%s)\n", lp); ! 58: grime.ispeed = grime.ospeed = B9600; ! 59: ioctl(fileno(lpf), TIOCSDEV, &grime); ! 60: setbuf (lpf, iobuf); ! 61: } ! 62: ! 63: ! 64: dem_close() ! 65: { ! 66: dem_dis(); ! 67: } ! 68: ! 69: get_snumb() ! 70: { ! 71: } ! 72: ! 73: lwrite() ! 74: { ! 75: banner(lpf, &line[1]); ! 76: } ! 77: ! 78: ! 79: FILE *ibuf; ! 80: ! 81: enum linemode {normal, large, plot}; ! 82: ! 83: /* ! 84: * how many rows of dots have appeared on this page. ! 85: * ! 86: * there are ten rows per normal character, 20 per ! 87: * large character. We count dots to know whether ! 88: * to emit a form feed at the end. ! 89: */ ! 90: int dots = 0; ! 91: ! 92: /* Heights for various character modes */ ! 93: #define NDOTS 10 ! 94: #define LDOTS 20 ! 95: #define PDOTS 1 ! 96: ! 97: /* vertical granularity in non-plot mode */ ! 98: #define GRAIN 10 ! 99: ! 100: /* align x downward with granularity y */ ! 101: #define align(x,y) (((x)/(y))*(y)) ! 102: ! 103: /* Page depth, in dots */ ! 104: #define PAGE 660 ! 105: ! 106: sascii(fc) ! 107: char fc; ! 108: { ! 109: register int c, p; ! 110: register enum linemode lm; ! 111: ! 112: if((ibuf = fopen(&line[1], "r")) == NULL) ! 113: return(0); ! 114: if(fc == 'F') ! 115: putc(ff, lpf); ! 116: ! 117: clr(); ! 118: p = 0; ! 119: lm = normal; ! 120: while ((c = getc (ibuf)) != EOF) { ! 121: switch (c) { ! 122: ! 123: case ' ': ! 124: ++p; ! 125: break; ! 126: ! 127: case '\b': ! 128: if (p > 0) ! 129: --p; ! 130: break; ! 131: ! 132: case '\t': ! 133: p = (p + 8) & -8; ! 134: break; ! 135: ! 136: case '\r': ! 137: p = 0; ! 138: break; ! 139: ! 140: case '\n': ! 141: case '\f': ! 142: emit(c, lm); ! 143: lm = normal; ! 144: clr(); ! 145: p = 0; ! 146: break; ! 147: ! 148: case '\033': /* escape-backspace for expand */ ! 149: c = getc (ibuf); ! 150: if (c == '\b') ! 151: lm = large; ! 152: break; ! 153: ! 154: case '\005': /* plot mode */ ! 155: lm = plot; ! 156: break; ! 157: ! 158: default: ! 159: if (p < LINESIZE) { ! 160: if (p < blen && buf[p] != ' ') { ! 161: if (c == '_' || buf[p] == '_') { ! 162: ubuf[p] = '_'; ! 163: if (p >= ulen) ! 164: ulen = p + 1; ! 165: } ! 166: if (c == '_') ! 167: c = buf[p]; ! 168: } ! 169: buf[p++] = c; ! 170: if (p > blen) ! 171: blen = p; ! 172: } ! 173: break; ! 174: ! 175: } ! 176: } ! 177: ! 178: /* if we're not exactly at page end, start a new page */ ! 179: if (dots % PAGE) ! 180: putc ('\f', lpf); ! 181: ! 182: fflush(lpf); ! 183: fclose(ibuf); ! 184: return(0); ! 185: } ! 186: ! 187: etcp1() ! 188: { ! 189: } ! 190: ! 191: /* VARARGS */ ! 192: trouble(s, a1, a2, a3, a4) ! 193: char *s; ! 194: { ! 195: if(retcode != 0){ ! 196: dem_dis(); ! 197: } ! 198: logerr(s, a1, a2, a3, a4); ! 199: longjmp(env, 1); ! 200: } ! 201: ! 202: /* VARARGS */ ! 203: logerr(s, a1, a2, a3, a4) ! 204: char *s; ! 205: int a1, a2, a3, a4; ! 206: { ! 207: #ifdef DEBUG ! 208: fprintf(stderr, s, a1, a2, a3, a4); ! 209: putc('\n', stderr); ! 210: #endif ! 211: } ! 212: ! 213: getowner() ! 214: { ! 215: } ! 216: ! 217: maildname() ! 218: { ! 219: fprintf(pmail, "Your %s job for file %s is finished, bignose.\n", DAEMNAM, mailfname); ! 220: } ! 221: ! 222: clr() ! 223: { ! 224: register int i; ! 225: ! 226: ulen = blen = 0; ! 227: ! 228: for (i = 0; i < LINESIZE; i++) ! 229: buf[i] = ubuf[i] = ' '; ! 230: } ! 231: ! 232: emit(c, mode) ! 233: register int c; ! 234: register enum linemode mode; ! 235: { ! 236: register int i; ! 237: ! 238: switch (mode) { ! 239: case large: ! 240: dots = align (dots, GRAIN) + LDOTS; ! 241: putc ('\b', lpf); ! 242: break; ! 243: ! 244: case plot: ! 245: dots += PDOTS; ! 246: putc ('\005', lpf); ! 247: while (blen > 0 && (buf[blen-1] & 077) == 0) ! 248: --blen; ! 249: break; ! 250: ! 251: case normal: ! 252: dots = align (dots, GRAIN) + NDOTS; ! 253: break; ! 254: } ! 255: ! 256: for (i = 0; i < blen; i++) ! 257: putc (buf[i], lpf); ! 258: ! 259: if (ulen && mode != plot) { ! 260: putc ('\r', lpf); ! 261: for (i = 0; i < ulen; i++) ! 262: putc (ubuf[i], lpf); ! 263: } ! 264: ! 265: putc (c, lpf); ! 266: if (c == '\f') ! 267: dots = 0; ! 268: ! 269: if (ferror (lpf)) ! 270: trouble ("Output error on %s\n", lp); ! 271: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.