last few day's work
[unix-history] / usr / src / usr.bin / window / main.c
index a35214a..25a2420 100644 (file)
@@ -1,36 +1,98 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      1.7 83/07/27";
+static char *sccsid = "@(#)main.c      3.1 83/08/11";
 #endif
 
 #include "defs.h"
 
 #endif
 
 #include "defs.h"
 
-main()
+char escapec = CTRL(p);
+
+#define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
+
+/*ARGSUSED*/
+main(argc, argv)
+char **argv;
 {
        register n;
        register char *p;
 {
        register n;
        register char *p;
-       int wwchild();
+       char fast = 0;
        int imask;
        int imask;
+       struct timezone timezone;
 
 
-       gettimeofday(&starttime, &timezone);
+       if (p = rindex(*argv, '/'))
+               p++;
+       else
+               p = *argv;
+       debug = strcmp(p, "a.out") == 0;
+       while (*++argv) {
+               if (**argv == '-') {
+                       switch (*++*argv) {
+                       case 'f':
+                               fast++;
+                               break;
+                       case 'e':
+                               setescape(next(argv));
+                               break;
+                       case 't':
+                               terse++;
+                               break;
+                       case 'd':
+                               debug++;
+                               break;
+                       default:
+                               (void) usage();
+                       }
+               } else
+                       (void) usage();
+       }
+       if ((shell = getenv("SHELL")) == 0)
+               shell = "/bin/csh";
+       if (shellname = rindex(shell, '/'))
+               shellname++;
+       else
+               shellname = shell;
+       (void) gettimeofday(&starttime, &timezone);
        if (wwinit() < 0) {
        if (wwinit() < 0) {
-               fflush(stdout);
-               fprintf("Can't do windows on this terminal.\n");
+               (void) fflush(stdout);
+               (void) fprintf(stderr, "Can't do windows on this terminal.\n");
                exit(1);
        }
                exit(1);
        }
-       if ((cmdwin = wwopen(WW_NONE, 0, 1, wwncol, 0, 0)) == 0) {
-               fflush(stdout);
-               fprintf(stderr, "Can't open command window.\r\n");
+       if (debug) {
+               wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
+               (void) wwsettty(0, &wwnewtty);
+       }
+
+       if ((cmdwin = wwopen(WWO_REVERSE, 1, wwncol, 0, 0, 0)) == 0) {
+               (void) wwflush();
+               (void) fprintf(stderr, "Can't open command window.\r\n");
+               goto bad;
+       }
+       if ((framewin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
+               (void) wwflush();
+               (void) fprintf(stderr, "Can't open frame window.\r\n");
                goto bad;
        }
                goto bad;
        }
-       wwsetcurwin(cmdwin);
-       for (n = 0; n < wwncol; n++)                    /* XXX */
-               Waputc(0, WINVERSE|WBUF, cmdwin->ww_win);
+       wwadd(framewin, &wwhead);
+
+       curwin = cmdwin;
+       wwupdate();
        wwflush();
        (void) signal(SIGCHLD, wwchild);
        wwflush();
        (void) signal(SIGCHLD, wwchild);
-       if (doconfig() < 0)
-               dodefault();
-       if (selwin != 0)
-               wwsetcurwin(selwin);
+       if (!fast) {
+               if (!terse)
+                       wwadd(cmdwin, &wwhead);
+               if (doconfig() < 0)
+                       dodefault();
+               if (selwin != 0) {
+                       curwin = selwin;
+                       /*
+                       Woncursor(selwin->ww_win, 0);
+                       */
+               }
+               if (!terse) {
+                       wwdelete(cmdwin);
+                       reframe();
+               }
+       }
        while (!quit) {
                if (curwin == cmdwin) {
                        docmd();
        while (!quit) {
                if (curwin == cmdwin) {
                        docmd();
@@ -40,8 +102,8 @@ main()
                 * Loop until we get some keyboard input.
                 */
                while (ibufc == 0) {
                 * Loop until we get some keyboard input.
                 */
                while (ibufc == 0) {
-                       wwsetcursor(WCurRow(curwin->ww_win),
-                               WCurCol(curwin->ww_win));
+                       wwcurtowin(curwin);
+                       wwupdate();
                        wwflush();
                        imask = 1 << 0;
                        while (wwforce(&imask) < 0)
                        wwflush();
                        imask = 1 << 0;
                        while (wwforce(&imask) < 0)
@@ -60,29 +122,39 @@ main()
                        nread++;
                }
                /*
                        nread++;
                }
                /*
-                * Weird loop.  Copy the buffer to the pty stopping
-                * on the escape character in a hopefully efficient
-                * way.
+                * Weird loop.  Copy the buffer to the pty
+                * and stopping on the escape character
+                * in a hopefully efficient way.
                 * Probably a good thing to make ibufc == 1 a special
                 * case.
                 */
                for (p = ibufp, n = ibufc;;) {
                        if (--n < 0) {
                 * Probably a good thing to make ibufc == 1 a special
                 * case.
                 */
                for (p = ibufp, n = ibufc;;) {
                        if (--n < 0) {
-                               write(curwin->ww_pty, ibufp, ibufc);
+                               (void) write(curwin->ww_pty, ibufp, ibufc);
                                ibufp = ibuf;
                                ibufc = 0;
                                break;
                                ibufp = ibuf;
                                ibufc = 0;
                                break;
-                       } else if (*p++ == ESCAPE) {
+                       } else if (*p++ == escapec) {
                                if ((n = p - ibufp) > 1)
                                if ((n = p - ibufp) > 1)
-                                       write(curwin->ww_pty, ibufp, n - 1);
+                                       (void) write(curwin->ww_pty,
+                                               ibufp, n - 1);
                                ibufp = p;
                                ibufc -= n;
                                ibufp = p;
                                ibufc -= n;
-                               wwsetcurwin(cmdwin);
+                               curwin = cmdwin;
                                break;
                        }
                }
        }
                                break;
                        }
                }
        }
+       wwupdate();
+       wwflush();
 bad:
        wwend();
        return 0;
 }
 bad:
        wwend();
        return 0;
 }
+
+usage()
+{
+       (void) fprintf(stderr, "window: [-e escape] [-t] [-f]\n");
+       exit(1);
+       return 0;                       /* for lint */
+}