Got rid of 'curwin'.
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 2 Sep 1983 09:34:54 +0000 (01:34 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Fri, 2 Sep 1983 09:34:54 +0000 (01:34 -0800)
and now knows about dead processes.

SCCS-vsn: usr.bin/window/main.c 3.9
SCCS-vsn: usr.bin/window/wwchild.c 3.2
SCCS-vsn: usr.bin/window/cmd.c 3.10
SCCS-vsn: usr.bin/window/cmd2.c 3.11
SCCS-vsn: usr.bin/window/defs.h 3.4

usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/cmd2.c
usr/src/usr.bin/window/defs.h
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/wwchild.c

index 782c7c9..528c01f 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.9 83/08/31";
+static char *sccsid = "@(#)cmd.c       3.10 83/09/01";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -13,187 +13,190 @@ docmd()
                wwadd(cmdwin, &wwhead);
        if (selwin != 0)
                wwcursor(selwin, 1);
                wwadd(cmdwin, &wwhead);
        if (selwin != 0)
                wwcursor(selwin, 1);
-top:
-       while ((c = bgetc()) >= 0) {
-               if (!terse)
-                       (void) wwputs("\r\n", cmdwin);
-               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([):
-               foo:
-                       if (selwin == 0) {
-                               error("No window.");
-                               continue;
-                       }
-               }
-               switch (c) {
-               case '1': case '2': case '3': case '4': case '5':
-               case '6': case '7': case '8': case '9':
-                       if ((w = window[c - '1']) == 0) {
-                               wwbell();
+       for (;;) {
+               while ((c = bgetc()) >= 0) {
+                       if (!terse)
+                               (void) wwputs("\r\n", cmdwin);
+                       switch (c) {
+                       default:
+                               if (c == escapec)
+                                       goto foo;
                                break;
                                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([):
+                       foo:
+                               if (selwin == 0) {
+                                       error("No window.");
+                                       continue;
+                               }
                        }
                        }
-                       setselwin(w);
-                       goto out;
-               case '%':
-                       if ((w = getwin()) != 0)
+                       switch (c) {
+                       case '1': case '2': case '3': case '4': case '5':
+                       case '6': case '7': case '8': case '9':
+                               if ((w = window[c - '1']) == 0) {
+                                       wwbell();
+                                       break;
+                               }
                                setselwin(w);
                                setselwin(w);
-                       break;
-               case 'c':
-                       if ((w = getwin()) != 0)
-                               c_close(w);
-                       break;
-               case 'C':
-                       c_close((struct ww *)0);
-                       break;
-               case 'w':
-                       c_window();
-                       break;
-               case 'm':
-                       if ((w = getwin()) != 0)
-                               c_move(w);
-                       break;
-               case 'S':
-                       c_show();
-                       break;
-               case 'L':
-                       c_list();
-                       break;
-               case ':':
-                       c_colon();
-                       break;
-               case 'h':
-                       (void) wwwrite(selwin, "\b", 1);
-                       break;
-               case 'j':
-                       (void) wwwrite(selwin, "\n", 1);
-                       break;
-               case 'k':
-                       (void) wwwrite(selwin, "\033A", 2);
-                       break;
-               case 'l':
-                       (void) wwwrite(selwin, "\033C", 2);
-                       break;
-               case CTRL(e):
-                       wwscroll(selwin, 1);
-                       break;
-               case CTRL(y):
-                       wwscroll(selwin, -1);
-                       break;
-               case CTRL(d):
-                       wwscroll(selwin, selwin->ww_w.nr / 2);
-                       break;
-               case CTRL(u):
-                       wwscroll(selwin, - selwin->ww_w.nr / 2);
-                       break;
-               case CTRL(f):
-                       wwscroll(selwin, selwin->ww_w.nr);
-                       break;
-               case CTRL(b):
-                       wwscroll(selwin, - selwin->ww_w.nr);
-                       break;
-               case CTRL(s):
-                       (void) write(selwin->ww_pty,
-                               &wwwintty.ww_tchars.t_stopc, 1);
-                       break;
-               case CTRL(q):
-                       (void) write(selwin->ww_pty,
-                               &wwwintty.ww_tchars.t_startc, 1);
-                       break;
-               case CTRL(l):
-                       wwredraw();
-                       break;
-               case '?':
-                       c_help();
-                       break;
-               case CTRL([):
-                       goto out;
-               case CTRL(z):
-                       wwsuspend();
-                       break;
-               case 'q':
-                       c_quit();
-                       if (quit)
-                               goto out;
-                       break;
-               /* undocumented commands */
-               case 's':
-                       c_stat();
-                       break;
-               case 't':
-                       c_time(RUSAGE_SELF);
-                       break;
-               case 'T':
-                       c_time(RUSAGE_CHILDREN);
-                       break;
-               /* debugging commands */
-               case 'M':
-                       if (!debug)
-                               goto badcmd;
-                       wwdumpsmap();
-                       break;
-               case 'V':
-                       if (!debug)
-                               goto badcmd;
-                       if ((w = getwin()) != 0)
-                               wwdumpnvis(w);
-                       break;
-               case 'D':
-                       if (!debug)
-                               goto badcmd;
-                       if ((w = getwin()) != 0)
-                               wwdumpcov(w);
-                       break;
-               case 'W':
-                       if (!debug)
-                               goto badcmd;
-                       if ((w = getwin()) != 0)
-                               wwdumpwin(w);
-                       break;
-               default:
-               badcmd:
-                       if (c == escapec) {
-                               (void) write(selwin->ww_pty, &escapec, 1);
-                               goto out;
+                               if (checkproc(selwin) >= 0)
+                                       incmd = 0;
+                               break;
+                       case '%':
+                               if ((w = getwin()) != 0)
+                                       setselwin(w);
+                               break;
+                       case 'c':
+                               if ((w = getwin()) != 0)
+                                       c_close(w);
+                               break;
+                       case 'C':
+                               c_close((struct ww *)0);
+                               break;
+                       case 'w':
+                               c_window();
+                               break;
+                       case 'm':
+                               if ((w = getwin()) != 0)
+                                       c_move(w);
+                               break;
+                       case 'S':
+                               c_show();
+                               break;
+                       case 'L':
+                               c_list();
+                               break;
+                       case ':':
+                               c_colon();
+                               break;
+                       case 'h':
+                               (void) wwwrite(selwin, "\b", 1);
+                               break;
+                       case 'j':
+                               (void) wwwrite(selwin, "\n", 1);
+                               break;
+                       case 'k':
+                               (void) wwwrite(selwin, "\033A", 2);
+                               break;
+                       case 'l':
+                               (void) wwwrite(selwin, "\033C", 2);
+                               break;
+                       case CTRL(e):
+                               wwscroll(selwin, 1);
+                               break;
+                       case CTRL(y):
+                               wwscroll(selwin, -1);
+                               break;
+                       case CTRL(d):
+                               wwscroll(selwin, selwin->ww_w.nr / 2);
+                               break;
+                       case CTRL(u):
+                               wwscroll(selwin, - selwin->ww_w.nr / 2);
+                               break;
+                       case CTRL(f):
+                               wwscroll(selwin, selwin->ww_w.nr);
+                               break;
+                       case CTRL(b):
+                               wwscroll(selwin, - selwin->ww_w.nr);
+                               break;
+                       case CTRL(s):
+                               (void) write(selwin->ww_pty,
+                                       &wwwintty.ww_tchars.t_stopc, 1);
+                               break;
+                       case CTRL(q):
+                               (void) write(selwin->ww_pty,
+                                       &wwwintty.ww_tchars.t_startc, 1);
+                               break;
+                       case CTRL(l):
+                               wwredraw();
+                               break;
+                       case '?':
+                               c_help();
+                               break;
+                       case CTRL([):
+                               if (checkproc(selwin) >= 0)
+                                       incmd = 0;
+                               break;
+                       case CTRL(z):
+                               wwsuspend();
+                               break;
+                       case 'q':
+                               c_quit();
+                               break;
+                       /* undocumented commands */
+                       case 's':
+                               c_stat();
+                               break;
+                       case 't':
+                               c_time(RUSAGE_SELF);
+                               break;
+                       case 'T':
+                               c_time(RUSAGE_CHILDREN);
+                               break;
+                       /* debugging commands */
+                       case 'M':
+                               if (!debug)
+                                       goto badcmd;
+                               wwdumpsmap();
+                               break;
+                       case 'V':
+                               if (!debug)
+                                       goto badcmd;
+                               if ((w = getwin()) != 0)
+                                       wwdumpnvis(w);
+                               break;
+                       case 'D':
+                               if (!debug)
+                                       goto badcmd;
+                               if ((w = getwin()) != 0)
+                                       wwdumpcov(w);
+                               break;
+                       case 'W':
+                               if (!debug)
+                                       goto badcmd;
+                               if ((w = getwin()) != 0)
+                                       wwdumpwin(w);
+                               break;
+                       default:
+                       badcmd:
+                               if (c == escapec) {
+                                       if (checkproc(selwin) >= 0) {
+                                               (void) write(selwin->ww_pty,
+                                                       &escapec, 1);
+                                               incmd = 0;
+                                       }
+                               } else {
+                                       if (!terse)
+                                               wwbell();
+                                       error("Type ? for help.");
+                               }
                        }
                        }
-                       if (!terse)
-                               wwbell();
-                       error("Type ? for help.");
-                       break;
                }
                }
-       }
-       if (terse)
-               wwsetcursor(0, 0);
-       else {
-               if (!terse)
+               if (!incmd || quit)
+                       break;
+               if (terse)
+                       wwsetcursor(0, 0);
+               else {
                        (void) wwputs("Command: ", cmdwin);
                        (void) wwputs("Command: ", cmdwin);
-               wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin));
+                       wwcurtowin(cmdwin);
+               }
+               while (bpeekc() < 0)
+                       bread();
        }
        }
-       while (bpeekc() < 0)
-               bread();
-       goto top;
-out:
        if (!quit) {
        if (!quit) {
-               curwin = selwin;
                if (!terse) {
                        wwdelete(cmdwin);
                        reframe();
                }
                if (!terse) {
                        wwdelete(cmdwin);
                        reframe();
                }
-       }
-       if (selwin != 0)
                wwcursor(selwin, 0);
                wwcursor(selwin, 0);
+       }
 }
 
 struct ww *
 }
 
 struct ww *
