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