summaryrefslogtreecommitdiff
path: root/busybox/busybox-1.00/add-getkey-applet.patch
blob: fb681335563cd85a1efe64641221ca4227ffdda4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#

--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ busybox-1.00-pre10/console-tools/getkey.c	2004-06-11 22:22:54.402329312 +0200
@@ -0,0 +1,70 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * getkey.c - Michael 'Mickey' Lauer
+ *
+ * Version 0.1
+ *
+ * A simple keygrapper. Displays a configurable message and waits a dedicated number
+ * of seconds for a keypress. Sets the exit code accordingly (SUCCESS on keypress).
+ */
+#include <stdio.h>
+#include <fcntl.h>
+#include <memory.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/kd.h>
+#include "busybox.h"
+
+extern int getkey_main(int argc, char **argv)
+{
+    int status = EXIT_FAILURE;
+
+    if ( argc < 2 ) {
+        bb_show_usage();
+    }
+
+    //bb_printf( "DEBUG: time = '%s'\n", argv[1] );
+    //bb_printf( "DEBUG: mesg = '%s'\n", argv[2] );
+
+    struct termios orig;
+    struct termios attr;
+
+    tcgetattr(STDIN_FILENO, &orig);
+    attr = orig;
+    attr.c_cc[VMIN] = 0;
+    attr.c_cc[VTIME] = 0;
+    attr.c_iflag |= INLCR;
+    attr.c_oflag |= OPOST|ONLCR;
+    attr.c_cflag &= ~PARENB;
+    attr.c_lflag &= ~(ICANON/*|ECHO*/);
+    tcsetattr(STDIN_FILENO,TCSANOW,&attr);
+
+    fd_set rfds;
+    struct timeval tv;
+    int retval;
+
+    FD_ZERO(&rfds);
+    FD_SET(0, &rfds);
+
+    tv.tv_sec = atoi( argv[1] );
+    tv.tv_usec = 0;
+
+    if ( argc == 3 )
+    {
+        bb_printf( argv[2], tv.tv_sec );
+        bb_printf( "\n" );
+        fflush(stdout);
+    }
+    retval = select(1, &rfds, NULL, NULL, &tv);
+    if (retval)
+    {
+        status = EXIT_SUCCESS;
+    }
+
+    tcsetattr(STDIN_FILENO,TCSANOW,&orig);
+    return status;
+};
+
--- busybox-1.00-pre10/console-tools/Makefile.in~getkey	2004-03-15 09:28:17.000000000 +0100
+++ busybox-1.00-pre10/console-tools/Makefile.in	2004-06-10 16:31:03.000000000 +0200
@@ -27,6 +27,7 @@
 CONSOLETOOLS_DIR-$(CONFIG_CLEAR)	+= clear.o
 CONSOLETOOLS_DIR-$(CONFIG_DEALLOCVT)	+= deallocvt.o
 CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP)	+= dumpkmap.o
+CONSOLETOOLS_DIR-$(CONFIG_GETKEY)	+= getkey.o
 CONSOLETOOLS_DIR-$(CONFIG_LOADFONT)	+= loadfont.o
 CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP)	+= loadkmap.o
 CONSOLETOOLS_DIR-$(CONFIG_OPENVT)	+= openvt.o
--- busybox-1.00-pre10/console-tools/Config.in~getkey	2003-12-20 08:07:22.000000000 +0100
+++ busybox-1.00-pre10/console-tools/Config.in	2004-06-10 16:34:39.000000000 +0200
@@ -31,6 +31,14 @@
 	  This program dumps the kernel's keyboard translation table to
 	  stdout, in binary format. You can then use loadkmap to load it.
 
+config CONFIG_GETKEY
+	bool "getkey"
+	default n
+	help
+	  This program displays a configurable message and waits
+	  a dedicated number of seconds for a keypress. It sets
+	  the exit code accordingly, i.e. SUCCESS if there was a keypress.
+
 config CONFIG_LOADFONT
 	bool "loadfont"
 	default n
--- busybox-1.00-pre10/include/applets.h~getkey	2004-04-06 18:59:43.000000000 +0200
+++ busybox-1.00-pre10/include/applets.h	2004-06-10 16:40:23.000000000 +0200
@@ -223,6 +223,9 @@
 #ifdef CONFIG_FTPPUT
 	APPLET(ftpput, ftpgetput_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
 #endif
+#ifdef CONFIG_GETKEY
+	APPLET(getkey, getkey_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
+#endif
 #ifdef CONFIG_GETOPT
 	APPLET(getopt, getopt_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
--- busybox-1.00-pre10/include/usage.h~getkey	2004-04-13 21:27:20.000000000 +0200
+++ busybox-1.00-pre10/include/usage.h	2004-06-11 22:23:29.593979368 +0200
@@ -729,6 +729,13 @@
 	"\t-p, --password         Password to be used\n" \
 	"\t-P, --port             Port number to be used"
 
+#define getkey_trivial_usage \
+	"time [message]"
+#define getkey_full_usage \
+	"Display a message and wait for a keypress."
+#define getkey_example_usage \
+	"$ getkey 5 'Press a key within %d seconds to interrupt autoboot.'"
+
 #define getopt_trivial_usage \
 	"[OPTIONS]..."
 #define getopt_full_usage \