bgets()
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 29 Jul 1983 04:09:41 +0000 (20:09 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 29 Jul 1983 04:09:41 +0000 (20:09 -0800)
SCCS-vsn: usr.bin/window/wwgets.c 1.5

usr/src/usr.bin/window/wwgets.c

index 30e1800..4397f6d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwgets.c    1.4 83/07/27";
+static char *sccsid = "@(#)wwgets.c    1.5 83/07/28";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -36,3 +36,40 @@ bread()
                nread++;
        }
 }
                nread++;
        }
 }
+
+bgets(buf, n, w)
+char *buf;
+int n;
+register struct ww *w;
+{
+       register char *p = buf;
+       register char c;
+
+       for (;;) {
+               wwsetcursor(WCurRow(w->ww_win), WCurCol(w->ww_win));
+               while ((c = bpeekc()) < 0)
+                       bread();
+               switch (c) {
+               case '\b':
+                       if (p > buf) {
+                               wwputs("\b \b", w);
+                               p--;
+                               if (ISCTRL(*p))
+                                       wwputs("\b \b", w);
+                       } else
+                               Ding();
+                       break;
+               case '\r':
+               case '\n':
+                       *p = 0;
+                       return;
+               default:
+                       if (p >= buf + n - 1)
+                               Ding();
+                       else {
+                               *p++ = c;
+                               wwputs(unctrl(*p), w);
+                       }
+               }
+       }
+}