]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.bin/systat/keyboard.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.bin / systat / keyboard.c
1 /*-
2  * Copyright (c) 1980, 1992, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #include <sys/cdefs.h>
35
36 __FBSDID("$FreeBSD$");
37
38 #ifdef lint
39 static const char sccsid[] = "@(#)keyboard.c    8.1 (Berkeley) 6/6/93";
40 #endif
41
42 #include <errno.h>
43 #include <ctype.h>
44 #include <signal.h>
45 #include <stdlib.h>
46 #include <termios.h>
47
48 #include "systat.h"
49 #include "extern.h"
50
51 int
52 keyboard(void)
53 {
54         char ch, line[80];
55         int oldmask;
56
57         for (;;) {
58                 col = 0;
59                 move(CMDLINE, 0);
60                 do {
61                         refresh();
62                         ch = getch();
63                         if (ch == ERR) {
64                                 if (errno == EINTR)
65                                         continue;
66                                 exit(1);
67                         }
68                         if (ch >= 'A' && ch <= 'Z')
69                                 ch += 'a' - 'A';
70                         if (col == 0) {
71 #define mask(s) (1 << ((s) - 1))
72                                 if (ch == CTRL('l')) {
73                                         oldmask = sigblock(mask(SIGALRM));
74                                         wrefresh(curscr);
75                                         sigsetmask(oldmask);
76                                         continue;
77                                 }
78                                 if (ch == CTRL('g')) {
79                                         oldmask = sigblock(mask(SIGALRM));
80                                         status();
81                                         sigsetmask(oldmask);
82                                         continue;
83                                 }
84                                 if (ch != ':')
85                                         continue;
86                                 move(CMDLINE, 0);
87                                 clrtoeol();
88                         }
89                         if (ch == erasechar() && col > 0) {
90                                 if (col == 1 && line[0] == ':')
91                                         continue;
92                                 col--;
93                                 goto doerase;
94                         }
95                         if (ch == CTRL('w') && col > 0) {
96                                 while (--col >= 0 && isspace(line[col]))
97                                         ;
98                                 col++;
99                                 while (--col >= 0 && !isspace(line[col]))
100                                         if (col == 0 && line[0] == ':')
101                                                 break;
102                                 col++;
103                                 goto doerase;
104                         }
105                         if (ch == killchar() && col > 0) {
106                                 col = 0;
107                                 if (line[0] == ':')
108                                         col++;
109                 doerase:
110                                 move(CMDLINE, col);
111                                 clrtoeol();
112                                 continue;
113                         }
114                         if (isprint(ch) || ch == ' ') {
115                                 line[col] = ch;
116                                 mvaddch(CMDLINE, col, ch);
117                                 col++;
118                         }
119                 } while (col == 0 || (ch != '\r' && ch != '\n'));
120                 line[col] = '\0';
121                 oldmask = sigblock(mask(SIGALRM));
122                 command(line + 1);
123                 sigsetmask(oldmask);
124         }
125         /*NOTREACHED*/
126 }