last few day's work
[unix-history] / usr / src / usr.bin / window / main.c
index 462888e..25a2420 100644 (file)
@@ -1,59 +1,98 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)main.c      1.8 83/07/28";
+static char *sccsid = "@(#)main.c      3.1 83/08/11";
 #endif
 
 #include "defs.h"
 
 #endif
 
 #include "defs.h"
 
-char escapec = CTRL(l);
+char escapec = CTRL(p);
 
 
-#define next(a) (**(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
+#define next(a) (*++*(a) ? *(a) : (*++(a) ? *(a) : (char *)usage()))
 
 
-/*ARGUSED*/
+/*ARGSUSED*/
 main(argc, argv)
 char **argv;
 {
        register n;
        register char *p;
 main(argc, argv)
 char **argv;
 {
        register n;
        register char *p;
-       int wwchild();
+       char fast = 0;
        int imask;
        int imask;
+       struct timezone timezone;
 
 
+       if (p = rindex(*argv, '/'))
+               p++;
+       else
+               p = *argv;
+       debug = strcmp(p, "a.out") == 0;
        while (*++argv) {
                if (**argv == '-') {
                        switch (*++*argv) {
        while (*++argv) {
                if (**argv == '-') {
                        switch (*++*argv) {
+                       case 'f':
+                               fast++;
+                               break;
                        case 'e':
                                setescape(next(argv));
                                break;
                        case 't':
                                terse++;
                                break;
                        case 'e':
                                setescape(next(argv));
                                break;
                        case 't':
                                terse++;
                                break;
+                       case 'd':
+                               debug++;
+                               break;
                        default:
                        default:
-                               usage();
+                               (void) usage();
                        }
                } else
                        }
                } else
-                       usage();
+                       (void) usage();
        }
        }
-       gettimeofday(&starttime, &timezone);
+       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;
        }
-       if (terse)
-               Whide(cmdwin->ww_win);
-       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();
@@ -63,8 +102,8 @@ char **argv;
                 * 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)
@@ -83,28 +122,31 @@ char **argv;
                        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;
                        } else if (*p++ == escapec) {
                                if ((n = p - ibufp) > 1)
                                ibufp = ibuf;
                                ibufc = 0;
                                break;
                        } else if (*p++ == escapec) {
                                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;
@@ -112,6 +154,7 @@ bad:
 
 usage()
 {
 
 usage()
 {
-       fprintf(stderr, "window: [-e escape] [-t]\n");
+       (void) fprintf(stderr, "window: [-e escape] [-t] [-f]\n");
        exit(1);
        exit(1);
+       return 0;                       /* for lint */
 }
 }