|
3 | 3 |
|
4 | 4 | ''' |
5 | 5 | Generate a Python extension module that exports macros from |
6 | | -/usr/include/linux/input.h |
| 6 | +/usr/include/linux/input.h and /usr/include/linux/uinput.h |
7 | 7 | ''' |
8 | 8 |
|
9 | 9 | import os, sys, re |
|
12 | 12 | template = r''' |
13 | 13 | #include <Python.h> |
14 | 14 | #include <linux/input.h> |
| 15 | +#include <linux/uinput.h> |
15 | 16 |
|
16 | 17 | /* Automatically generated by evdev.genecodes */ |
17 | | -/* Generated on %s */ |
| 18 | +/* Generated on %(uname)s */ |
18 | 19 |
|
19 | 20 | #define MODULE_NAME "_ecodes" |
20 | | -#define MODULE_HELP "linux/input.h macros" |
| 21 | +#define MODULE_HELP "linux/input.h and linux/uinput.h macros" |
21 | 22 |
|
22 | 23 | static PyMethodDef MethodTable[] = { |
23 | 24 | { NULL, NULL, 0, NULL} |
|
49 | 50 |
|
50 | 51 | if (m == NULL) return NULL; |
51 | 52 |
|
52 | | -%s |
| 53 | + /* input.h constants */ |
| 54 | +%(input)s |
| 55 | +
|
| 56 | + /* uinput.h constants */ |
| 57 | +%(uinput)s |
53 | 58 |
|
54 | 59 | return m; |
55 | 60 | } |
|
69 | 74 | #endif |
70 | 75 | ''' |
71 | 76 |
|
72 | | -header = '/usr/include/linux/input.h' if len(sys.argv) == 1 else sys.argv[1] |
73 | | -regex = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF)_\w+)' |
74 | | -regex = re.compile(regex) |
| 77 | +inputh = '/usr/include/linux/input.h' if len(sys.argv) == 1 else sys.argv[1] |
| 78 | +uinputh = '/usr/include/linux/uinput.h' if len(sys.argv) < 3 else sys.argv[2] |
| 79 | + |
| 80 | +inputh_re = r'#define +((?:KEY|ABS|REL|SW|MSC|LED|BTN|REP|SND|ID|EV|BUS|SYN|FF)_\w+)' |
| 81 | +inputh_re = re.compile(inputh_re) |
| 82 | +uinputh_re = r'#define +((?:EV|UI_FF)_\w+)' |
| 83 | +uinputh_re = re.compile(uinputh_re) |
75 | 84 |
|
76 | | -if not os.path.exists(header): |
77 | | - print('no such file: %s' % header) |
78 | | - sys.exit(1) |
| 85 | +for fn in inputh, uinputh: |
| 86 | + if not os.path.exists(fn): |
| 87 | + print('no such file: %s' % inputh) |
| 88 | + sys.exit(1) |
79 | 89 |
|
80 | | -def getmacros(): |
81 | | - for line in open(header): |
| 90 | +def getmacros(fn, regex): |
| 91 | + for line in open(fn): |
82 | 92 | macro = regex.search(line) |
83 | 93 | if macro: |
84 | 94 | yield ' PyModule_AddIntMacro(m, %s);' % macro.group(1) |
85 | 95 |
|
86 | 96 | uname = list(os.uname()); del uname[1] |
87 | 97 | uname = ' '.join(uname) |
88 | 98 |
|
89 | | -macros = os.linesep.join(getmacros()) |
90 | | -print(template % (uname, macros)) |
| 99 | +input_macros = os.linesep.join(getmacros(inputh, inputh_re)) |
| 100 | +uinput_macros = os.linesep.join(getmacros(uinputh, uinputh_re)) |
| 101 | + |
| 102 | +ctx = {'uname': uname, 'input': input_macros, 'uinput': uinput_macros} |
| 103 | +print(template % ctx) |
0 commit comments