do case insensitive comparison on domain name
[unix-history] / usr / src / usr.bin / window / cmd.c
index d7e3dc0..6e685da 100644 (file)
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       1.9 83/07/28";
-#endif
+static char sccsid[] = "@(#)cmd.c      3.38 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 
 #include "defs.h"
-
-struct ww *getwin();
+#include "char.h"
 
 docmd()
 {
        register char c;
        register struct ww *w;
 
 docmd()
 {
        register char c;
        register struct ww *w;
+       char out = 0;
 
 
-       if (!terse)
-               Wunhide(cmdwin->ww_win);
-       if (selwin != 0)
-               Woncursor(selwin->ww_win, 1);
-top:
-       while ((c = bgetc()) >= 0) {
+       while (!out && !quit) {
+               if ((c = wwgetc()) < 0) {
+                       if (terse)
+                               wwsetcursor(0, 0);
+                       else {
+                               wwputs("Command: ", cmdwin);
+                               wwcurtowin(cmdwin);
+                       }
+                       do
+                               wwiomux();
+                       while ((c = wwgetc()) < 0);
+               }
                if (!terse)
                if (!terse)
-                       wwputs("\r\n", cmdwin);
+                       wwputc('\n', cmdwin);
                switch (c) {
                default:
                switch (c) {
                default:
-                       if (c == escapec)
-                               goto foo;
-                       break;
+                       if (c != escapec)
+                               break;
                case 'h': case 'j': case 'k': case 'l':
                case 'h': case 'j': case 'k': case 'l':
-               case CTRL(u):
-               case CTRL(d):
-               case CTRL(b):
-               case CTRL(f):
-               case CTRL([):
-               foo:
+               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('['):
                        if (selwin == 0) {
                        if (selwin == 0) {
-                               if (terse)
-                                       Ding();
-                               else
-                                       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) {
+                               error("%c: No such window.", c);
                                break;
                        }
                        setselwin(w);
                                break;
                        }
                        setselwin(w);
-                       goto out;
+                       if (checkproc(selwin) >= 0)
+                                out = 1;
+                       break;
                case '%':
                        if ((w = getwin()) != 0)
                                setselwin(w);
                        break;
                case '%':
                        if ((w = getwin()) != 0)
                                setselwin(w);
                        break;
+               case ctrl('^'):
+                       if (lastselwin != 0) {
+                               setselwin(lastselwin);
+                               if (checkproc(selwin) >= 0)
+                                       out = 1;
+                       } else
+                               error("No previous window.");
+                       break;
                case 'c':
                        if ((w = getwin()) != 0)
                case 'c':
                        if ((w = getwin()) != 0)
-                               doclose(w);
-                       break;
-               case 'C':
-                       doclose((struct ww *)0);
-                       break;
-               case 'Z':
-                       if (terse)
-                               Ding();
-                       else
-                               wwputs("Command Z is now C.  ", cmdwin);
+                               closewin(w);
                        break;
                case 'w':
                        break;
                case 'w':
-                       dowindow();
-                       break;
-               case 'S':
-                       doshow();
-                       break;
-               case 'L':
-                       dolist();
+                       c_window();
                        break;
                        break;
-               /*
-               case 'e':
-                       doescape();
-                       break;
-               case 'L':
-                       dolabel();
-                       break;
-               case 'r':
-                       selwin->ww_refresh = 0;
+               case 'm':
+                       if ((w = getwin()) != 0)
+                               c_move(w);
                        break;
                        break;
-               case 'R':
-                       selwin->ww_refresh = 1;
+               case 'M':
+                       if ((w = getwin()) != 0)
+                               movewin(w, w->ww_alt.t, w->ww_alt.l);
                        break;
                        break;
-               */
                case 's':
                case 's':
-                       dostat();
-                       break;
-               case 't':
-                       dotime(RUSAGE_SELF);
+                       if ((w = getwin()) != 0)
+                               c_size(w);
                        break;
                        break;
-               case 'T':
-                       dotime(RUSAGE_CHILDREN);
+               case 'S':
+                       if ((w = getwin()) != 0)
+                               sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                        break;
                case ':':
                        break;
                case ':':
-                       docolon();
+                       c_colon();
                        break;
                case 'h':
                        break;
                case 'h':
-                       Wcurleft(selwin->ww_win, 1);
+                       (void) wwwrite(selwin, "\b", 1);
                        break;
                case 'j':
                        break;
                case 'j':
-                       Wcurdown(selwin->ww_win, 1);
+                       (void) wwwrite(selwin, "\n", 1);
                        break;
                case 'k':
                        break;
                case 'k':
-                       Wcurup(selwin->ww_win, 1);
+                       (void) wwwrite(selwin, "\033A", 2);
                        break;
                case 'l':
                        break;
                case 'l':
-                       Wcurright(selwin->ww_win, 1);
+                       (void) wwwrite(selwin, "\033C", 2);
+                       break;
+               case ctrl('e'):
+                       wwscroll(selwin, 1);
                        break;
                        break;
-               case CTRL(d):
-                       doscroll(1);
+               case ctrl('y'):
+                       wwscroll(selwin, -1);
                        break;
                        break;
-               case CTRL(u):
-                       doscroll(-1);
+               case ctrl('d'):
+                       wwscroll(selwin, selwin->ww_w.nr / 2);
                        break;
                        break;
-               case CTRL(f):
-                       doscroll(2);
+               case ctrl('u'):
+                       wwscroll(selwin, - selwin->ww_w.nr / 2);
                        break;
                        break;
-               case CTRL(b):
-                       doscroll(-2);
+               case ctrl('f'):
+                       wwscroll(selwin, selwin->ww_w.nr);
                        break;
                        break;
-               case CTRL(l):
-                       ScreenGarbaged = 1;
+               case ctrl('b'):
+                       wwscroll(selwin, - selwin->ww_w.nr);
+                       break;
+               case ctrl('s'):
+                       stopwin(selwin);
+                       break;
+               case ctrl('q'):
+                       startwin(selwin);
+                       break;
+               case ctrl('l'):
+                       wwredraw();
                        break;
                case '?':
                        break;
                case '?':
-                       dohelp();
+                       c_help();
+                       break;
+               case ctrl('['):
+                       if (checkproc(selwin) >= 0)
+                               out = 1;
                        break;
                        break;
-               case CTRL([):
-                       goto out;
-               case CTRL(z):
+               case ctrl('z'):
                        wwsuspend();
                        break;
                case 'q':
                        wwsuspend();
                        break;
                case 'q':
-                       doquit();
-                       if (quit)
-                               goto out;
-                       break;
-               case '.':
-                       if (terse)
-                               Ding();
-                       else
-                               wwputs("Use q to quit.  ", cmdwin);
+                       c_quit();
                        break;
                        break;
+               /* debugging stuff */
+               case '&':
+                       if (debug) {
+                               c_debug();
+                               break;
+                       }
                default:
                        if (c == escapec) {
                default:
                        if (c == escapec) {
-                               write(selwin->ww_pty, &escapec, 1);
-                               goto out;
+                               if (checkproc(selwin) >= 0) {
+                                       (void) write(selwin->ww_pty,
+                                               &escapec, 1);
+                                       out = 1;
+                               }
+                       } else {
+                               if (!terse)
+                                       wwbell();
+                               error("Type ? for help.");
                        }
                        }
-                       Ding();
-                       if (!terse)
-                               wwprintf(cmdwin, "Type ? for help.  ");
-                       break;
                }
        }
                }
        }
-       if (terse)
-               wwsetcursor(0, 0);
-       else {
-               if (!terse)
-                       wwputs("Command: ", cmdwin);
-               wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
-       }
-       while (bpeekc() < 0)
-               bread();
-       goto top;
-out:
        if (!quit)
        if (!quit)
-               wwsetcurwin(selwin);
-       if (selwin != 0)
-               Woncursor(selwin->ww_win, 0);
-       if (!terse)
-               Whide(cmdwin->ww_win);
+               setcmd(0);
 }
 
 struct ww *
 }
 
 struct ww *
@@ -184,45 +194,81 @@ getwin()
 
        if (!terse)
                wwputs("Which window? ", cmdwin);
 
        if (!terse)
                wwputs("Which window? ", cmdwin);
-       wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
-       while ((c = bgetc()) < 0)
-               bread();
-       if (c < '1' || c > '9' || (w = wwfind(c - '0')) == 0)
-               Ding();
+       wwcurtowin(cmdwin);
+       while ((c = wwgetc()) < 0)
+               wwiomux();
+       if (debug && c == 'c')
+               w = cmdwin;
+       else if (debug && c == 'f')
+               w = framewin;
+       else if (debug && c == 'b')
+               w = boxwin;
+       else if (c >= '1' && c < NWINDOW + '1')
+               w = window[c - '1'];
+       else if (c == '+')
+               w = selwin;
+       else if (c == '-')
+               w = lastselwin;
+       if (w == 0)
+               wwbell();
        if (!terse)
        if (!terse)
-               wwputs("\r\n", cmdwin);
+               wwputc('\n', cmdwin);
        return w;
 }
 
        return w;
 }
 
