[PATCH evemu 04/10] make-event-names: handle aliases for event code defines

Peter Hutterer peter.hutterer at who-t.net
Mon Aug 4 21:01:46 PDT 2014


Some codes are defined as aliases, e.g.
 #define BTN_A BTN_SOUTH

Handle those as one-way conversions, so we get the right value from the string
when requested.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/make-event-names.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/make-event-names.py b/src/make-event-names.py
index 324647c..320b5ec 100755
--- a/src/make-event-names.py
+++ b/src/make-event-names.py
@@ -46,6 +46,9 @@ oneway = [
 		"BTN_TRIGGER_HAPPY"
 ]
 
+# As above, but input.h defines them as aliases instead of int values
+aliases = {}
+
 def p(s):
 	print(textwrap.dedent(s))
 
@@ -59,6 +62,17 @@ def print_python_bits(bits, prefix):
 			print("	\"%s\" : %d," % (val, name))
 		else:
 			print("	%d : \"%s\", \"%s\" : %d," % (val, name, name, val))
+
+	for alias, mapping in aliases.items():
+		if prefix == "key" and alias.lower().startswith("btn"):
+			pass
+		elif not alias.lower().startswith(prefix):
+			continue
+		for val, name in getattr(bits, prefix).items():
+			if name == mapping:
+				print("	\"%s\" : %d," % (alias, val))
+				break
+
 	print("}")
 	print("")
 
@@ -112,6 +126,7 @@ def parse_define(bits, line):
 	try:
 		value = int(m.group(2), 0)
 	except ValueError:
+		aliases[name] = m.group(2)
 		return
 
 	for prefix in prefixes:
-- 
1.9.3



More information about the Input-tools mailing list