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