-setselwin(w)
-register struct ww *w;
+checkproc(w)
+struct ww *w;
 {
 {
-       struct ww *oldselwin = selwin;
-
-       if (w == oldselwin)
-               return;
-       if (selwin = w) {
-               labelwin(w);
-               /* bring it to the top just below cmdwin */
-               wwsetcurwin(w);
-               wwsetcurwin(cmdwin);
-               Woncursor(w->ww_win, 1);
+       if (w->ww_state != WWS_HASPROC) {
+               error("No process in window.");
+               return -1;
        }
        }
-       if (oldselwin) {
-               labelwin(oldselwin);
-               Woncursor(oldselwin->ww_win, 0);
+       return 0;
+}
+
+setcmd(new)
+char new;
+{
+       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;
 }
 
 }
 
-labelwin(w)
-register struct ww *w;
+setterse(new)
+char new;
 {
 {
-       char buf[2];
-       int mode = w == selwin ? WINVERSE : 0;
+       if (incmd)
+               if (new && !terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               } else if (!new && terse)
+                       wwadd(cmdwin, &wwhead);
+       terse = new;
+}
 
 
-       buf[0] = w->ww_ident + '0';
-       buf[1] = 0;
-       wwlabel(w, 1, buf, mode);
-       if (w->ww_label)
-               wwlabel(w, 3, w->ww_label, mode);
+/*
+ * Set the current window.
+ */
+setselwin(w)
+struct ww *w;
+{
+       if (selwin == w)
+               return;
+       if (selwin != 0)
+               lastselwin = selwin;
+       if ((selwin = w) != 0)
+               front(selwin, 1);
 }
 }