xref: /original-bsd/usr.bin/window/mloop.c (revision 1403a0cd)
1 #ifndef lint
2 static char sccsid[] = "@(#)mloop.c	3.8 04/24/85";
3 #endif
4 
5 /*
6  * Copyright (c) 1983 Regents of the University of California,
7  * All rights reserved.  Redistribution permitted subject to
8  * the terms of the Berkeley Software License Agreement.
9  */
10 
11 #include "defs.h"
12 
13 mloop()
14 {
15 	wwrint();		/* catch typeahead before we set ASYNC */
16 	while (!quit) {
17 		if (incmd) {
18 			docmd();
19 		} else if (wwcurwin->ww_state != WWS_HASPROC) {
20 			setcmd(1);
21 			if (wwpeekc() == escapec)
22 				(void) wwgetc();
23 			error("Process died.");
24 		} else {
25 			register struct ww *w = wwcurwin;
26 			register char *p;
27 			register n;
28 
29 			wwiomux();
30 			if (wwibp < wwibq) {
31 				for (p = wwibp; p < wwibq && *p != escapec;
32 				     p++)
33 					;
34 				if ((n = p - wwibp) > 0) {
35 					if (!w->ww_ispty && w->ww_stopped)
36 						startwin(w);
37 					(void) write(w->ww_pty, wwibp, n);
38 					wwibp = p;
39 				}
40 				if (wwpeekc() == escapec) {
41 					(void) wwgetc();
42 					setcmd(1);
43 				}
44 			}
45 		}
46 	}
47 }
48