xref: /original-bsd/usr.bin/window/mloop.c (revision cd18b70b)
1 #ifndef lint
2 static char sccsid[] = "@(#)mloop.c	3.9 05/18/87";
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 			if (!wwcurwin->ww_keepopen)
21 				closewin(wwcurwin);
22 			setcmd(1);
23 			if (wwpeekc() == escapec)
24 				(void) wwgetc();
25 			error("Process died.");
26 		} else {
27 			register struct ww *w = wwcurwin;
28 			register char *p;
29 			register n;
30 
31 			wwiomux();
32 			if (wwibp < wwibq) {
33 				for (p = wwibp; p < wwibq && *p != escapec;
34 				     p++)
35 					;
36 				if ((n = p - wwibp) > 0) {
37 					if (!w->ww_ispty && w->ww_stopped)
38 						startwin(w);
39 					(void) write(w->ww_pty, wwibp, n);
40 					wwibp = p;
41 				}
42 				if (wwpeekc() == escapec) {
43 					(void) wwgetc();
44 					setcmd(1);
45 				}
46 			}
47 		}
48 	}
49 }
50