[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.15

1.15    ! deraadt     1: /*     $OpenBSD: keyboard.c,v 1.14 2003/07/10 00:06:51 david 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.15    ! deraadt    37: static char rcsid[] = "$OpenBSD: keyboard.c,v 1.14 2003/07/10 00:06:51 david Exp $";
1.1       deraadt    38: #endif /* not lint */
                     39:
                     40: #include <ctype.h>
                     41: #include <signal.h>
1.14      david      42: #include <stdlib.h>
1.1       deraadt    43: #include <termios.h>
1.10      deraadt    44: #include <errno.h>
1.1       deraadt    45:
                     46: #include "systat.h"
                     47: #include "extern.h"
                     48:
1.4       kstailey   49: void
1.12      deraadt    50: keyboard(void)
1.1       deraadt    51: {
1.11      deraadt    52:        char line[80];
1.7       millert    53:        sigset_t mask, omask;
1.11      deraadt    54:        int ch;
1.1       deraadt    55:
1.10      deraadt    56:        for (;;) {
                     57:                col = 0;
                     58:                move(CMDLINE, 0);
                     59:                do {
1.15    ! deraadt    60:                        if (gottstp) {
        !            61:                                endwin();
        !            62:                                kill(getpid(), SIGSTOP);
        !            63:                                gotwinch = 1;
        !            64:                                gottstp = 0;
        !            65:                        }
1.10      deraadt    66:                        if (gotdisplay) {
                     67:                                display();
                     68:                                gotdisplay = 0;
                     69:                        }
                     70:                        if (gotdie) {
                     71:                                die();
                     72:                        }
                     73:                        if (gotwinch) {
                     74:                                clearok(curscr, TRUE);
                     75:                                wrefresh(curscr);
                     76:                                gotwinch = 0;
                     77:                        }
                     78:
                     79:                        refresh();
                     80:                        if ((ch = getch()) == ERR) {
                     81:                                if (errno == EINTR)
                     82:                                        continue;
1.6       millert    83:                                exit(1);
1.10      deraadt    84:                        }
                     85:                        ch &= 0177;
                     86:                        if (ch == 0177 && ferror(stdin)) {
                     87:                                clearerr(stdin);
                     88:                                continue;
                     89:                        }
                     90:                        if (ch >= 'A' && ch <= 'Z')
                     91:                                ch += 'a' - 'A';
                     92:                        if (col == 0) {
1.7       millert    93:                                switch (ch) {
                     94:                                case CTRL('l'):
                     95:                                case CTRL('g'):
                     96:                                        sigemptyset(&mask);
                     97:                                        sigaddset(&mask, SIGALRM);
                     98:                                        sigprocmask(SIG_BLOCK, &mask, &omask);
                     99:                                        if (ch == CTRL('l'))
                    100:                                                wrefresh(curscr);
                    101:                                        else
                    102:                                                status();
                    103:                                        sigprocmask(SIG_SETMASK, &omask, NULL);
1.10      deraadt   104:                                        continue;
1.7       millert   105:                                case ':':
                    106:                                        break;
                    107:                                default:
1.1       deraadt   108:                                        continue;
                    109:                                }
1.10      deraadt   110:                                move(CMDLINE, 0);
                    111:                                clrtoeol();
                    112:                        }
                    113:                        if (ch == erasechar() && col > 0) {
                    114:                                if (col == 1 && line[0] == ':')
                    115:                                        continue;
                    116:                                col--;
                    117:                                goto doerase;
                    118:                        }
                    119:                        if (ch == CTRL('w') && col > 0) {
                    120:                                while (--col >= 0 && isspace(line[col]))
                    121:                                        ;
                    122:                                col++;
                    123:                                while (--col >= 0 && !isspace(line[col]))
                    124:                                        if (col == 0 && line[0] == ':')
                    125:                                                break;
                    126:                                col++;
                    127:                                goto doerase;
                    128:                        }
                    129:                        if (ch == killchar() && col > 0) {
                    130:                                col = 0;
                    131:                                if (line[0] == ':')
                    132:                                        col++;
                    133:                doerase:
                    134:                                move(CMDLINE, col);
                    135:                                clrtoeol();
                    136:                                continue;
                    137:                        }
1.5       aaron     138:                        if (col >= sizeof(line) - 1) {
1.3       deraadt   139:                                /* line too long */
                    140:                                beep();
                    141:                                continue;
                    142:                        }
1.10      deraadt   143:                        if (isprint(ch) || ch == ' ') {
                    144:                                line[col] = ch;
                    145:                                mvaddch(CMDLINE, col, ch);
                    146:                                col++;
                    147:                        }
                    148:                } while (col == 0 || (ch != '\r' && ch != '\n'));
                    149:                line[col] = '\0';
1.7       millert   150:                sigemptyset(&mask);
                    151:                sigaddset(&mask, SIGALRM);
                    152:                sigprocmask(SIG_BLOCK, &mask, &omask);
1.10      deraadt   153:                command(line + 1);
1.7       millert   154:                sigprocmask(SIG_SETMASK, &omask, NULL);
1.10      deraadt   155:        }
1.1       deraadt   156:        /*NOTREACHED*/
                    157: }