mapnl option to window
[unix-history] / usr / src / usr.bin / window / mloop.c
index 8a7864d..1e2886e 100644 (file)
@@ -1,49 +1,37 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)mloop.c     3.2 84/01/16";
+static char sccsid[] = "@(#)mloop.c    3.5 %G%";
 #endif
 
 #include "defs.h"
 
 mloop()
 {
 #endif
 
 #include "defs.h"
 
 mloop()
 {
-       register n;
-       register char *p;
-       int imask;
-
        while (!quit) {
        while (!quit) {
-               if (!incmd && selwin->ww_state != WWS_HASPROC) {
-                       incmd = 1;
-                       error("Process died.");
-               }
                if (incmd) {
                        docmd();
                if (incmd) {
                        docmd();
-                       continue;
-               }
-               while (wwibc == 0) {
-                       wwcurtowin(selwin);
+               } else if (wwcurwin->ww_state != WWS_HASPROC) {
+                       setcmd(1);
+                       if (wwpeekc() == escapec)
+                               (void) wwgetc();
+                       error("Process died.");
+               } else {
+                       register char *p;
+                       register n;
+
                        wwiomux();
                        wwiomux();
-               }
-               /*
-                * 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 wwibc == 1 a special
-                * case.
-                */
-               for (p = wwibp, n = wwibc;;) {
-                       if (--n < 0) {
-                               (void) write(selwin->ww_pty, wwibp, wwibc);
-                               wwibc = 0;
-                               break;
-                       }
-                       if (*p++ == escapec) {
-                               if ((n = p - wwibp) > 1)
-                                       (void) write(selwin->ww_pty,
-                                               wwibp, n - 1);
-                               wwibp = p;
-                               wwibc -= n;
-                               incmd = 1;
-                               break;
+                       if (wwibp < wwibq) {
+                               for (p = wwibp; p < wwibq && *p != escapec;
+                                    p++)
+                                       ;
+                               if ((n = p - wwibp) > 0) {
+                                       (void) write(wwcurwin->ww_pty,
+                                               wwibp, n);
+                                       wwibp = p;
+                               }
+                               if (wwpeekc() == escapec) {
+                                       (void) wwgetc();
+                                       setcmd(1);
+                               }
                        }
                }
        }
                        }
                }
        }