Commit | Line | Data |
---|---|---|
20c927a9 | 1 | #ifndef lint |
60de5df9 | 2 | static char sccsid[] = "@(#)wwgets.c 3.9 %G%"; |
20c927a9 EW |
3 | #endif |
4 | ||
60de5df9 EW |
5 | /* |
6 | * Copyright (c) 1983 Regents of the University of California, | |
7 | * All rights reserved. Redistribution permitted subject to | |
8 | * the terms of the Berkeley Software License Agreement. | |
9 | */ | |
10 | ||
8fa6d94c | 11 | #include "ww.h" |
0e64e422 | 12 | #include "char.h" |
20c927a9 | 13 | |
8fa6d94c | 14 | wwgets(buf, n, w) |
059a7be6 EW |
15 | char *buf; |
16 | int n; | |
17 | register struct ww *w; | |
18 | { | |
19 | register char *p = buf; | |
20 | register char c; | |
7ecf4dca | 21 | char uc = w->ww_unctrl; |
059a7be6 | 22 | |
7ecf4dca | 23 | w->ww_unctrl = 0; |
059a7be6 | 24 | for (;;) { |
85af59e4 | 25 | wwcurtowin(w); |
8fa6d94c EW |
26 | while ((c = wwgetc()) < 0) |
27 | wwiomux(); | |
5b912384 EW |
28 | if (c == wwoldtty.ww_sgttyb.sg_erase) { |
29 | if (p > buf) | |
30 | rub(*--p, w); | |
5b912384 EW |
31 | } else if (c == wwoldtty.ww_sgttyb.sg_kill) { |
32 | while (p > buf) | |
33 | rub(*--p, w); | |
34 | } else if (c == wwoldtty.ww_ltchars.t_werasc) { | |
35 | while (--p >= buf && (*p == ' ' || *p == '\t')) | |
36 | rub(*p, w); | |
37 | while (p >= buf && *p != ' ' && *p != '\t') | |
38 | rub(*p--, w); | |
39 | p++; | |
40 | } else if (c == '\r' || c == '\n') { | |
059a7be6 | 41 | break; |
5b912384 | 42 | } else { |
059a7be6 | 43 | if (p >= buf + n - 1) |
0e64e422 | 44 | wwputc(ctrl(g), w); |
5b912384 | 45 | else |
b1189050 | 46 | wwputs(unctrl(*p++ = c), w); |
059a7be6 EW |
47 | } |
48 | } | |
5b912384 | 49 | *p = 0; |
7ecf4dca | 50 | w->ww_unctrl = uc; |
5b912384 EW |
51 | } |
52 | ||
8fa6d94c | 53 | static |
5b912384 EW |
54 | rub(c, w) |
55 | struct ww *w; | |
56 | { | |
57 | register i; | |
58 | ||
59 | for (i = strlen(unctrl(c)); --i >= 0;) | |
1b032f84 | 60 | (void) wwwrite(w, "\b \b", 3); |
059a7be6 | 61 | } |