updated c_help()
[unix-history] / usr / src / usr.bin / window / wwgets.c
CommitLineData
20c927a9 1#ifndef lint
14f251df 2static char *sccsid = "@(#)wwgets.c 3.1 83/08/11";
20c927a9
EW
3#endif
4
5#include "defs.h"
6
7char *ibufp = ibuf;
8
9bread()
10{
11 register n;
b4be6cd6 12 register char *p;
20c927a9
EW
13 int imask;
14
b4be6cd6 15 while (ibufc == 0) {
85af59e4 16 wwupdate();
b4be6cd6
EW
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 }
39b49130 30 if ((n = read(0, p, n)) > 0) {
b4be6cd6 31 ibufc += n;
39b49130
EW
32 nreadc += n;
33 } else if (n == 0)
34 nreadz++;
35 else
36 nreade++;
37 nread++;
b4be6cd6 38 }
20c927a9 39}
059a7be6
EW
40
41bgets(buf, n, w)
42char *buf;
43int n;
44register struct ww *w;
45{
46 register char *p = buf;
47 register char c;
48
49 for (;;) {
85af59e4 50 wwcurtowin(w);
5b912384 51 while ((c = bgetc()) < 0)
059a7be6 52 bread();
5b912384
EW
53 if (c == wwoldtty.ww_sgttyb.sg_erase) {
54 if (p > buf)
55 rub(*--p, w);
56 else
85af59e4 57 wwbell();
5b912384
EW
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') {
059a7be6 68 break;
5b912384 69 } else {
059a7be6 70 if (p >= buf + n - 1)
85af59e4 71 wwbell();
5b912384 72 else
85af59e4 73 (void) wwputs(unctrl(*p++ = c), w);
059a7be6
EW
74 }
75 }
5b912384
EW
76 *p = 0;
77}
78
79rub(c, w)
80struct ww *w;
81{
82 register i;
83
84 for (i = strlen(unctrl(c)); --i >= 0;)
85af59e4 85 (void) wwputs("\b \b", w);
059a7be6 86}