fix contrib notice (Edward Wang)
[unix-history] / usr / src / usr.bin / window / win.c
index 2c45548..5dc3a0d 100644 (file)
@@ -1,9 +1,22 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Edward Wang at The University of California, Berkeley.
+ *
+ * %sccs.include.redist.c%
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)win.c      3.11 %G%";
-#endif
+static char sccsid[] = "@(#)win.c      3.24 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 #include "char.h"
 
 #include "defs.h"
 #include "char.h"
+#ifdef POSIX_TTY
+#include <sys/ioctl.h>
+#endif
 
 /*
  * Higher level routines for dealing with windows.
 
 /*
  * Higher level routines for dealing with windows.
@@ -47,8 +60,7 @@ char *shf, **sh;
        w->ww_id = id;
        window[id] = w;
        w->ww_hasframe = hasframe;
        w->ww_id = id;
        window[id] = w;
        w->ww_hasframe = hasframe;
-       w->ww_altpos.r = 1;
-       w->ww_altpos.c = 0;
+       w->ww_alt = w->ww_w;
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
        if (label != 0 && setlabel(w, label) < 0)
                error("No memory for label.");
        wwcursor(w, 1);
@@ -60,11 +72,9 @@ char *shf, **sh;
        setselwin((struct ww *)0);
        addwin(w, 0);
        setselwin(w);
        setselwin((struct ww *)0);
        addwin(w, 0);
        setselwin(w);
-       wwupdate();
-       wwflush();
        if (wwspawn(w, shf, sh) < 0) {
                error("Can't execute %s: %s.", shf, wwerror());
        if (wwspawn(w, shf, sh) < 0) {
                error("Can't execute %s: %s.", shf, wwerror());
-               c_close(w);
+               closewin(w);
                return 0;
        }
        return w;
                return 0;
        }
        return w;
@@ -83,23 +93,51 @@ findid()
        return i;
 }
 
        return i;
 }
 
+struct ww *
+findselwin()
+{
+       register struct ww *w, *s = 0;
+       register i;
+
+       for (i = 0; i < NWINDOW; i++)
+               if ((w = window[i]) != 0 && w != selwin &&
+                   (s == 0 ||
+                    !isfg(w) && (w->ww_order < s->ww_order || isfg(s))))
+                       s = w;
+       return s;
+}
+
 /*
 /*
- * Close a user window.
- * May leave selwin == 0.
+ * Close a user window.  Close all if w == 0.
  */
 closewin(w)
 register struct ww *w;
 {
  */
 closewin(w)
 register struct ww *w;
 {
-       if (w == selwin)
-               selwin = 0;
-       if (w == lastselwin)
-               lastselwin = 0;
-       if (w->ww_id >= 0 && w->ww_id < NWINDOW)
-               window[w->ww_id] = 0;
-       if (w->ww_label)
-               str_free(w->ww_label);
-       deletewin(w);
-       wwclose(w);
+       char didit = 0;
+       register i;
+
+       if (w != 0) {
+               closewin1(w);
+               didit++;
+       } else
+               for (i = 0; i < NWINDOW; i++) {
+                       if ((w = window[i]) == 0)
+                               continue;
+                       closewin1(w);
+                       didit++;
+               }
+       if (didit) {
+               if (selwin == 0)
+                       if (lastselwin != 0) {
+                               setselwin(lastselwin);
+                               lastselwin = 0;
+                       } else if (w = findselwin())
+                               setselwin(w);
+               if (lastselwin == 0 && selwin)
+                       if (w = findselwin())
+                               lastselwin = w;
+               reframe();
+       }
 }
 
 /*
 }
 
 /*
@@ -123,7 +161,6 @@ char *label;
        (void) setlabel(w, label);
        addwin(w, 1);
        reframe();
        (void) setlabel(w, label);
        addwin(w, 1);
        reframe();
-       wwupdate();
        return w;
 }
 
        return w;
 }
 
@@ -133,10 +170,25 @@ char *label;
 closeiwin(w)
 struct ww *w;
 {
 closeiwin(w)
 struct ww *w;
 {
-       closewin(w);
+       closewin1(w);
        reframe();
 }
 
        reframe();
 }
 
+closewin1(w)
+register struct ww *w;
+{
+       if (w == selwin)
+               selwin = 0;
+       if (w == lastselwin)
+               lastselwin = 0;
+       if (w->ww_id >= 0 && w->ww_id < NWINDOW)
+               window[w->ww_id] = 0;
+       if (w->ww_label)
+               str_free(w->ww_label);
+       deletewin(w);
+       wwclose(w);
+}
+
 /*
  * Move the window to the top of its group.
  * Don't do it if already fully visible.
 /*
  * Move the window to the top of its group.
  * Don't do it if already fully visible.
@@ -223,6 +275,36 @@ register struct ww *w;
        }
 }
 
        }
 }
 
+stopwin(w)
+       register struct ww *w;
+{
+       w->ww_stopped = 1;
+       if (w->ww_pty >= 0 && w->ww_ispty)
+               (void) ioctl(w->ww_pty, TIOCSTOP, (char *)0);
+}
+
+startwin(w)
+       register struct ww *w;
+{
+       w->ww_stopped = 0;
+       if (w->ww_pty >= 0 && w->ww_ispty)
+               (void) ioctl(w->ww_pty, TIOCSTART, (char *)0);
+}
+
+sizewin(w, nrow, ncol)
+register struct ww *w;
+{
+       struct ww *back = w->ww_back;
+
+       w->ww_alt.nr = w->ww_w.nr;
+       w->ww_alt.nc = w->ww_w.nc;
+       wwdelete(w);
+       if (wwsize(w, nrow, ncol) < 0)
+               error("Can't resize window: %s.", wwerror());
+       wwadd(w, back);
+       reframe();
+}
+
 waitnl(w)
 struct ww *w;
 {
 waitnl(w)
 struct ww *w;
 {
@@ -242,7 +324,7 @@ char always;
        w->ww_unctrl = 0;
        wwputs("\033E", w);
        w->ww_unctrl = uc;
        w->ww_unctrl = 0;
        wwputs("\033E", w);
        w->ww_unctrl = uc;
-       return c == ctrl([) ? 2 : 1;
+       return c == ctrl('[') ? 2 : 1;
 }
 
 waitnl1(w, prompt)
 }
 
 waitnl1(w, prompt)
@@ -253,7 +335,7 @@ char *prompt;
 
        w->ww_unctrl = 0;
        front(w, 0);
 
        w->ww_unctrl = 0;
        front(w, 0);
-       wwprintf(w, "\033Y%c%c\033p%s\033q ",
+       wwprintf(w, "\033Y%c%c\033sA%s\033rA ",
                w->ww_w.nr - 1 + ' ', ' ', prompt);     /* print on last line */
        wwcurtowin(w);
        while (wwpeekc() < 0)
                w->ww_w.nr - 1 + ' ', ' ', prompt);     /* print on last line */
        wwcurtowin(w);
        while (wwpeekc() < 0)