date and time created 83/09/13 15:00:22 by edward
[unix-history] / usr / src / usr.bin / window / mloop.c
CommitLineData
3e02121b
EW
1#ifndef lint
2static char *sccsid = "@(#)mloop.c 3.1 83/09/02";
3#endif
4
5#include "defs.h"
6
7mloop()
8{
9 register n;
10 register char *p;
11 int imask;
12
13 while (!quit) {
14 if (!incmd && selwin->ww_state != WWS_HASPROC) {
15 incmd = 1;
16 error("Process died.");
17 }
18 if (incmd) {
19 docmd();
20 continue;
21 }
22 /*
23 * Loop until we get some keyboard input.
24 */
25 while (ibufc == 0) {
26 wwcurtowin(selwin);
27 wwupdate();
28 wwflush();
29 while (imask = 1, wwforce(&imask) < 0)
30 ;
31 if ((imask & 1) == 0)
32 continue;
33 /* NOTE: ibufc == 0 */
34 ibufp = ibuf;
35 /* may block */
36 if ((ibufc = read(0, ibuf, sizeof ibuf)) < 0) {
37 ibufc = 0;
38 nreade++;
39 } else if (ibufc == 0)
40 nreadz++;
41 else
42 nreadc += ibufc;
43 nread++;
44 }
45 /*
46 * Weird loop. Copy the buffer to the pty
47 * and stopping on the escape character
48 * in a hopefully efficient way.
49 * Probably a good thing to make ibufc == 1 a special
50 * case.
51 */
52 for (p = ibufp, n = ibufc;;) {
53 if (--n < 0) {
54 (void) write(selwin->ww_pty, ibufp, ibufc);
55 ibufp = ibuf;
56 ibufc = 0;
57 break;
58 }
59 if (*p++ == escapec) {
60 if ((n = p - ibufp) > 1)
61 (void) write(selwin->ww_pty,
62 ibufp, n - 1);
63 ibufp = p;
64 ibufc -= n;
65 incmd = 1;
66 break;
67 }
68 }
69 }
70}