Annotation of src/usr.bin/systat/keyboard.c, Revision 1.6
1.6 ! millert 1: /* $OpenBSD: keyboard.c,v 1.5 2000/06/04 23:06:17 aaron 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.6 ! millert 41: static char rcsid[] = "$OpenBSD: keyboard.c,v 1.5 2000/06/04 23:06:17 aaron Exp $";
1.1 deraadt 42: #endif /* not lint */
43:
44: #include <ctype.h>
45: #include <signal.h>
46: #include <termios.h>
47:
48: #include "systat.h"
49: #include "extern.h"
50:
1.4 kstailey 51: void
1.1 deraadt 52: keyboard()
53: {
54: char ch, line[80];
55: int oldmask;
56:
57: for (;;) {
58: col = 0;
59: move(CMDLINE, 0);
60: do {
61: refresh();
1.6 ! millert 62: if ((ch = getch()) == ERR)
! 63: exit(1);
! 64: ch &= 0177;
1.1 deraadt 65: if (ch == 0177 && ferror(stdin)) {
66: clearerr(stdin);
67: continue;
68: }
69: if (ch >= 'A' && ch <= 'Z')
70: ch += 'a' - 'A';
71: if (col == 0) {
72: #define mask(s) (1 << ((s) - 1))
73: if (ch == CTRL('l')) {
74: oldmask = sigblock(mask(SIGALRM));
75: wrefresh(curscr);
76: sigsetmask(oldmask);
77: continue;
78: }
79: if (ch == CTRL('g')) {
80: oldmask = sigblock(mask(SIGALRM));
81: status();
82: sigsetmask(oldmask);
83: continue;
84: }
85: if (ch != ':')
86: continue;
87: move(CMDLINE, 0);
88: clrtoeol();
89: }
90: if (ch == erasechar() && col > 0) {
91: if (col == 1 && line[0] == ':')
92: continue;
93: col--;
94: goto doerase;
95: }
96: if (ch == CTRL('w') && col > 0) {
97: while (--col >= 0 && isspace(line[col]))
98: ;
99: col++;
100: while (--col >= 0 && !isspace(line[col]))
101: if (col == 0 && line[0] == ':')
102: break;
103: col++;
104: goto doerase;
105: }
106: if (ch == killchar() && col > 0) {
107: col = 0;
108: if (line[0] == ':')
109: col++;
110: doerase:
111: move(CMDLINE, col);
112: clrtoeol();
113: continue;
114: }
1.5 aaron 115: if (col >= sizeof(line) - 1) {
1.3 deraadt 116: /* line too long */
117: beep();
118: continue;
119: }
1.1 deraadt 120: if (isprint(ch) || ch == ' ') {
121: line[col] = ch;
122: mvaddch(CMDLINE, col, ch);
123: col++;
124: }
125: } while (col == 0 || (ch != '\r' && ch != '\n'));
126: line[col] = '\0';
127: oldmask = sigblock(mask(SIGALRM));
128: command(line + 1);
129: sigsetmask(oldmask);
130: }
131: /*NOTREACHED*/
132: }