[BACK]Return to keyboard.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Annotation of src/usr.bin/systat/keyboard.c, Revision 1.13

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