@@ -222,6 +225,16 @@ getwin()
        return w;
 }
 
        return w;
 }
 
+checkproc(w)
+struct ww *w;
+{
+       if (w->ww_state != WWS_HASPROC) {
+               error("No process in window.");
+               return -1;
+       }
+       return 0;
+}
+
 setselwin(w)
 struct ww *w;
 {
 setselwin(w)
 struct ww *w;
 {
index d0b462d..08ce987 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd2.c      3.10 83/08/26";
+static char *sccsid = "@(#)cmd2.c      3.11 83/09/01";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -134,14 +134,15 @@ c_stat()
 
 c_list()
 {
 
 c_list()
 {
-       register struct ww *w;
+       register struct ww *w, *wp;
        register i;
        int n;
        register i;
        int n;
+       char *msg;
 
        for (n = 0, i = 0; i < NWINDOW; i++)
                if (window[i] != 0)
                        n++;
 
        for (n = 0, i = 0; i < NWINDOW; i++)
                if (window[i] != 0)
                        n++;
-       if ((w = openiwin(MAX(n, 1) + 2, "Active Windows")) == 0) {
+       if ((w = openiwin(MAX(n, 1) + 2, "Windows")) == 0) {
                error("Can't open listing window: %s.", wwerror());
                return;
        }
                error("Can't open listing window: %s.", wwerror());
                return;
        }
@@ -149,13 +150,16 @@ c_list()
                (void) wwputs("No windows.\n", w);
        } else {
                for (i = 0; i < NWINDOW; i++) {
                (void) wwputs("No windows.\n", w);
        } else {
                for (i = 0; i < NWINDOW; i++) {
-                       if (window[i] == 0)
+                       if ((wp = window[i]) == 0)
                                continue;
                                continue;
-                       (void) wwprintf(w, "%c %c   %s\n",
-                               window[i] == selwin ? '*' : ' ',
+                       (void) wwprintf(w, "%c %c %-13s %-.*s\n",
+                               wp == selwin ? '*' : ' ',
                                i + '1',
                                i + '1',
-                               window[i]->ww_label ? window[i]->ww_label
-                                       : "(No label)");
+                               wp->ww_state == WWS_HASPROC
+                                       ? "" : "(No process)",
+                               wwncol - 20,
+                               wp->ww_label
+                                       ? wp->ww_label : "(No label)");
                }
        }
        waitnl(w);
                }
        }
        waitnl(w);
index e9579fc..0b8236c 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)defs.h      3.3 83/08/25    
+ *     @(#)defs.h      3.4 83/09/01    
  */
 
 #include "ww.h"
  */
 
 #include "ww.h"
@@ -28,7 +28,6 @@ struct ww *selwin;            /* the selected window */
 struct ww *cmdwin;             /* the command window */
 struct ww *framewin;           /* the window for framing */
 struct ww *boxwin;             /* the window for the box */
 struct ww *cmdwin;             /* the command window */
 struct ww *framewin;           /* the window for framing */
 struct ww *boxwin;             /* the window for the box */
-struct ww *curwin;             /* the current window */
 
 char *shell;                   /* the shell program */
 char *shellname;               /* the shell program name (for argv[0]) */
 
 char *shell;                   /* the shell program */
 char *shellname;               /* the shell program name (for argv[0]) */
@@ -39,6 +38,7 @@ int nbufline;                 /* number of lines in the buffer */
 char quit;
 char terse;
 char debug;
 char quit;
 char terse;
 char debug;
+char incmd;                    /* in command mode */
 char escapec;                  /* escape character */
 
 struct ww *getwin();
 char escapec;                  /* escape character */
 
 struct ww *getwin();
index 8087fe8..5d493ba 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      3.8 83/08/26";
+static char *sccsid = "@(#)main.c      3.9 83/09/01";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -92,7 +92,6 @@ char **argv;
                goto bad;
        }
 
                goto bad;
        }
 
