Annotation of src/usr.bin/systat/keyboard.c, Revision 1.11
1.11 ! deraadt 1: /* $OpenBSD: keyboard.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $ */
1.1 deraadt 2: /* $NetBSD: keyboard.c,v 1.2 1995/01/20 08:51:59 jtc Exp $ */
3:
4: /*-
5: * Copyright (c) 1980, 1992, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the University of
19: * California, Berkeley and its contributors.
20: * 4. Neither the name of the University nor the names of its contributors
21: * may be used to endorse or promote products derived from this software
22: * without specific prior written permission.
23: *
24: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34: * SUCH DAMAGE.
35: */
36:
37: #ifndef lint
38: #if 0
39: static char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93";
40: #endif
1.11 ! deraadt 41: static char rcsid[] = "$OpenBSD: keyboard.c,v 1.10 2001/12/07 09:18:08 deraadt Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include <ctype.h>
45: #include <signal.h>
46: #include <termios.h>
1.10 deraadt 47: #include <errno.h>
1.1 deraadt 48:
49: #include "systat.h"
50: #include "extern.h"
51:
1.4 kstailey 52: void
1.1 deraadt 53: keyboard()
54: {
1.11 ! deraadt 55: char line[80];
1.7 millert 56: sigset_t mask, omask;
1.11 ! deraadt 57: int ch;
1.1 deraadt 58:
1.10 deraadt 59: for (;;) {
60: col = 0;
61: move(CMDLINE, 0);
62: do {
63: if (gotdisplay) {
64: display();
65: gotdisplay = 0;
66: }
67: if (gotdie) {
68: die();
69: }
70: if (gotwinch) {
71: clearok(curscr, TRUE);
72: wrefresh(curscr);
73: gotwinch = 0;
74: }
75:
76: refresh();
77: if ((ch = getch()) == ERR) {
78: if (errno == EINTR)
79: continue;
1.6 millert 80: exit(1);
1.10 deraadt 81: }
82: ch &= 0177;
83: if (ch == 0177 && ferror(stdin)) {
84: clearerr(stdin);
85: continue;
86: }
87: if (ch >= 'A' && ch <= 'Z')
88: ch += 'a' - 'A';
89: if (col == 0) {
1.7 millert 90: switch (ch) {
91: case CTRL('l'):
92: case CTRL('g'):
93: sigemptyset(&mask);
94: sigaddset(&mask, SIGALRM);
95: sigprocmask(SIG_BLOCK, &mask, &omask);
96: if (ch == CTRL('l'))
97: wrefresh(curscr);
98: else
99: status();
100: sigprocmask(SIG_SETMASK, &omask, NULL);
1.10 deraadt 101: continue;
1.7 millert 102: case ':':
103: break;
104: default:
1.1 deraadt 105: continue;
106: }
1.10 deraadt 107: move(CMDLINE, 0);
108: clrtoeol();
109: }
110: if (ch == erasechar() && col > 0) {
111: if (col == 1 && line[0] == ':')
112: continue;
113: col--;
114: goto doerase;
115: }
116: if (ch == CTRL('w') && col > 0) {
117: while (--col >= 0 && isspace(line[col]))
118: ;
119: col++;
120: while (--col >= 0 && !isspace(line[col]))
121: if (col == 0 && line[0] == ':')
122: break;
123: col++;
124: goto doerase;
125: }
126: if (ch == killchar() && col > 0) {
127: col = 0;
128: if (line[0] == ':')
129: col++;
130: doerase:
131: move(CMDLINE, col);
132: clrtoeol();
133: continue;
134: }
1.5 aaron 135: if (col >= sizeof(line) - 1) {
1.3 deraadt 136: /* line too long */
137: beep();
138: continue;
139: }
1.10 deraadt 140: if (isprint(ch) || ch == ' ') {
141: line[col] = ch;
142: mvaddch(CMDLINE, col, ch);
143: col++;
144: }
145: } while (col == 0 || (ch != '\r' && ch != '\n'));
146: line[col] = '\0';
1.7 millert 147: sigemptyset(&mask);
148: sigaddset(&mask, SIGALRM);
149: sigprocmask(SIG_BLOCK, &mask, &omask);
1.10 deraadt 150: command(line + 1);
1.7 millert 151: sigprocmask(SIG_SETMASK, &omask, NULL);
1.10 deraadt 152: }
1.1 deraadt 153: /*NOTREACHED*/
154: }