Commit | Line | Data |
---|---|---|
fc38b21b | 1 | #ifndef lint |
b4be6cd6 | 2 | static char *sccsid = "@(#)main.c 1.4 83/07/19"; |
fc38b21b EW |
3 | #endif |
4 | ||
2b44d852 | 5 | #include "defs.h" |
fc38b21b EW |
6 | |
7 | main() | |
8 | { | |
9 | register n; | |
10 | register char *p; | |
11 | int wwchild(); | |
12 | int imask; | |
fc38b21b | 13 | |
2b44d852 | 14 | gettimeofday(&starttime, &timezone); |
4711df8b EW |
15 | if (wwinit() < 0) { |
16 | fflush(stdout); | |
17 | fprintf("Can't do windows on this terminal.\n"); | |
18 | exit(1); | |
19 | } | |
2b44d852 | 20 | if ((cmdwin = wwopen(1, 0, 1, WCols, 0, 0)) == 0) { |
4711df8b | 21 | fflush(stdout); |
2b44d852 | 22 | fprintf(stderr, "Can't open command window.\r\n"); |
4711df8b EW |
23 | goto bad; |
24 | } | |
2b44d852 EW |
25 | wwsetcurrent(cmdwin); |
26 | for (n = 0; n < WCols; n++) | |
27 | Waputc(0, WINVERSE|WBUF, cmdwin->ww_win); | |
28 | wwflush(); | |
fc38b21b | 29 | (void) signal(SIGCHLD, wwchild); |
2b44d852 EW |
30 | while (!quit) { |
31 | if (curwin == cmdwin) { | |
32 | docmd(); | |
4711df8b | 33 | continue; |
2b44d852 | 34 | } |
b4be6cd6 EW |
35 | /* |
36 | * Loop until we get some keyboard input. | |
37 | */ | |
2b44d852 EW |
38 | while (ibufc == 0) { |
39 | wwsetcursor(WCurRow(curwin->ww_win), | |
40 | WCurCol(curwin->ww_win)); | |
41 | wwflush(); | |
b4be6cd6 EW |
42 | imask = 1 << 0; |
43 | while (wwforce(&imask) < 0) | |
44 | ; | |
45 | if ((imask & 1 << 0) == 0) | |
4711df8b | 46 | continue; |
b4be6cd6 EW |
47 | /* NOTE: ibufc == 0 */ |
48 | ibufp = ibuf; | |
49 | if ((ibufc = read(0, ibuf, sizeof ibuf)) < 0) | |
50 | ibufc = 0; | |
2b44d852 | 51 | } |
b4be6cd6 EW |
52 | /* |
53 | * Weird loop. Copy the buffer to the pty stopping | |
54 | * on the escape character in a hopefully efficient | |
55 | * way. | |
56 | * Probably a good thing to make ibufc == 1 a special | |
57 | * case. | |
58 | */ | |
59 | for (p = ibufp, n = ibufc;;) { | |
60 | if (--n < 0) { | |
61 | write(curwin->ww_pty, ibufp, ibufc); | |
62 | ibufp = ibuf; | |
63 | ibufc = 0; | |
64 | break; | |
65 | } else if (*p++ == ESCAPE) { | |
66 | if ((n = p - ibufp) > 1) | |
67 | write(curwin->ww_pty, ibufp, n - 1); | |
68 | ibufp = p; | |
69 | ibufc -= n; | |
70 | wwsetcurrent(cmdwin); | |
71 | break; | |
72 | } | |
fc38b21b EW |
73 | } |
74 | } | |
75 | bad: | |
fc38b21b EW |
76 | wwend(); |
77 | return 0; | |
78 | } |