keyboard.c revision 226396
11590Srgrimes/*- 21590Srgrimes * Copyright (c) 1980, 1992, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes */ 291590Srgrimes 3087715Smarkm#include <sys/cdefs.h> 311590Srgrimes 3287715Smarkm__FBSDID("$FreeBSD: head/usr.bin/systat/keyboard.c 226396 2011-10-15 13:20:36Z ed $"); 3387715Smarkm 3487715Smarkm#ifdef lint 3587715Smarkmstatic const char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93"; 3687715Smarkm#endif 3787715Smarkm 38197956Sjh#include <errno.h> 391590Srgrimes#include <ctype.h> 401590Srgrimes#include <signal.h> 41197956Sjh#include <stdlib.h> 421590Srgrimes#include <termios.h> 431590Srgrimes 441590Srgrimes#include "systat.h" 451590Srgrimes#include "extern.h" 461590Srgrimes 471590Srgrimesint 48175387Sdelphijkeyboard(void) 491590Srgrimes{ 50226396Sed char ch, line[80]; 511590Srgrimes int oldmask; 521590Srgrimes 53226396Sed for (;;) { 54226396Sed col = 0; 55226396Sed move(CMDLINE, 0); 56226396Sed do { 57226396Sed refresh(); 58226396Sed ch = getch(); 59226396Sed if (ch == ERR) { 60226396Sed if (errno == EINTR) 61226396Sed continue; 62226396Sed exit(1); 63226396Sed } 64226396Sed if (ch >= 'A' && ch <= 'Z') 65226396Sed ch += 'a' - 'A'; 66226396Sed if (col == 0) { 671590Srgrimes#define mask(s) (1 << ((s) - 1)) 68226396Sed if (ch == CTRL('l')) { 691590Srgrimes oldmask = sigblock(mask(SIGALRM)); 701590Srgrimes wrefresh(curscr); 711590Srgrimes sigsetmask(oldmask); 72226396Sed continue; 73226396Sed } 741590Srgrimes if (ch == CTRL('g')) { 751590Srgrimes oldmask = sigblock(mask(SIGALRM)); 761590Srgrimes status(); 771590Srgrimes sigsetmask(oldmask); 781590Srgrimes continue; 791590Srgrimes } 80226396Sed if (ch != ':') 81226396Sed continue; 82226396Sed move(CMDLINE, 0); 83226396Sed clrtoeol(); 84226396Sed } 85226396Sed if (ch == erasechar() && col > 0) { 86226396Sed if (col == 1 && line[0] == ':') 87226396Sed continue; 88226396Sed col--; 89226396Sed goto doerase; 90226396Sed } 91226396Sed if (ch == CTRL('w') && col > 0) { 92226396Sed while (--col >= 0 && isspace(line[col])) 93226396Sed ; 94226396Sed col++; 95226396Sed while (--col >= 0 && !isspace(line[col])) 96226396Sed if (col == 0 && line[0] == ':') 97226396Sed break; 98226396Sed col++; 99226396Sed goto doerase; 100226396Sed } 101226396Sed if (ch == killchar() && col > 0) { 102226396Sed col = 0; 103226396Sed if (line[0] == ':') 104226396Sed col++; 105226396Sed doerase: 106226396Sed move(CMDLINE, col); 107226396Sed clrtoeol(); 108226396Sed continue; 109226396Sed } 110226396Sed if (isprint(ch) || ch == ' ') { 111226396Sed line[col] = ch; 112226396Sed mvaddch(CMDLINE, col, ch); 113226396Sed col++; 114226396Sed } 115226396Sed } while (col == 0 || (ch != '\r' && ch != '\n')); 116226396Sed line[col] = '\0'; 1171590Srgrimes oldmask = sigblock(mask(SIGALRM)); 118226396Sed command(line + 1); 1191590Srgrimes sigsetmask(oldmask); 120226396Sed } 1211590Srgrimes /*NOTREACHED*/ 1221590Srgrimes} 123