summaryrefslogtreecommitdiffstats
path: root/toolbox/generate-input.h-labels.py
blob: ebb95887a028744ad2e3400ee9e16194a483c1b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pylint: disable=bad-indentation,bad-continuation

import os
import re

input_prop_list = []
ev_list = []
syn_list = []
key_list = []
rel_list = []
abs_list = []
sw_list = []
msc_list = []
led_list = []
rep_list = []
snd_list = []
mt_tool_list = []
ff_status_list = []
ff_list = []

r = re.compile(r'#define\s+(\S+)\s+((?:0x)?\d+)')

with open('bionic/libc/kernel/uapi/linux/input.h', 'r') as f:
  for line in f:
    m = r.match(line)
    if m:
      name = m.group(1)
      if name.startswith("INPUT_PROP_"):
        input_prop_list.append(name)
      elif name.startswith("EV_"):
        ev_list.append(name)
      elif name.startswith("SYN_"):
        syn_list.append(name)
      elif name.startswith("KEY_") or name.startswith("BTN_"):
        key_list.append(name)
      elif name.startswith("REL_"):
        rel_list.append(name)
      elif name.startswith("ABS_"):
        abs_list.append(name)
      elif name.startswith("SW_"):
        sw_list.append(name)
      elif name.startswith("MSC_"):
        msc_list.append(name)
      elif name.startswith("LED_"):
        led_list.append(name)
      elif name.startswith("REP_"):
        rep_list.append(name)
      elif name.startswith("SND_"):
        snd_list.append(name)
      elif name.startswith("MT_TOOL_"):
        mt_tool_list.append(name)
      elif name.startswith("FF_STATUS_"):
        ff_status_list.append(name)
      elif name.startswith("FF_"):
        ff_list.append(name)

def Dump(struct_name, values):
  print 'static struct label %s[] = {' % (struct_name)
  for value in values:
    print '    LABEL(%s),' % (value)
  print '    LABEL_END,'
  print '};'

Dump("input_prop_labels", input_prop_list)
Dump("ev_labels", ev_list)
Dump("syn_labels", syn_list)
Dump("key_labels", key_list)
Dump("rel_labels", rel_list)
Dump("abs_labels", abs_list)
Dump("sw_labels", sw_list)
Dump("msc_labels", msc_list)
Dump("led_labels", led_list)
Dump("rep_labels", rep_list)
Dump("snd_labels", snd_list)
Dump("mt_tool_labels", mt_tool_list)
Dump("ff_status_labels", ff_status_list)
Dump("ff_labels", ff_list)