do case insensitive comparison on domain name
[unix-history] / usr / src / usr.bin / window / cmd.c
index c4bf534..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.5 83/07/22";
-#endif
+static char sccsid[] = "@(#)cmd.c      3.38 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "defs.h"
 
 #include "defs.h"
-
-struct ww *getwin();
-struct ww *openwin();
-char *strtime();
+#include "char.h"
 
 docmd()
 {
        register char c;
        register struct ww *w;
 
 docmd()
 {
        register char c;
        register struct ww *w;
-       char buf;
+       char out = 0;
 
 
-top:
-       Wunhide(cmdwin->ww_win);
-       if (selwin != 0)
-               Woncursor(selwin->ww_win, 1);
-       while ((c = bgetc()) >= 0) {
-               wwputs("\r\n", cmdwin);
+       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)
+                       wwputc('\n', cmdwin);
                switch (c) {
                switch (c) {
-               case 'r':
-               case 'R':
+               default:
+                       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([):
-               case ESCAPE:
+               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) {
-                               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;
-               case '%':
-                       if ((w = getwin()) == 0)
-                               break;
-                       setselwin(w);
+                       if (checkproc(selwin) >= 0)
+                                out = 1;
                        break;
                        break;
-               case 'c':
-                       doclose(CLOSE_ONE, getwin());
+               case '%':
+                       if ((w = getwin()) != 0)
+                               setselwin(w);
                        break;
                        break;
-               case 'C':
-                       doclose(CLOSE_DEAD, (struct ww *)0);
+               case ctrl('^'):
+                       if (lastselwin != 0) {
+                               setselwin(lastselwin);
+                               if (checkproc(selwin) >= 0)
+                                       out = 1;
+                       } else
+                               error("No previous window.");
                        break;
                        break;
-               case 'Z':
-                       doclose(CLOSE_ALL, (struct ww *)0);
+               case 'c':
+                       if ((w = getwin()) != 0)
+                               closewin(w);
                        break;
                case 'w':
                        break;
                case 'w':
-                       dowindow();
-                       break;
-               case 'Q':
-                       doquery();
+                       c_window();
                        break;
                        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;
                case 's':
                        break;
                case 's':
-                       dostat();
+                       if ((w = getwin()) != 0)
+                               c_size(w);
                        break;
                        break;
-               case 't':
-                       dotime(RUSAGE_SELF);
+               case 'S':
+                       if ((w = getwin()) != 0)
+                               sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
                        break;
                        break;
-               case 'T':
-                       dotime(RUSAGE_CHILDREN);
+               case ':':
+                       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;
+               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;
                        break;
-               case CTRL(d):
-                       doscroll(1);
+               case ctrl('f'):
+                       wwscroll(selwin, selwin->ww_w.nr);
                        break;
                        break;
-               case CTRL(u):
-                       doscroll(-1);
+               case ctrl('b'):
+                       wwscroll(selwin, - selwin->ww_w.nr);
                        break;
                        break;
-               case CTRL(f):
-                       doscroll(2);
+               case ctrl('s'):
+                       stopwin(selwin);
                        break;
                        break;
-               case CTRL(b):
-                       doscroll(-2);
+               case ctrl('q'):
+                       startwin(selwin);
                        break;
                        break;
-               case CTRL(l):
-                       ScreenGarbaged = 1;
+               case ctrl('l'):
+                       wwredraw();
                        break;
                case '?':
                        break;
                case '?':
-                       dohelp();
-                       break;
-               case ESCAPE:
-                       buf = ESCAPE;
-                       write(selwin->ww_pty, &buf, 1);
-               case CTRL([):
-                       goto out;
-               case CTRL(z):
+                       c_help();
+                       break;
+               case ctrl('['):
+                       if (checkproc(selwin) >= 0)
+                               out = 1;
+                       break;
+               case ctrl('z'):
                        wwsuspend();
                        break;
                        wwsuspend();
                        break;
-               case '.':
-                       doquit();
-                       if (quit)
-                               goto out;
+               case 'q':
+                       c_quit();
                        break;
                        break;
+               /* debugging stuff */
+               case '&':
+                       if (debug) {
+                               c_debug();
+                               break;
+                       }
                default:
                default:
-                       Ding();
-                       wwprintf(cmdwin, "Type ? for help.  ");
-                       break;
+                       if (c == escapec) {
+                               if (checkproc(selwin) >= 0) {
+                                       (void) write(selwin->ww_pty,
+                                               &escapec, 1);
+                                       out = 1;
+                               }
+                       } else {
+                               if (!terse)
+                                       wwbell();
+                               error("Type ? for help.");
+                       }
                }
        }
                }
        }
-       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);
-       Whide(cmdwin->ww_win);
+               setcmd(0);
 }
 
 struct ww *
 getwin()
 {
        register int c;
 }
 
 struct ww *
 getwin()
 {
        register int c;
-       struct ww *w;
+       struct ww *w = 0;
 
 
-       while ((c = bgetc()) < 0)
-               bread();
-       if (c < '1' || c > '9') {
-               Ding();
-               return 0;
-       }
-       if ((w = wwfind(c - '0')) == 0)
-               Ding();
+       if (!terse)
+               wwputs("Which window? ", cmdwin);
+       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)
+               wwputc('\n', cmdwin);
        return w;
 }
 
        return w;
 }
 
-setselwin(w)
-register struct ww *w;
+checkproc(w)
+struct ww *w;
 {
 {
-       if (selwin) {
-               labelwin(selwin, 0);
-               Woncursor(selwin->ww_win, 0);
+       if (w->ww_state != WWS_HASPROC) {
+               error("No process in window.");
+               return -1;
        }
        }
-       if (selwin = w) {
-               labelwin(w, WINVERSE);
-               /* bring it to the top just below cmdwin */
-               wwsetcurwin(w);
-               wwsetcurwin(cmdwin);
-               Woncursor(w->ww_win, 1);
+       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, mode)
-register struct ww *w;
+setterse(new)
+char new;
 {
 {
-       char buf[2];
+       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, buf, 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);
 }
 }