[PATCH evemu 7/7] tools: allow symbolic names for evemu-event

Peter Hutterer peter.hutterer at who-t.net
Thu Nov 21 16:20:02 PST 2013


evemu-event --type EV_KEY --code KEY_A --value 1 /dev/input/event0

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 configure.ac           |  2 +-
 tools/Makefile.am      |  3 +++
 tools/evemu-device.txt |  4 +++-
 tools/evemu-event.c    | 45 +++++++++++++++++++++++++++++++++++++--------
 4 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 75f5ad1..9a3f854 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,7 +33,7 @@ AC_PROG_CXX
 AC_PROG_INSTALL
 AM_PATH_PYTHON([2.6])
 
-PKG_CHECK_MODULES([LIBEVDEV], [libevdev >= 0.4])
+PKG_CHECK_MODULES([LIBEVDEV], [libevdev >= 0.5])
 
 # man page generation
 AC_ARG_VAR([XMLTO], [Path to xmlto command])
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b62b2da..bb1eae6 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -15,6 +15,9 @@ AM_LDFLAGS = $(top_builddir)/src/libevemu.la
 evemu_describe_SOURCES = evemu-record.c find_event_devices.c find_event_devices.h
 evemu_record_SOURCES = evemu-record.c find_event_devices.c find_event_devices.h
 
+evemu_event_CFLAGS = $(LIBEVDEV_CFLAGS)
+evemu_event_LDADD = $(LIBEVDEV_LIBS)
+
 # man page generation
 if HAVE_DOCTOOLS
 # actual man pages
diff --git a/tools/evemu-device.txt b/tools/evemu-device.txt
index 27bba25..081355f 100644
--- a/tools/evemu-device.txt
+++ b/tools/evemu-device.txt
@@ -27,7 +27,9 @@ evemu-play replays the event sequence given on stdin through the input
 device. The event sequence must be in the form created by evemu-record(1).
 
 evemu-event plays exactly one event with the current time. If *--sync* is
-given, evemu-event generates an *EV_SYN* event after the event.
+given, evemu-event generates an *EV_SYN* event after the event. The event
+type and code may be specified as the numerical value or the symbolic name
+from linux/input.h.
 
 evemu-device must be able to write to the uinput device node, and evemu-play
 must be able to write to the device node specified; in most cases this means
diff --git a/tools/evemu-event.c b/tools/evemu-event.c
index e44b084..d30e82e 100644
--- a/tools/evemu-event.c
+++ b/tools/evemu-event.c
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <linux/input.h>
+#include <libevdev/libevdev.h>
 
 static struct option opts[] = {
 	{ "type", required_argument, 0, 't'},
@@ -48,6 +49,24 @@ static int parse_arg(const char *arg, long int *value)
 	return 0;
 }
 
+static int parse_type(const char *arg, long int *value)
+{
+	*value = libevdev_event_type_from_name(arg);
+	if (*value != -1)
+		return 0;
+
+	return parse_arg(arg, value);
+}
+
+static int parse_code(long int type, const char *arg, long int *value)
+{
+	*value = libevdev_event_code_from_name(type, arg);
+	if (*value != -1)
+		return 0;
+
+	return parse_arg(arg, value);
+}
+
 static void usage(void)
 {
 	fprintf(stderr, "Usage: %s [--sync] <device> --type <type> --code <code> --value <value>\n", program_invocation_short_name);
@@ -61,6 +80,7 @@ int main(int argc, char *argv[])
 	struct input_event ev;
 	int sync = 0;
 	const char *path = NULL;
+	const char *code_arg = NULL, *type_arg = NULL;
 
 	if (argc < 5) {
 		usage();
@@ -77,16 +97,10 @@ int main(int argc, char *argv[])
 
 		switch(c) {
 			case 't': /* type */
-				if (parse_arg(optarg, &type) || type < 0 || type > EV_MAX) {
-					fprintf(stderr, "error: invalid type argument '%s'\n", optarg);
-					goto out;
-				}
+				type_arg = optarg;
 				break;
 			case 'c': /* code */
-				if (parse_arg(optarg, &code) || code < 0 || code > USHRT_MAX) {
-					fprintf(stderr, "error: invalid code argument '%s'\n", optarg);
-					goto out;
-				}
+				code_arg = optarg;
 				break;
 			case 'v': /* value */
 				if (parse_arg(optarg, &value) || value < INT_MIN || value > INT_MAX) {
@@ -106,6 +120,21 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (!type_arg || !code_arg) {
+		usage();
+		goto out;
+	}
+
+	if (parse_type(type_arg, &type)) {
+		fprintf(stderr, "error: invalid type argument '%s'\n", type_arg);
+		goto out;
+	}
+
+	if (parse_code(type, code_arg, &code)) {
+		fprintf(stderr, "error: invalid code argument '%s'\n", code_arg);
+		goto out;
+	}
+
 	/* if device wasn't specified as option, take the remaining arg */
 	if (optind < argc) {
 		if (argc - optind != 1 || path) {
-- 
1.8.3.1



More information about the Input-tools mailing list