Skip to content

Commit 83083e9

Browse files
Add script for parsing event codes from a header file
1 parent 7f9f4e3 commit 83083e9

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

scripts/parse-event-codes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
from __future__ import with_statement
5+
6+
import re
7+
import sys
8+
9+
def parse_event_codes(filepath, ev_type, ev_name):
10+
with open(filepath) as f:
11+
for line in f:
12+
match = re.match(r"^#define (" + ev_name + "_.*)\t+((?:0x[0-9a-f]+)|(?:\d+)|(?:[A-Z_]+))", line)
13+
if match:
14+
print("%s = (%s, %s)" % (match.group(1).strip(), ev_type, match.group(2).strip()))
15+
16+
if __name__ == "__main__":
17+
filepath = sys.argv[1]
18+
19+
parse_event_codes(filepath, "0x01", "KEY")
20+
parse_event_codes(filepath, "0x01", "BTN")
21+
parse_event_codes(filepath, "0x02", "REL")
22+
parse_event_codes(filepath, "0x03", "ABS")

0 commit comments

Comments
 (0)