[PATCH libevdev 2/3] Resolve the names "SW_MAX" and friends

Peter Hutterer peter.hutterer at who-t.net
Mon Jun 18 05:53:10 UTC 2018


Some of the *_MAX names are duplicates and have a real define. These were not
resolved until now.

Fixes https://gitlab.freedesktop.org/libevdev/libevdev/issues/3

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/make-event-names.py | 18 ++++++++++++++----
 test/test-event-codes.c      | 16 ++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/libevdev/make-event-names.py b/libevdev/make-event-names.py
index faee720..38b44cf 100755
--- a/libevdev/make-event-names.py
+++ b/libevdev/make-event-names.py
@@ -9,7 +9,8 @@ import re
 import sys
 
 class Bits(object):
-	pass
+	def __init__(self):
+		self.max_codes = {}
 
 prefixes = [
 		"EV_",
@@ -113,6 +114,12 @@ def print_lookup(bits, prefix):
 	if prefix == "btn":
 		names = names + btn_additional;
 
+	# We need to manually add the _MAX codes because some are
+	# duplicates
+	maxname = "%s_MAX" % (prefix.upper())
+	if maxname in duplicates:
+		names.append((bits.max_codes[maxname], maxname))
+
 	for val, name in sorted(names, key=lambda e: e[1]):
 		print("	{ .name = \"%s\", .value = %s }," % (name, name))
 
@@ -161,9 +168,6 @@ def parse_define(bits, line):
 
 	name = m.group(1)
 
-	if name in duplicates:
-		return
-
 	try:
 		value = int(m.group(2), 0)
 	except ValueError:
@@ -173,6 +177,12 @@ def parse_define(bits, line):
 		if not name.startswith(prefix):
 			continue
 
+		if name.endswith("_MAX"):
+			bits.max_codes[name] = value
+
+		if name in duplicates:
+			return
+
 		attrname = prefix[:-1].lower()
 
 		if not hasattr(bits, attrname):
diff --git a/test/test-event-codes.c b/test/test-event-codes.c
index 8e85df8..8b587d9 100644
--- a/test/test-event-codes.c
+++ b/test/test-event-codes.c
@@ -99,6 +99,21 @@ START_TEST(test_code_names_invalid)
 }
 END_TEST
 
+START_TEST(test_code_names_max)
+{
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_SYN, "SYN_MAX"), SYN_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_KEY, "KEY_MAX"), KEY_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_REL, "REL_MAX"), REL_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_ABS, "ABS_MAX"), ABS_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_MSC, "MSC_MAX"), MSC_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_SW, "SW_MAX"), SW_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_LED, "LED_MAX"), LED_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_SND, "SND_MAX"), SND_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_REP, "REP_MAX"), REP_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_FF, "FF_MAX"), FF_MAX);
+}
+END_TEST
+
 START_TEST(test_properties)
 {
 	struct prop {
@@ -143,6 +158,7 @@ TEST_SUITE(event_code_suite)
 	tc = tcase_create("code tests");
 	tcase_add_test(tc, test_code_names);
 	tcase_add_test(tc, test_code_names_invalid);
+	tcase_add_test(tc, test_code_names_max);
 	suite_add_tcase(s, tc);
 
 	tc = tcase_create("property tests");
-- 
2.14.4



More information about the Input-tools mailing list