-       curwin = cmdwin;
        wwupdate();
        wwflush();
        (void) signal(SIGCHLD, wwchild);
        wwupdate();
        wwflush();
        (void) signal(SIGCHLD, wwchild);
@@ -102,7 +101,7 @@ char **argv;
                if (dflag || doconfig() < 0)
                        dodefault();
                if (selwin != 0) {
                if (dflag || doconfig() < 0)
                        dodefault();
                if (selwin != 0) {
-                       curwin = selwin;
+                       incmd = 0;
                        wwcursor(selwin, 0);
                }
                if (!terse) {
                        wwcursor(selwin, 0);
                }
                if (!terse) {
@@ -111,7 +110,7 @@ char **argv;
                }
        }
        while (!quit) {
                }
        }
        while (!quit) {
-               if (curwin == cmdwin) {
+               if (incmd) {
                        docmd();
                        continue;
                }
                        docmd();
                        continue;
                }
@@ -119,7 +118,7 @@ char **argv;
                 * Loop until we get some keyboard input.
                 */
                while (ibufc == 0) {
                 * Loop until we get some keyboard input.
                 */
                while (ibufc == 0) {
-                       wwcurtowin(curwin);
+                       wwcurtowin(selwin);
                        wwupdate();
                        wwflush();
                        while (imask = 1, wwforce(&imask) < 0)
                        wwupdate();
                        wwflush();
                        while (imask = 1, wwforce(&imask) < 0)
@@ -146,17 +145,17 @@ char **argv;
                 */
                for (p = ibufp, n = ibufc;;) {
                        if (--n < 0) {
                 */
                for (p = ibufp, n = ibufc;;) {
                        if (--n < 0) {
-                               (void) write(curwin->ww_pty, ibufp, ibufc);
+                               (void) write(selwin->ww_pty, ibufp, ibufc);
                                ibufp = ibuf;
                                ibufc = 0;
                                break;
                        } else if (*p++ == escapec) {
                                if ((n = p - ibufp) > 1)
                                ibufp = ibuf;
                                ibufc = 0;
                                break;
                        } else if (*p++ == escapec) {
                                if ((n = p - ibufp) > 1)
-                                       (void) write(curwin->ww_pty,
+                                       (void) write(selwin->ww_pty,
                                                ibufp, n - 1);
                                ibufp = p;
                                ibufc -= n;
                                                ibufp, n - 1);
                                ibufp = p;
                                ibufc -= n;
-                               curwin = cmdwin;
+                               incmd = 1;
                                break;
                        }
                }
                                break;
                        }
                }
index 1db4dd0..066ba2b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwchild.c   3.1 83/08/11";
+static char *sccsid = "@(#)wwchild.c   3.2 83/09/01";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -16,16 +16,8 @@ wwchild()
                        if (*wp && (*wp)->ww_state == WWS_HASPROC
                            && (*wp)->ww_pid == pid) {
                                (*wp)->ww_state = WWS_DEAD;
                        if (*wp && (*wp)->ww_state == WWS_HASPROC
                            && (*wp)->ww_pid == pid) {
                                (*wp)->ww_state = WWS_DEAD;
-                               /*
-                               (void) wwprintf(curwin,
-                                       "\r\n%d: Died\r\n", pid);
-                               */
                                break;
                        }
                }
                                break;
                        }
                }
-               /*
-               if (wp >= &wwindex[NWW])
-                       (void) wwprintf(curwin, "\r\n%d: No such child\r\n", pid);
-               */
        }
 }
        }
 }