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

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