|
|
1.1 ! root 1: /* ! 2: * paper command: filter to print on HP2621P without dropping ! 3: * characters due to intervening layers of system buffering. ! 4: * This version is (hopefully) independent of strap settings. ! 5: * Operates by handshaking with terminal every N characters. ! 6: */ ! 7: ! 8: #include <signal.h> ! 9: #include <sgtty.h> ! 10: #include <stdio.h> ! 11: ! 12: #define N 25 ! 13: #define ESC '\033' ! 14: #define DC1 '\021' ! 15: ! 16: char buff[N+1]; ! 17: char enqstat[] = {ESC, '^', DC1, DC1}; ! 18: char printon[] = {ESC, '&', 'p', '1', '1', 'C', DC1, DC1, '\r', '\n'}; ! 19: char printoff[] = {ESC, '&', 'p', '1', '3', 'C', DC1, DC1, '\r', '\n'}; ! 20: ! 21: char done = 0; ! 22: struct sgttyb oldtty, newtty; ! 23: ! 24: interrupt () ! 25: { ! 26: signal (SIGINT, SIG_IGN); ! 27: signal (SIGQUIT, SIG_IGN); ! 28: signal (SIGTERM, SIG_IGN); ! 29: newtty.sg_flags |= RAW; ! 30: stty (2, &newtty); ! 31: write (2, printoff, sizeof printoff); ! 32: sleep (3); ! 33: stty (2, &oldtty); ! 34: exit (1); ! 35: } ! 36: ! 37: prepare () ! 38: { ! 39: register int n=0, c; ! 40: static char saveesc=0; ! 41: if (saveesc) { ! 42: buff[n++] = ESC; ! 43: saveesc = 0; ! 44: } ! 45: if (done) ! 46: return n; ! 47: while (n < N) { ! 48: c = getchar(); ! 49: if (c == EOF) { ! 50: done = 1; ! 51: break; ! 52: } ! 53: if (c==ESC && n+4>=N) { ! 54: saveesc = 1; ! 55: break; ! 56: } ! 57: if (c == '\n') ! 58: buff[n++] = '\r'; ! 59: buff[n++] = c; ! 60: } ! 61: return n; ! 62: } ! 63: ! 64: await (c) ! 65: int c; ! 66: { ! 67: static char got; ! 68: while (1) { ! 69: if (read(2, &got, 1) != 1) ! 70: interrupt (); ! 71: if (got == c) ! 72: return; ! 73: } ! 74: } ! 75: ! 76: main (argc, argv) ! 77: int argc; ! 78: char **argv; ! 79: { ! 80: register int n; ! 81: gtty (2, &oldtty); ! 82: signal (SIGINT, interrupt); ! 83: signal (SIGQUIT, interrupt); ! 84: signal (SIGTERM, interrupt); ! 85: newtty = oldtty; ! 86: newtty.sg_flags = EVENP | ODDP | CBREAK; ! 87: newtty.sg_flags |= n = oldtty.sg_flags & XTABS; ! 88: stty (2, &newtty); ! 89: write (2, printon, sizeof printon); ! 90: ! 91: n = 0; ! 92: do { ! 93: write (2, enqstat, sizeof enqstat); ! 94: write (2, buff, n); ! 95: n = prepare(); ! 96: await (ESC); ! 97: await ('\r'); ! 98: } while (n != 0); ! 99: ! 100: write (2, printoff, sizeof printoff); ! 101: write (2, enqstat, sizeof enqstat); ! 102: await (ESC); ! 103: await ('\r'); ! 104: stty (2, &oldtty); ! 105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.