2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1980, 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 static const char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93";
40 #include <sys/select.h>
53 static int keyboard_dispatch(int ch);
59 struct timeval last, intvl, now, tm;
62 /* Set initial timings */
63 gettimeofday(&last, NULL);
64 intvl.tv_sec = delay / 1000000;
65 intvl.tv_usec = delay % 1000000;
70 /* Determine interval to sleep */
71 (void)gettimeofday(&now, NULL);
72 tm.tv_sec = last.tv_sec + intvl.tv_sec - now.tv_sec;
73 tm.tv_usec = last.tv_usec + intvl.tv_usec - now.tv_usec;
74 while (tm.tv_usec < 0) {
75 tm.tv_usec += 1000000;
78 while (tm.tv_usec >= 1000000) {
79 tm.tv_usec -= 1000000;
83 /* We have to update screen immediately */
85 gettimeofday(&last, NULL);
91 FD_SET(STDIN_FILENO, &rfds);
92 n = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tm);
95 /* Read event on stdin */
98 if (keyboard_dispatch(ch) == 0) {
106 intvl.tv_sec = delay / 1000000;
107 intvl.tv_usec = delay % 1000000;
112 if (n < 0 && errno != EINTR)
115 /* Timeout or signal. Call display another time */
117 gettimeofday(&last, NULL);
123 keyboard_dispatch(int ch)
131 if (ch >= 'A' && ch <= 'Z')
134 if (ch == CTRL('l')) {
138 if (ch == CTRL('g')) {
147 if (ch == erasechar() && col > 0) {
148 if (col == 1 && line[0] == ':')
153 if (ch == CTRL('w') && col > 0) {
154 while (--col >= 0 && isspace(line[col]))
157 while (--col >= 0 && !isspace(line[col]))
158 if (col == 0 && line[0] == ':')
163 if (ch == killchar() && col > 0) {
172 if (isprint(ch) || ch == ' ') {
174 mvaddch(CMDLINE, col, ch);
178 if (col == 0 || (ch != '\r' && ch != '\n'))