scrolling has come
[unix-history] / usr / src / usr.bin / window / cmd.c
index e58e9be..0dc9cd3 100644 (file)
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       1.3 83/07/20";
+static char *sccsid = "@(#)cmd.c       3.3 83/08/18";
 #endif
 
 #include "defs.h"
 
 struct ww *getwin();
 #endif
 
 #include "defs.h"
 
 struct ww *getwin();
-struct ww *openwin();
-char *strtime();
 
 docmd()
 {
        register char c;
        register struct ww *w;
 
 docmd()
 {
        register char c;
        register struct ww *w;
-       char buf;
 
 
+       if (!terse)
+               wwadd(cmdwin, &wwhead);
+       /*
+       if (selwin != 0)
+               Woncursor(selwin->ww_win, 1);
+       */
 top:
 top:
-       Wunhide(cmdwin->ww_win);
        while ((c = bgetc()) >= 0) {
        while ((c = bgetc()) >= 0) {
-               wwputs("\r\n", cmdwin);
+               if (!terse)
+                       (void) wwputs("\r\n", cmdwin);
                switch (c) {
                switch (c) {
-               case 'r':
-               case 'R':
+               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([):
-               case ESCAPE:
+               foo:
                        if (selwin == 0) {
                        if (selwin == 0) {
-                               wwputs("No window.  ", cmdwin);
+                               error("No window.");
                                continue;
                        }
                }
                switch (c) {
                case '1': case '2': case '3': case '4': case '5':
                case '6': case '7': case '8': case '9':
                                continue;
                        }
                }
                switch (c) {
                case '1': case '2': case '3': case '4': case '5':
                case '6': case '7': case '8': case '9':
-                       if ((w = wwfind(c - '0')) == 0) {
-                               Ding();
+                       if ((w = window[c - '1']) == 0) {
+                               wwbell();
                                break;
                        }
                        setselwin(w);
                        goto out;
                case '%':
                                break;
                        }
                        setselwin(w);
                        goto out;
                case '%':
-                       if ((w = getwin()) == 0)
-                               break;
-                       setselwin(w);
+                       if ((w = getwin()) != 0)
+                               setselwin(w);
                        break;
                case 'c':
                        break;
                case 'c':
+                       if ((w = getwin()) != 0)
+                               c_close(w);
+                       break;
                case 'C':
                case 'C':
-               case 'Z':
-                       doclose(c);
+                       c_close((struct ww *)0);
                        break;
                case 'w':
                        break;
                case 'w':
-                       dowindow();
+                       c_window();
                        break;
                        break;
-               case 'Q':
-                       doquery();
+               case 'S':
+                       c_show();
                        break;
                        break;
-               case 'r':
-                       selwin->ww_refresh = 0;
+               case 'L':
+                       c_list();
                        break;
                        break;
-               case 'R':
-                       selwin->ww_refresh = 1;
+               case 's':
+                       c_stat();
+                       break;
+               case 'M':
+                       wwdumpsmap();
+                       break;
+               case 'V':
+                       if ((w = getwin()) != 0)
+                               wwdumpnvis(w);
+                       break;
+               case 'D':
+                       if ((w = getwin()) != 0)
+                               wwdumpcov(w);
+                       break;
+               case 'W':
+                       if ((w = getwin()) != 0)
+                               wwdumpwin(w);
                        break;
                case 't':
                        break;
                case 't':
-                       dotime(RUSAGE_SELF);
+                       c_time(RUSAGE_SELF);
                        break;
                case 'T':
                        break;
                case 'T':
-                       dotime(RUSAGE_CHILDREN);
+                       c_time(RUSAGE_CHILDREN);
+                       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):
                        break;
                case CTRL(l):
-                       ScreenGarbaged = 1;
+                       wwredraw();
                        break;
                case '?':
                        break;
                case '?':
-                       dohelp();
+                       c_help();
                        break;
                        break;
-               case ESCAPE:
-                       buf = ESCAPE;
-                       write(selwin->ww_pty, &buf, 1);
                case CTRL([):
                        goto out;
                case CTRL(z):
                        wwsuspend();
                        break;
                case CTRL([):
                        goto out;
                case CTRL(z):
                        wwsuspend();
                        break;
-               case '.':
-                       doquit();
+               case 'q':
+                       c_quit();
                        if (quit)
                                goto out;
                        break;
                        if (quit)
                                goto out;
                        break;
+               case '.':
+                       error("Use q to quit.");
+                       break;
                default:
                default:
-                       Ding();
-                       wwprintf(cmdwin, "Type ? for help.  ");
+                       if (c == escapec) {
+                               (void) write(selwin->ww_pty, &escapec, 1);
+                               goto out;
+                       }
+                       if (!terse)
+                               wwbell();
+                       error("Type ? for help.");
                        break;
                }
        }
                        break;
                }
        }
-       wwputs("Command: ", cmdwin);
-       wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
+       if (terse)
+               wwsetcursor(0, 0);
+       else {
+               if (!terse)
+                       (void) wwputs("Command: ", cmdwin);
+               wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin));
+       }
        while (bpeekc() < 0)
                bread();
        goto top;
 out:
        while (bpeekc() < 0)
                bread();
        goto top;
 out:
-       if (!quit)
-               wwsetcurwin(selwin);
-       Whide(cmdwin->ww_win);
+       if (!quit) {
+               curwin = selwin;
+               if (!terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               }
+       }
+       /*
+       if (selwin != 0)
+               Woncursor(selwin->ww_win, 0);
+       */
 }
 
 struct ww *
 getwin()
 {
        register int c;
 }
 
 struct ww *
 getwin()
 {
        register int c;
-       struct ww *w;
+       struct ww *w = 0;
 
 
+       if (!terse)
+               (void) wwputs("Which window? ", cmdwin);
+       wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin));
        while ((c = bgetc()) < 0)
                bread();
        while ((c = bgetc()) < 0)
                bread();
