xref: /original-bsd/usr.bin/window/wwrint.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)wwrint.c	8.1 (Berkeley) 06/06/93";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 #include "tt.h"
17 #if defined(OLD_TTY) || defined(VMIN_BUG)
18 #include <fcntl.h>
19 #endif
20 
21 /*
22  * Tty input interrupt handler.
23  * (1) Read input into buffer (wwib*).
24  * (2) Set the interrupt flag if anything is read.
25  * Currently, the last is used to get out of the blocking
26  * select() in wwiomux().
27  * To avoid race conditions, we only modify wwibq in here, except
28  * when the buffer is empty; and everywhere else, we only change wwibp.
29  * It should be completely safe.
30  */
31 void
32 wwrint()
33 {
34 	register n;
35 
36 	if (wwibp == wwibq)
37 		wwibp = wwibq = wwib;
38 	wwnread++;
39 #if defined(OLD_TTY) || defined(VMIN_BUG)
40 	/* we have set c_cc[VMIN] to 0 */
41 	(void) fcntl(0, F_SETFL, O_NONBLOCK|wwnewtty.ww_fflags);
42 #endif
43 	n = read(0, wwibq, wwibe - wwibq);
44 #if defined(OLD_TTY) || defined(VMIN_BUG)
45 	(void) fcntl(0, F_SETFL, wwnewtty.ww_fflags);
46 #endif
47 	if (n > 0) {
48 		if (tt.tt_rint)
49 			n = (*tt.tt_rint)(wwibq, n);
50 		if (n > 0) {
51 			wwibq += n;
52 			wwnreadc += n;
53 			/*
54 			 * Hasten or delay the next checkpoint,
55 			 * as the case may be.
56 			 */
57 			if (tt.tt_checkpoint && !wwdocheckpoint)
58 				(void) alarm(1);
59 			wwsetintr();
60 		}
61 	} else if (n == 0)
62 		wwnreadz++;
63 	else
64 		wwnreade++;
65 }
66