less -> more
[unix-history] / usr / src / usr.bin / window / wwgets.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
5e8b0e60 19static char sccsid[] = "@(#)wwgets.c 3.12 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
8fa6d94c 22#include "ww.h"
0e64e422 23#include "char.h"
20c927a9 24
8fa6d94c 25wwgets(buf, n, w)
059a7be6
EW
26char *buf;
27int n;
28register struct ww *w;
29{
30 register char *p = buf;
31 register char c;
7ecf4dca 32 char uc = w->ww_unctrl;
059a7be6 33
7ecf4dca 34 w->ww_unctrl = 0;
059a7be6 35 for (;;) {
85af59e4 36 wwcurtowin(w);
8fa6d94c
EW
37 while ((c = wwgetc()) < 0)
38 wwiomux();
5b912384
EW
39 if (c == wwoldtty.ww_sgttyb.sg_erase) {
40 if (p > buf)
41 rub(*--p, w);
5b912384
EW
42 } else if (c == wwoldtty.ww_sgttyb.sg_kill) {
43 while (p > buf)
44 rub(*--p, w);
45 } else if (c == wwoldtty.ww_ltchars.t_werasc) {
46 while (--p >= buf && (*p == ' ' || *p == '\t'))
47 rub(*p, w);
48 while (p >= buf && *p != ' ' && *p != '\t')
49 rub(*p--, w);
50 p++;
51 } else if (c == '\r' || c == '\n') {
059a7be6 52 break;
5b912384 53 } else {
059a7be6 54 if (p >= buf + n - 1)
95bc282c 55 wwputc(ctrl('g'), w);
5b912384 56 else
b1189050 57 wwputs(unctrl(*p++ = c), w);
059a7be6
EW
58 }
59 }
5b912384 60 *p = 0;
7ecf4dca 61 w->ww_unctrl = uc;
5b912384
EW
62}
63
8fa6d94c 64static
5b912384
EW
65rub(c, w)
66struct ww *w;
67{
68 register i;
69
70 for (i = strlen(unctrl(c)); --i >= 0;)
1b032f84 71 (void) wwwrite(w, "\b \b", 3);
059a7be6 72}