-       if (c < '1' || c > '9') {
-               Ding();
-               return 0;
-       }
-       if ((w = wwfind(c - '0')) == 0)
-               Ding();
+       if (debug && c == 'c')
+               w = cmdwin;
+       else if (debug && c == 'f')
+               w = framewin;
+       else if (c >= '1' && c < NWINDOW + '1')
+               w = window[c - '1'];
+       if (w == 0)
+               wwbell();
+       if (!terse)
+               (void) wwputs("\r\n", cmdwin);
        return w;
 }
 
 setselwin(w)
 register struct ww *w;
 {
        return w;
 }
 
 setselwin(w)
 register struct ww *w;
 {
-       if (selwin)
-               labelwin(selwin, 0);
-       selwin = w;
-       if (w) {
-               labelwin(w, WINVERSE);
-               /* bring it to the top just below cmdwin */
-               wwsetcurwin(w);
-               wwsetcurwin(cmdwin);
+       register struct ww *oldselwin = selwin;
+
+       if (w == oldselwin)
+               return;
+       if (selwin = w) {
+               wwdelete(w);
+               /*
+                * Stick it in front of the old selected window,
+                * or behind everbody else.
+                */
+               wwadd(w, (oldselwin ? oldselwin : &wwhead)->ww_back);
+               /*
+               Woncursor(w->ww_win, 1);
+               */
+       }
+       /*
+       if (oldselwin) {
+               Woncursor(oldselwin->ww_win, 0);
        }
        }
+       */
+       reframe();
 }
 
 }
 
-labelwin(w, mode)
+labelwin(w)
 register struct ww *w;
 {
 register struct ww *w;
 {
-       char buf[2];
+       int mode = w == selwin ? WWM_REV : 0;
 
 
-       buf[0] = w->ww_ident + '0';
-       buf[1] = 0;
-       wwlabel(w, buf, mode);
+       if (w->ww_id >= 0) {
+               char buf[2];
+
+               buf[0] = w->ww_id + '1';
+               buf[1] = 0;
+               (void) 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;
+               (void) wwlabel(w, framewin, col, w->ww_label, mode);
+       }
 }
 }