xref: /original-bsd/usr.bin/systat/keyboard.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1980, 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)keyboard.c	8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11 
12 #include <ctype.h>
13 #include <signal.h>
14 #include <termios.h>
15 
16 #include "systat.h"
17 #include "extern.h"
18 
19 int
20 keyboard()
21 {
22         char ch, line[80];
23 	int oldmask;
24 
25         for (;;) {
26                 col = 0;
27                 move(CMDLINE, 0);
28                 do {
29                         refresh();
30                         ch = getch() & 0177;
31                         if (ch == 0177 && ferror(stdin)) {
32                                 clearerr(stdin);
33                                 continue;
34                         }
35                         if (ch >= 'A' && ch <= 'Z')
36                                 ch += 'a' - 'A';
37                         if (col == 0) {
38 #define	mask(s)	(1 << ((s) - 1))
39                                 if (ch == CTRL('l')) {
40 					oldmask = sigblock(mask(SIGALRM));
41 					wrefresh(curscr);
42 					sigsetmask(oldmask);
43                                         continue;
44                                 }
45 				if (ch == CTRL('g')) {
46 					oldmask = sigblock(mask(SIGALRM));
47 					status();
48 					sigsetmask(oldmask);
49 					continue;
50 				}
51                                 if (ch != ':')
52                                         continue;
53                                 move(CMDLINE, 0);
54                                 clrtoeol();
55                         }
56                         if (ch == erasechar() && col > 0) {
57                                 if (col == 1 && line[0] == ':')
58                                         continue;
59                                 col--;
60                                 goto doerase;
61                         }
62                         if (ch == CTRL('w') && col > 0) {
63                                 while (--col >= 0 && isspace(line[col]))
64                                         ;
65                                 col++;
66                                 while (--col >= 0 && !isspace(line[col]))
67                                         if (col == 0 && line[0] == ':')
68                                                 break;
69                                 col++;
70                                 goto doerase;
71                         }
72                         if (ch == killchar() && col > 0) {
73                                 col = 0;
74                                 if (line[0] == ':')
75                                         col++;
76                 doerase:
77                                 move(CMDLINE, col);
78                                 clrtoeol();
79                                 continue;
80                         }
81                         if (isprint(ch) || ch == ' ') {
82                                 line[col] = ch;
83                                 mvaddch(CMDLINE, col, ch);
84                                 col++;
85                         }
86                 } while (col == 0 || (ch != '\r' && ch != '\n'));
87                 line[col] = '\0';
88 		oldmask = sigblock(mask(SIGALRM));
89                 command(line + 1);
90 		sigsetmask(oldmask);
91         }
92 	/*NOTREACHED*/
93 }
94