1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
7 *
8 * %sccs.include.redist.c%
9 */
10
11 #ifndef lint
12 static char sccsid[] = "@(#)wwgets.c 8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14
15 #include "ww.h"
16 #include "char.h"
17
wwgets(buf,n,w)18 wwgets(buf, n, w)
19 char *buf;
20 int n;
21 register struct ww *w;
22 {
23 register char *p = buf;
24 register char c;
25 char uc = w->ww_unctrl;
26 static void rub();
27
28 w->ww_unctrl = 0;
29 for (;;) {
30 wwcurtowin(w);
31 while ((c = wwgetc()) < 0)
32 wwiomux();
33 #ifdef OLD_TTY
34 if (c == wwoldtty.ww_sgttyb.sg_erase)
35 #else
36 if (c == wwoldtty.ww_termios.c_cc[VERASE])
37 #endif
38 {
39 if (p > buf)
40 rub(*--p, w);
41 } else
42 #ifdef OLD_TTY
43 if (c == wwoldtty.ww_sgttyb.sg_kill)
44 #else
45 if (c == wwoldtty.ww_termios.c_cc[VKILL])
46 #endif
47 {
48 while (p > buf)
49 rub(*--p, w);
50 } else
51 #ifdef OLD_TTY
52 if (c == wwoldtty.ww_ltchars.t_werasc)
53 #else
54 if (c == wwoldtty.ww_termios.c_cc[VWERASE])
55 #endif
56 {
57 while (--p >= buf && (*p == ' ' || *p == '\t'))
58 rub(*p, w);
59 while (p >= buf && *p != ' ' && *p != '\t')
60 rub(*p--, w);
61 p++;
62 } else if (c == '\r' || c == '\n') {
63 break;
64 } else {
65 if (p >= buf + n - 1)
66 wwputc(ctrl('g'), w);
67 else
68 wwputs(unctrl(*p++ = c), w);
69 }
70 }
71 *p = 0;
72 w->ww_unctrl = uc;
73 }
74
75 static void
rub(c,w)76 rub(c, w)
77 struct ww *w;
78 {
79 register i;
80
81 for (i = strlen(unctrl(c)); --i >= 0;)
82 (void) wwwrite(w, "\b \b", 3);
83 }
84