4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
47 * Routine to check to see if any input is waiting.
48 * It returns a 1 if there is input waiting, and a zero if
49 * no input is waiting.
51 * This function replaces system calls to ioctl() with the FIONREAD
52 * parameter. It enables curses to stop a screen refresh whenever
53 * a character is input.
54 * Standard BTL UNIX 4.0 or 5.0 does not handle FIONREAD.
55 * Changes have been made to 'wrefresh.c' to
56 * call this routine as "_inputpending = chkinput()".
57 * (delay.c and getch.c also use FIONREAD for nodelay, select and fast peek,
58 * but these routines have not been changed).
60 * Philip N. Crusius - July 20, 1983
61 * Modified to handle various systems March 9, 1984 by Mark Horton.
65 #include <sys/types.h>
66 #include "curses_inc.h"
76 ioctl(SP
->check_fd
, FIONREAD
, &i
);
88 int ifds
, ofds
, efds
, n
;
91 ifds
= 1 << SP
->check_fd
;
93 tv
.tv_sec
= tv
.t_usec
= 0;
94 n
= select(20, &ifds
, &ofds
, &efds
, &tv
);
106 unsigned char c
; /* character input */
109 * Only check typeahead if the user is using our input
110 * routines. This is because the read below will put
111 * stuff into the inputQ that will never be read and the
112 * screen will never get updated from now on.
113 * This code should GO AWAY when a poll() or FIONREAD can
114 * be done on the file descriptor as then the check
115 * will be non-destructive.
118 if (!cur_term
->fl_typeahdok
||
119 (cur_term
->_chars_on_queue
== INP_QSIZE
) ||
120 (cur_term
->_check_fd
< 0)) {
124 /* If input is waiting in curses queue, return (TRUE). */
126 if ((int)cur_term
->_chars_on_queue
> 0) {
129 (void) fprintf(outf
, "Found a character on the input "
137 if (read(cur_term
->_check_fd
, (char *)&c
, 1) > 0) {
140 (void) fprintf(outf
, "Reading ahead\n");
144 * A character was waiting. Put it at the end
145 * of the curses queue and return 1 to show that
152 cur_term
->_input_queue
[cur_term
->_chars_on_queue
++] = c
;
156 /* No input was waiting so return 0. */
159 (void) fprintf(outf
, "No input waiting\n");
172 #endif /* HAVE_CHK */
176 _print_queue() /* FOR DEBUG ONLY */
178 int i
, j
= cur_term
->_chars_on_queue
;
179 chtype
*inputQ
= cur_term
->_input_queue
;
182 for (i
= 0; i
< j
; i
++)
183 (void) fprintf(outf
, "inputQ[%d] = %c\n", i
, inputQ
[i
]);