aboutsummaryrefslogtreecommitdiffstats
path: root/src/getkey.c
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>1999-09-02 00:57:26 +0000
committerBill Nottingham <notting@redhat.com>1999-09-02 00:57:26 +0000
commite6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c (patch)
tree519a94d0646687a868681da20d91e311c54f023f /src/getkey.c
parentacd1b3af175819b9209cde675deb4a88af32e506 (diff)
downloadinitscripts-e6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c.tar
initscripts-e6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c.tar.gz
initscripts-e6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c.tar.bz2
initscripts-e6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c.tar.xz
initscripts-e6d28cc5aaeabd53ed652eec63c2c22bb3f7e97c.zip
add interactive prompt to make Cristian & Preston happy
Diffstat (limited to 'src/getkey.c')
-rw-r--r--src/getkey.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/getkey.c b/src/getkey.c
new file mode 100644
index 00000000..b17558a3
--- /dev/null
+++ b/src/getkey.c
@@ -0,0 +1,47 @@
+
+#include <ctype.h>
+#include <signal.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+
+/* A very simple keygrabber. */
+
+struct termios tp;
+
+void reset_term(int x) {
+ tcsetattr(0,TCSANOW,&tp);
+ exit(x);
+}
+
+int main(int argc, char **argv) {
+ char foo[2];
+ int tp_if,tp_of,tp_lf;
+ int x;
+
+ if (argc>1) {
+ for (x=0;argv[1][x];x++) argv[1][x]=toupper(argv[1][x]);
+ }
+ foo[0]=foo[1]='\0';
+ signal(SIGTERM,reset_term);
+ tcgetattr(0,&tp);
+ tp_if=tp.c_iflag;
+ tp_of=tp.c_oflag;
+ tp_lf=tp.c_lflag;
+ tp.c_iflag=0;
+ tp.c_oflag &= ~OPOST;
+ tp.c_lflag &= ~(ISIG | ICANON);
+ tcsetattr(0,TCSANOW,&tp);
+ tp.c_iflag=tp_if;
+ tp.c_oflag=tp_of;
+ tp.c_lflag=tp_lf;
+ while (1) {
+ read(0,foo,1);
+ foo[0]=toupper(foo[0]);
+ /* Die if we get a control-c or control-d */
+ if (foo[0]==3 || foo[0]==4) reset_term(1);
+ if ((!argv[1]) || strstr(argv[1],foo)) {
+ reset_term(0);
+ }
+ }
+}