]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwiomux.c
4bcc55905819da9594d0a84f163870236b24a76c
1 /* $NetBSD: wwiomux.c,v 1.6 1997/11/21 08:37:30 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)wwiomux.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: wwiomux.c,v 1.6 1997/11/21 08:37:30 lukem Exp $");
48 #include <sys/types.h>
49 #if !defined(OLD_TTY) && !defined(TIOCPKT_DATA)
50 #include <sys/ioctl.h>
59 * Multiple window output handler.
60 * The idea is to copy window outputs to the terminal, via the
61 * display package. We try to give wwcurwin highest priority.
62 * The only return conditions are when there is keyboard input
63 * and when a child process dies.
64 * When there's nothing to do, we sleep in a select().
65 * The history of this routine is interesting.
86 for (w
= wwhead
.ww_forw
; w
!= &wwhead
; w
= w
->ww_forw
) {
89 if (w
->ww_obq
< w
->ww_obe
) {
92 FD_SET(w
->ww_pty
, &imask
);
94 if (w
->ww_obq
> w
->ww_obp
&&
95 !ISSET(w
->ww_pflags
, WWP_STOPPED
))
106 wwcurtowin(wwcurwin
);
109 (void) setjmp(wwjmpbuf
);
124 n
= select(n
+ 1, &imask
, (fd_set
*)0, (fd_set
*)0, &tv
);
133 if (FD_ISSET(0, &imask
))
135 for (w
= wwhead
.ww_forw
; w
!= &wwhead
; w
= w
->ww_forw
) {
137 !FD_ISSET(w
->ww_pty
, &imask
))
141 if (w
->ww_type
== WWT_PTY
) {
149 n
= read(w
->ww_pty
, p
, w
->ww_obe
- p
);
152 (void) close(w
->ww_pty
);
156 (void) close(w
->ww_pty
);
158 } else if (w
->ww_type
!= WWT_PTY
) {
162 } else if (*p
== TIOCPKT_DATA
) {
169 if (*p
& TIOCPKT_STOP
)
170 SET(w
->ww_pflags
, WWP_STOPPED
);
171 if (*p
& TIOCPKT_START
)
172 CLR(w
->ww_pflags
, WWP_STOPPED
);
173 if (*p
& TIOCPKT_FLUSHWRITE
) {
174 CLR(w
->ww_pflags
, WWP_STOPPED
);
175 w
->ww_obq
= w
->ww_obp
=
182 * Try the current window first, if there is output
183 * then process it and go back to the top to try again.
184 * This can lead to starvation of the other windows,
185 * but presumably that what we want.
186 * Update will eventually happen when output from wwcurwin
189 if ((w
= wwcurwin
) != 0 && w
->ww_pty
>= 0 &&
190 w
->ww_obq
> w
->ww_obp
&&
191 !ISSET(w
->ww_pflags
, WWP_STOPPED
)) {
192 n
= wwwrite(w
, w
->ww_obp
, w
->ww_obq
- w
->ww_obp
);
193 if ((w
->ww_obp
+= n
) == w
->ww_obq
)
194 w
->ww_obq
= w
->ww_obp
= w
->ww_ob
;
198 for (w
= wwhead
.ww_forw
; w
!= &wwhead
; w
= w
->ww_forw
)
199 if (w
->ww_pty
>= 0 && w
->ww_obq
> w
->ww_obp
&&
200 !ISSET(w
->ww_pflags
, WWP_STOPPED
)) {
201 n
= wwwrite(w
, w
->ww_obp
,
202 w
->ww_obq
- w
->ww_obp
);
203 if ((w
->ww_obp
+= n
) == w
->ww_obq
)
204 w
->ww_obq
= w
->ww_obp
= w
->ww_ob
;