Commit | Line | Data |
---|---|---|
07ed1e09 KM |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
3d3ef1d9 | 7 | #ifndef lint |
07ed1e09 KM |
8 | static char sccsid[] = "@(#)keyboard.c 5.1 (Berkeley) %G%"; |
9 | #endif not lint | |
3d3ef1d9 SL |
10 | |
11 | /* | |
12 | * Keyboard input support. | |
13 | */ | |
14 | ||
15 | #include "systat.h" | |
855ff304 | 16 | #include <ctype.h> |
3d3ef1d9 SL |
17 | |
18 | keyboard() | |
19 | { | |
20 | char ch, line[80]; | |
855ff304 | 21 | int oldmask; |
3d3ef1d9 SL |
22 | |
23 | for (;;) { | |
24 | col = 0; | |
855ff304 | 25 | move(CMDLINE, 0); |
3d3ef1d9 SL |
26 | do { |
27 | refresh(); | |
28 | ch = getch() & 0177; | |
29 | if (ch == 0177 && ferror(stdin)) { | |
30 | clearerr(stdin); | |
31 | continue; | |
32 | } | |
33 | if (ch >= 'A' && ch <= 'Z') | |
34 | ch += 'a' - 'A'; | |
35 | if (col == 0) { | |
36 | #define mask(s) (1 << ((s) - 1)) | |
37 | if (ch == CTRL(l)) { | |
855ff304 | 38 | oldmask = sigblock(mask(SIGALRM)); |
3d3ef1d9 SL |
39 | wrefresh(curscr); |
40 | sigsetmask(oldmask); | |
41 | continue; | |
42 | } | |
43 | if (ch == CTRL(g)) { | |
855ff304 | 44 | oldmask = sigblock(mask(SIGALRM)); |
3d3ef1d9 | 45 | status(); |
855ff304 | 46 | sigsetmask(oldmask); |
3d3ef1d9 SL |
47 | continue; |
48 | } | |
49 | if (ch != ':') | |
50 | continue; | |
855ff304 | 51 | move(CMDLINE, 0); |
3d3ef1d9 SL |
52 | clrtoeol(); |
53 | } | |
54 | if (ch == _tty.sg_erase && col > 0) { | |
55 | if (col == 1 && line[0] == ':') | |
56 | continue; | |
57 | col--; | |
58 | goto doerase; | |
59 | } | |
60 | if (ch == CTRL(w) && col > 0) { | |
61 | while (--col >= 0 && isspace(line[col])) | |
62 | ; | |
63 | col++; | |
64 | while (--col >= 0 && !isspace(line[col])) | |
65 | if (col == 0 && line[0] == ':') | |
66 | break; | |
67 | col++; | |
68 | goto doerase; | |
69 | } | |
70 | if (ch == _tty.sg_kill && col > 0) { | |
71 | col = 0; | |
72 | if (line[0] == ':') | |
73 | col++; | |
74 | doerase: | |
855ff304 | 75 | move(CMDLINE, col); |
3d3ef1d9 SL |
76 | clrtoeol(); |
77 | continue; | |
78 | } | |
974755eb | 79 | if (isprint(ch) || ch == ' ') { |
3d3ef1d9 | 80 | line[col] = ch; |
855ff304 | 81 | mvaddch(CMDLINE, col, ch); |
3d3ef1d9 SL |
82 | col++; |
83 | } | |
84 | } while (col == 0 || (ch != '\r' && ch != '\n')); | |
85 | line[col] = '\0'; | |
855ff304 | 86 | oldmask = sigblock(mask(SIGALRM)); |
3d3ef1d9 | 87 | command(line + 1); |
855ff304 | 88 | sigsetmask(oldmask); |
3d3ef1d9 SL |
89 | } |
90 | /*NOTREACHED*/ | |
91 | } |