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

1.3       deraadt     1: /*     $OpenBSD: keyboard.c,v 1.2 1996/06/26 05:40:07 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.3       deraadt    41: static char rcsid[] = "$OpenBSD: keyboard.c,v 1.2 1996/06/26 05:40:07 deraadt Exp $";
1.1       deraadt    42: #endif /* not lint */
                     43:
                     44: #include <ctype.h>
                     45: #include <signal.h>
                     46: #include <termios.h>
                     47:
                     48: #include "systat.h"
                     49: #include "extern.h"
                     50:
1.4     ! kstailey   51: void
1.1       deraadt    52: keyboard()
                     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() & 0177;
                     63:                         if (ch == 0177 && ferror(stdin)) {
                     64:                                 clearerr(stdin);
                     65:                                 continue;
                     66:                         }
                     67:                         if (ch >= 'A' && ch <= 'Z')
                     68:                                 ch += 'a' - 'A';
                     69:                         if (col == 0) {
                     70: #define        mask(s) (1 << ((s) - 1))
                     71:                                 if (ch == CTRL('l')) {
                     72:                                        oldmask = sigblock(mask(SIGALRM));
                     73:                                        wrefresh(curscr);
                     74:                                        sigsetmask(oldmask);
                     75:                                         continue;
                     76:                                 }
                     77:                                if (ch == CTRL('g')) {
                     78:                                        oldmask = sigblock(mask(SIGALRM));
                     79:                                        status();
                     80:                                        sigsetmask(oldmask);
                     81:                                        continue;
                     82:                                }
                     83:                                 if (ch != ':')
                     84:                                         continue;
                     85:                                 move(CMDLINE, 0);
                     86:                                 clrtoeol();
                     87:                         }
                     88:                         if (ch == erasechar() && col > 0) {
                     89:                                 if (col == 1 && line[0] == ':')
                     90:                                         continue;
                     91:                                 col--;
                     92:                                 goto doerase;
                     93:                         }
                     94:                         if (ch == CTRL('w') && col > 0) {
                     95:                                 while (--col >= 0 && isspace(line[col]))
                     96:                                         ;
                     97:                                 col++;
                     98:                                 while (--col >= 0 && !isspace(line[col]))
                     99:                                         if (col == 0 && line[0] == ':')
                    100:                                                 break;
                    101:                                 col++;
                    102:                                 goto doerase;
                    103:                         }
                    104:                         if (ch == killchar() && col > 0) {
                    105:                                 col = 0;
                    106:                                 if (line[0] == ':')
                    107:                                         col++;
                    108:                 doerase:
                    109:                                 move(CMDLINE, col);
                    110:                                 clrtoeol();
                    111:                                 continue;
                    112:                         }
1.3       deraadt   113:                        if (col >= sizeof(line)) {
                    114:                                /* line too long */
                    115:                                beep();
                    116:                                continue;
                    117:                        }
1.1       deraadt   118:                         if (isprint(ch) || ch == ' ') {
                    119:                                 line[col] = ch;
                    120:                                 mvaddch(CMDLINE, col, ch);
                    121:                                 col++;
                    122:                         }
                    123:                 } while (col == 0 || (ch != '\r' && ch != '\n'));
                    124:                 line[col] = '\0';
                    125:                oldmask = sigblock(mask(SIGALRM));
                    126:                 command(line + 1);
                    127:                sigsetmask(oldmask);
                    128:         }
                    129:        /*NOTREACHED*/
                    130: }