|
|
1.1 ! root 1: /* ! 2: * lpd - Printronix line printer daemon dispatcher ! 3: */ ! 4: ! 5: #include <ctype.h> ! 6: #include <sgtty.h> ! 7: ! 8: #define SPIDER 0 ! 9: #define PHONE 0 ! 10: #define LPD 1 ! 11: ! 12: #include "daemon.c" ! 13: ! 14: /* ! 15: * The remaining part is the line printer interface. ! 16: */ ! 17: ! 18: FILE *lpf = NULL; ! 19: ! 20: #define LINESIZE 1000 ! 21: ! 22: char buf[LINESIZE], ubuf[LINESIZE]; ! 23: int ulen, blen; ! 24: ! 25: dem_con() ! 26: { ! 27: return(0); ! 28: } ! 29: ! 30: dem_dis() ! 31: { ! 32: FCLOSE(lpf); ! 33: FCLOSE(dfb); ! 34: } ! 35: ! 36: dem_open(file) ! 37: char *file; ! 38: { ! 39: struct sgttyb tb; ! 40: static char iobuf[BUFSIZ]; ! 41: ! 42: if((lpf = fopen(lp, "w")) == NULL) ! 43: trouble("Can't open %s", lp); ! 44: ! 45: if (gtty(fileno(lpf),&tb) < 0) ! 46: trouble("Can't do gtty(%s)\n", lp); ! 47: ! 48: tb.sg_ispeed = tb.sg_ospeed = B9600; ! 49: tb.sg_flags &= ~ALLDELAY; ! 50: tb.sg_flags |= XTABS; ! 51: ! 52: if (stty(fileno(lpf),&tb) < 0) ! 53: trouble("Can't do stty(%s)\n", lp); ! 54: ! 55: setbuf (lpf, iobuf); ! 56: } ! 57: ! 58: ! 59: dem_close() ! 60: { ! 61: dem_dis(); ! 62: } ! 63: ! 64: get_snumb() ! 65: { ! 66: } ! 67: ! 68: lwrite() ! 69: { ! 70: banner(lpf, &line[1]); ! 71: } ! 72: ! 73: ! 74: FILE *ibuf; ! 75: ! 76: enum linemode {normal, large, plot}; ! 77: ! 78: sascii(fc) ! 79: char fc; ! 80: { ! 81: register int c, p; ! 82: register enum linemode lm; ! 83: ! 84: if((ibuf = fopen(&line[1], "r")) == NULL) ! 85: return(0); ! 86: if(fc == 'F') ! 87: putc(ff, lpf); ! 88: ! 89: clr(); ! 90: p = 0; ! 91: lm = normal; ! 92: while ((c = getc (ibuf)) != EOF) { ! 93: switch (c) { ! 94: ! 95: case ' ': ! 96: ++p; ! 97: break; ! 98: ! 99: case '\b': ! 100: if (p > 0) ! 101: --p; ! 102: break; ! 103: ! 104: case '\t': ! 105: p = (p + 8) & -8; ! 106: break; ! 107: ! 108: case '\r': ! 109: p = 0; ! 110: break; ! 111: ! 112: case '\n': ! 113: case '\f': ! 114: emit(c, lm); ! 115: lm = normal; ! 116: clr(); ! 117: p = 0; ! 118: break; ! 119: ! 120: case '\033': /* escape for expand */ ! 121: lm = large; ! 122: break; ! 123: ! 124: case '\005': /* plot mode */ ! 125: lm = plot; ! 126: break; ! 127: ! 128: default: ! 129: if (p < LINESIZE) { ! 130: if (lm != plot && c == '_') { ! 131: ubuf[p++] = c; ! 132: if (p > ulen) ! 133: ulen = p; ! 134: } else { ! 135: buf[p++] = c; ! 136: if (p > blen) ! 137: blen = p; ! 138: } ! 139: } ! 140: break; ! 141: ! 142: } ! 143: } ! 144: fflush(lpf); ! 145: fclose(ibuf); ! 146: return(0); ! 147: } ! 148: ! 149: etcp1() ! 150: { ! 151: } ! 152: ! 153: /* VARARGS */ ! 154: trouble(s, a1, a2, a3, a4) ! 155: char *s; ! 156: { ! 157: if(retcode != 0){ ! 158: dem_dis(); ! 159: } ! 160: logerr(s, a1, a2, a3, a4); ! 161: longjmp(env, 1); ! 162: } ! 163: ! 164: /* VARARGS */ ! 165: logerr(s, a1, a2, a3, a4) ! 166: char *s; ! 167: int a1, a2, a3, a4; ! 168: { ! 169: #ifdef DEBUG ! 170: fprintf(stderr, s, a1, a2, a3, a4); ! 171: putc('\n', stderr); ! 172: #endif ! 173: } ! 174: ! 175: getowner() ! 176: { ! 177: } ! 178: ! 179: maildname() ! 180: { ! 181: fprintf(pmail, "Your %s job for file %s is finished.\n", DAEMNAM, mailfname); ! 182: } ! 183: ! 184: clr() ! 185: { ! 186: register int i; ! 187: ! 188: ulen = blen = 0; ! 189: ! 190: for (i = 0; i < LINESIZE; i++) ! 191: buf[i] = ubuf[i] = ' '; ! 192: } ! 193: ! 194: emit(c, mode) ! 195: register int c; ! 196: register enum linemode mode; ! 197: { ! 198: register int i; ! 199: ! 200: switch (mode) { ! 201: case large: ! 202: putc ('\b', lpf); ! 203: break; ! 204: ! 205: case plot: ! 206: putc ('\005', lpf); ! 207: while (blen > 0 && (buf[blen-1] & 077) == 0) ! 208: --blen; ! 209: break; ! 210: } ! 211: ! 212: for (i = 0; i < blen; i++) ! 213: putc (buf[i], lpf); ! 214: ! 215: if (ulen && mode != plot) { ! 216: putc ('\r', lpf); ! 217: for (i = 0; i < ulen; i++) ! 218: putc (ubuf[i], lpf); ! 219: } ! 220: ! 221: putc (c, lpf); ! 222: ! 223: if (ferror (lpf)) ! 224: trouble ("Output error on %s\n", lp); ! 225: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.