xref: /csrg-svn/usr.bin/window/mloop.c (revision 33514)
118742Sedward /*
2*33514Sbostic  * Copyright (c) 1983 Regents of the University of California.
3*33514Sbostic  * All rights reserved.
4*33514Sbostic  *
5*33514Sbostic  * Redistribution and use in source and binary forms are permitted
6*33514Sbostic  * provided that this notice is preserved and that due credit is given
7*33514Sbostic  * to the University of California at Berkeley. The name of the University
8*33514Sbostic  * may not be used to endorse or promote products derived from this
9*33514Sbostic  * software without specific prior written permission. This software
10*33514Sbostic  * is provided ``as is'' without express or implied warranty.
1118742Sedward  */
1218742Sedward 
13*33514Sbostic #ifndef lint
14*33514Sbostic static char sccsid[] = "@(#)mloop.c	3.10 (Berkeley) 02/21/88";
15*33514Sbostic #endif /* not lint */
16*33514Sbostic 
1714894Sedward #include "defs.h"
1814894Sedward 
1914894Sedward mloop()
2014894Sedward {
2117409Sedward 	wwrint();		/* catch typeahead before we set ASYNC */
2214894Sedward 	while (!quit) {
2316282Sedward 		if (incmd) {
2416124Sedward 			docmd();
2516124Sedward 		} else if (wwcurwin->ww_state != WWS_HASPROC) {
2631140Sedward 			if (!wwcurwin->ww_keepopen)
2731140Sedward 				closewin(wwcurwin);
2816282Sedward 			setcmd(1);
2916124Sedward 			if (wwpeekc() == escapec)
3016124Sedward 				(void) wwgetc();
3114894Sedward 			error("Process died.");
3216124Sedward 		} else {
3318334Sedward 			register struct ww *w = wwcurwin;
3416124Sedward 			register char *p;
3516124Sedward 			register n;
3616124Sedward 
3715872Sedward 			wwiomux();
3816124Sedward 			if (wwibp < wwibq) {
3916124Sedward 				for (p = wwibp; p < wwibq && *p != escapec;
4016124Sedward 				     p++)
4116124Sedward 					;
4216124Sedward 				if ((n = p - wwibp) > 0) {
4318334Sedward 					if (!w->ww_ispty && w->ww_stopped)
4418334Sedward 						startwin(w);
4518334Sedward 					(void) write(w->ww_pty, wwibp, n);
4616124Sedward 					wwibp = p;
4716124Sedward 				}
4816124Sedward 				if (wwpeekc() == escapec) {
4916124Sedward 					(void) wwgetc();
5016282Sedward 					setcmd(1);
5116124Sedward 				}
5214894Sedward 			}
5314894Sedward 		}
5414894Sedward 	}
5514894Sedward }
56