new commands s and S. also better way to stop window output
[unix-history] / usr / src / usr.bin / window / cmd.c
index 450d928..90adf2c 100644 (file)
@@ -1,37 +1,35 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.17 83/12/02";
+static char sccsid[] = "@(#)cmd.c      3.31 %G%";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
+#include "char.h"
 
 docmd()
 {
        register char c;
        register struct ww *w;
 
 docmd()
 {
        register char c;
        register struct ww *w;
+       char out = 0;
 
 
-       if (!terse)
-               wwadd(cmdwin, &wwhead);
-       if (selwin != 0)
-               wwcursor(selwin, 1);
        for (;;) {
        for (;;) {
-               while ((c = bgetc()) >= 0) {
+               while ((c = wwgetc()) >= 0) {
                        if (!terse)
                        if (!terse)
-                               (void) wwputs("\r\n", cmdwin);
+                               wwputc('\n', cmdwin);
                        switch (c) {
                        default:
                                if (c == escapec)
                                        goto foo;
                                break;
                        case 'h': case 'j': case 'k': case 'l':
                        switch (c) {
                        default:
                                if (c == escapec)
                                        goto foo;
                                break;
                        case 'h': case 'j': case 'k': case 'l':
-                       case CTRL(y):
-                       case CTRL(e):
-                       case CTRL(u):
-                       case CTRL(d):
-                       case CTRL(b):
-                       case CTRL(f):
-                       case CTRL(s):
-                       case CTRL(q):
-                       case CTRL([):
+                       case ctrl(y):
+                       case ctrl(e):
+                       case ctrl(u):
+                       case ctrl(d):
+                       case ctrl(b):
+                       case ctrl(f):
+                       case ctrl(s):
+                       case ctrl(q):
+                       case ctrl([):
                        foo:
                                if (selwin == 0) {
                                        error("No window.");
                        foo:
                                if (selwin == 0) {
                                        error("No window.");
@@ -47,17 +45,17 @@ docmd()
                                }
                                setselwin(w);
                                if (checkproc(selwin) >= 0)
                                }
                                setselwin(w);
                                if (checkproc(selwin) >= 0)
-                                       incmd = 0;
+                                        out = 1;
                                break;
                        case '%':
                                if ((w = getwin()) != 0)
                                        setselwin(w);
                                break;
                                break;
                        case '%':
                                if ((w = getwin()) != 0)
                                        setselwin(w);
                                break;
-                       case CTRL(^):
+                       case ctrl(^):
                                if (lastselwin != 0) {
                                        setselwin(lastselwin);
                                        if (checkproc(selwin) >= 0)
                                if (lastselwin != 0) {
                                        setselwin(lastselwin);
                                        if (checkproc(selwin) >= 0)
-                                               incmd = 0;
+                                               out = 1;
                                } else
                                        error("No previous window.");
                                break;
                                } else
                                        error("No previous window.");
                                break;
@@ -65,9 +63,6 @@ docmd()
                                if ((w = getwin()) != 0)
                                        c_close(w);
                                break;
                                if ((w = getwin()) != 0)
                                        c_close(w);
                                break;
-                       case 'C':
-                               c_close((struct ww *)0);
-                               break;
                        case 'w':
                                c_window();
                                break;
                        case 'w':
                                c_window();
                                break;
@@ -77,14 +72,15 @@ docmd()
                                break;
                        case 'M':
                                if ((w = getwin()) != 0)
                                break;
                        case 'M':
                                if ((w = getwin()) != 0)
-                                       movewin(w, w->ww_altpos.r,
-                                               w->ww_altpos.c);
+                                       movewin(w, w->ww_alt.t, w->ww_alt.l);
                                break;
                                break;
-                       case 'S':
-                               c_show();
+                       case 's':
+                               if ((w = getwin()) != 0)
+                                       c_size(w);
                                break;
                                break;
-                       case 'L':
-                               c_list();
+                       case 'S':
+                               if ((w = getwin()) != 0)
+                                       sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                                break;
                        case ':':
                                c_colon();
                                break;
                        case ':':
                                c_colon();
@@ -101,60 +97,63 @@ docmd()
                        case 'l':
                                (void) wwwrite(selwin, "\033C", 2);
                                break;
                        case 'l':
                                (void) wwwrite(selwin, "\033C", 2);
                                break;
-                       case CTRL(e):
+                       case ctrl(e):
                                wwscroll(selwin, 1);
                                break;
                                wwscroll(selwin, 1);
                                break;
-                       case CTRL(y):
+                       case ctrl(y):
                                wwscroll(selwin, -1);
                                break;
                                wwscroll(selwin, -1);
                                break;
-                       case CTRL(d):
+                       case ctrl(d):
                                wwscroll(selwin, selwin->ww_w.nr / 2);
                                break;
                                wwscroll(selwin, selwin->ww_w.nr / 2);
                                break;
-                       case CTRL(u):
+                       case ctrl(u):
                                wwscroll(selwin, - selwin->ww_w.nr / 2);
                                break;
                                wwscroll(selwin, - selwin->ww_w.nr / 2);
                                break;
-                       case CTRL(f):
+                       case ctrl(f):
                                wwscroll(selwin, selwin->ww_w.nr);
                                break;
                                wwscroll(selwin, selwin->ww_w.nr);
                                break;
-                       case CTRL(b):
+                       case ctrl(b):
                                wwscroll(selwin, - selwin->ww_w.nr);
                                break;
                                wwscroll(selwin, - selwin->ww_w.nr);
                                break;
-                       case CTRL(s):
-                               (void) write(selwin->ww_pty,
-                                       &wwwintty.ww_tchars.t_stopc, 1);
+                       case ctrl(s):
+                               if (selwin->ww_pty < 0)
+                                       break;
+                               if (selwin->ww_ispty) {
+                                       (void) ioctl(selwin->ww_pty, TIOCSTOP,
+                                               (char *)0);
+                                       selwin->ww_stopped = 1;
+                               } else
+                                       (void) write(selwin->ww_pty,
+                                               &wwwintty.ww_tchars.t_stopc, 1);
                                break;
                                break;
-                       case CTRL(q):
-                               (void) write(selwin->ww_pty,
-                                       &wwwintty.ww_tchars.t_startc, 1);
+                       case ctrl(q):
+                               if (selwin->ww_pty < 0)
+                                       break;
+                               if (selwin->ww_ispty) {
+                                       (void) ioctl(selwin->ww_pty, TIOCSTART,
+                                               (char *)0);
+                                       selwin->ww_stopped = 0;
+                               } else
+                                       (void) write(selwin->ww_pty,
+                                               &wwwintty.ww_tchars.t_startc,
+                                               1);
                                break;
                                break;
-                       case CTRL(l):
+                       case ctrl(l):
                                wwredraw();
                                break;
                        case '?':
                                c_help();
                                break;
                                wwredraw();
                                break;
                        case '?':
                                c_help();
                                break;
-                       case CTRL([):
+                       case ctrl([):
                                if (checkproc(selwin) >= 0)
                                if (checkproc(selwin) >= 0)
-                                       incmd = 0;
+                                       out = 1;
                                break;
                                break;
-                       case CTRL(z):
+                       case ctrl(z):
                                wwsuspend();
                                break;
                        case 'q':
                                c_quit();
                                break;
                                wwsuspend();
                                break;
                        case 'q':
                                c_quit();
                                break;
-                       /* undocumented commands */
-                       case 's':
-                               c_stat();
-                               break;
-#ifndef O_4_1A
-                       case 't':
-                               c_time(RUSAGE_SELF);
-                               break;
-                       case 'T':
-                               c_time(RUSAGE_CHILDREN);
-                               break;
-#endif
                        /* debugging stuff */
                        case '&':
                                if (debug) {
                        /* debugging stuff */
                        case '&':
                                if (debug) {
@@ -166,7 +165,7 @@ docmd()
                                        if (checkproc(selwin) >= 0) {
                                                (void) write(selwin->ww_pty,
                                                        &escapec, 1);
                                        if (checkproc(selwin) >= 0) {
                                                (void) write(selwin->ww_pty,
                                                        &escapec, 1);
-                                               incmd = 0;
+                                               out = 1;
                                        }
                                } else {
                                        if (!terse)
                                        }
                                } else {
                                        if (!terse)
@@ -175,24 +174,19 @@ docmd()
                                }
                        }
                }
                                }
                        }
                }
-               if (!incmd || quit)
+               if (out || quit)
                        break;
                if (terse)
                        wwsetcursor(0, 0);
                else {
                        break;
                if (terse)
                        wwsetcursor(0, 0);
                else {
-                       (void) wwputs("Command: ", cmdwin);
+                       wwputs("Command: ", cmdwin);
                        wwcurtowin(cmdwin);
                }
                        wwcurtowin(cmdwin);
                }
-               while (bpeekc() < 0)
-                       bread();
-       }
-       if (!quit) {
-               if (!terse) {
-                       wwdelete(cmdwin);
-                       reframe();
-               }
-               wwcursor(selwin, 0);
+               while (wwpeekc() < 0)
+                       wwiomux();
        }
        }
+       if (!quit)
+               setcmd(0);
 }
 
 struct ww *
 }
 
 struct ww *
@@ -202,10 +196,10 @@ getwin()
        struct ww *w = 0;
 
        if (!terse)
        struct ww *w = 0;
 
        if (!terse)
-               (void) wwputs("Which window? ", cmdwin);
+               wwputs("Which window? ", cmdwin);
        wwcurtowin(cmdwin);
        wwcurtowin(cmdwin);
-       while ((c = bgetc()) < 0)
-               bread();
+       while ((c = wwgetc()) < 0)
+               wwiomux();
        if (debug && c == 'c')
                w = cmdwin;
        else if (debug && c == 'f')
        if (debug && c == 'c')
                w = cmdwin;
        else if (debug && c == 'f')
@@ -217,7 +211,7 @@ getwin()
        if (w == 0)
                wwbell();
        if (!terse)
        if (w == 0)
                wwbell();
        if (!terse)
-               (void) wwputs("\r\n", cmdwin);
+               wwputc('\n', cmdwin);
        return w;
 }
 
        return w;
 }
 
@@ -231,60 +225,49 @@ struct ww *w;
        return 0;
 }
 
        return 0;
 }
 
