1 #ifndef lint 2 static char *sccsid = "@(#)wwgets.c 3.1 83/08/11"; 3 #endif 4 5 #include "defs.h" 6 7 char *ibufp = ibuf; 8 9 bread() 10 { 11 register n; 12 register char *p; 13 int imask; 14 15 while (ibufc == 0) { 16 wwupdate(); 17 wwflush(); 18 imask = 1 << 0; 19 while (wwforce(&imask) < 0) 20 ; 21 if ((imask & 1 << 0) == 0) 22 continue; 23 if (ibufc == 0) { 24 p = ibufp = ibuf; 25 n = sizeof ibuf; 26 } else { 27 p = ibufp + ibufc; 28 n = (ibuf + sizeof ibuf) - p; 29 } 30 if ((n = read(0, p, n)) > 0) { 31 ibufc += n; 32 nreadc += n; 33 } else if (n == 0) 34 nreadz++; 35 else 36 nreade++; 37 nread++; 38 } 39 } 40 41 bgets(buf, n, w) 42 char *buf; 43 int n; 44 register struct ww *w; 45 { 46 register char *p = buf; 47 register char c; 48 49 for (;;) { 50 wwcurtowin(w); 51 while ((c = bgetc()) < 0) 52 bread(); 53 if (c == wwoldtty.ww_sgttyb.sg_erase) { 54 if (p > buf) 55 rub(*--p, w); 56 else 57 wwbell(); 58 } else if (c == wwoldtty.ww_sgttyb.sg_kill) { 59 while (p > buf) 60 rub(*--p, w); 61 } else if (c == wwoldtty.ww_ltchars.t_werasc) { 62 while (--p >= buf && (*p == ' ' || *p == '\t')) 63 rub(*p, w); 64 while (p >= buf && *p != ' ' && *p != '\t') 65 rub(*p--, w); 66 p++; 67 } else if (c == '\r' || c == '\n') { 68 break; 69 } else { 70 if (p >= buf + n - 1) 71 wwbell(); 72 else 73 (void) wwputs(unctrl(*p++ = c), w); 74 } 75 } 76 *p = 0; 77 } 78 79 rub(c, w) 80 struct ww *w; 81 { 82 register i; 83 84 for (i = strlen(unctrl(c)); --i >= 0;) 85 (void) wwputs("\b \b", w); 86 } 87