|
|
1.1 ! root 1: /* cons.c 1.1 88/06/02 */ ! 2: ! 3: /* ! 4: * Asynchronous versions of getchar and gets ! 5: * for use in disk formatter. ! 6: */ ! 7: #include "../machine/mtpr.h" ! 8: ! 9: #include "param.h" ! 10: #include "../tahoe/cp.h" ! 11: ! 12: int wait_for_char = 1; /* synchronous by default */ ! 13: extern struct cpdcb_i cpin; /* in ../prf.c */ ! 14: ! 15: agetchar() ! 16: { ! 17: static char_read = 0; /* read operation pending */ ! 18: char c; ! 19: ! 20: if (!char_read) { ! 21: char_read = 1; ! 22: cpin.cp_hdr.cp_unit = CPCONS; /* Resets done bit */ ! 23: cpin.cp_hdr.cp_comm = CPREAD; ! 24: cpin.cp_hdr.cp_count = 1; ! 25: mtpr(CPMDCB, &cpin); ! 26: } ! 27: uncache(&cpin.cp_hdr.cp_unit); ! 28: if (wait_for_char) { ! 29: while ((cpin.cp_hdr.cp_unit & CPDONE) == 0) ! 30: uncache(&cpin.cp_hdr.cp_unit); ! 31: } else ! 32: if ((cpin.cp_hdr.cp_unit & CPDONE) == 0) ! 33: return (0); ! 34: uncache(&cpin.cpi_buf[0]); ! 35: c = cpin.cpi_buf[0] & 0x7f; ! 36: char_read = 0; ! 37: if (c == '\r') ! 38: c = '\n'; ! 39: if (c != '\b' && c != '\177') ! 40: putchar(c); ! 41: return (c); ! 42: } ! 43: ! 44: agets(buf) ! 45: char *buf; ! 46: { ! 47: static char line[256]; ! 48: static char *lp = line; ! 49: register c; ! 50: ! 51: *buf = '\0'; ! 52: for (;;) { ! 53: c = agetchar() & 0177; ! 54: switch(c) { ! 55: case '\0' : ! 56: if (!wait_for_char) ! 57: return; ! 58: break; ! 59: case '\n': ! 60: case '\r': ! 61: c = '\n'; ! 62: *lp = '\0'; ! 63: strcpy(buf, line); ! 64: lp = line; ! 65: return; ! 66: case '\b': ! 67: case '\177': ! 68: if (lp > line) { ! 69: lp--; ! 70: putchar('\b'); ! 71: putchar(' '); ! 72: putchar('\b'); ! 73: } ! 74: continue; ! 75: case '#': ! 76: lp--; ! 77: if (lp < line) ! 78: lp = line; ! 79: continue; ! 80: case '@': ! 81: case 'u'&037: ! 82: lp = line; ! 83: putchar('\n'); ! 84: continue; ! 85: default: ! 86: if ((lp - line) < 256) ! 87: *lp++ = c; ! 88: } ! 89: } ! 90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.