-setselwin(w)
-struct ww *w;
+setcmd(new)
+char new;
 {
 {
-       lastselwin = selwin;
-       front(selwin = w, 1);
-}
-
-/*
- * wwvisible() doesn't work for tinted windows.
- * But anything to make it faster.
- */
-front(w, doreframe)
-register struct ww *w;
-{
-       if (!wwvisible(w) && w->ww_back != framewin) {
-               wwdelete(w);
-               wwadd(w, framewin);
-               reframe();
-       } else if (doreframe)
-               reframe();
+       if (new && !incmd) {
+               if (!terse)
+                       wwadd(cmdwin, &wwhead);
+               if (selwin != 0)
+                       wwcursor(selwin, 1);
+               wwcurwin = 0;
+       } else if (!new && incmd) {
+               if (!terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               }
+               if (selwin != 0)
+                       wwcursor(selwin, 0);
+               wwcurwin = selwin;
+       }
+       incmd = new;
 }
 
 }
 
-reframe()
+setterse(new)
+char new;
 {
 {
-       register struct ww *w;
-
-       wwunframe(framewin);
-       for (w = wwhead.ww_back; w != &wwhead; w = w->ww_back)
-               if (w->ww_hasframe) {
-                       wwframe(w, framewin);
-                       labelwin(w);
-               }
+       if (incmd)
+               if (new && !terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               } else if (!new && terse)
+                       wwadd(cmdwin, &wwhead);
+       terse = new;
 }
 
 }
 
-labelwin(w)
-register struct ww *w;
+/*
+ * Set the current window.
+ */
+setselwin(w)
+struct ww *w;
 {
 {
-       int mode = w == selwin ? WWM_REV : 0;
-
-       if (w->ww_id >= 0) {
-               char buf[2];
-
-               buf[0] = w->ww_id + '1';
-               buf[1] = 0;
-               wwlabel(w, framewin, 1, buf, mode);
-       }
-       if (w->ww_label) {
-               int col;
-
-               if (w->ww_center) {
-                       col = (w->ww_w.nc - strlen(w->ww_label)) / 2;
-                       col = MAX(3, col);
-               } else
-                       col = 3;
-               wwlabel(w, framewin, col, w->ww_label, mode);
-       }
+       if (selwin == w)
+               return;
+       if (selwin != 0)
+               lastselwin = selwin;
+       if ((selwin = w) != 0)
+               front(selwin, 1);
 }
 }