| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python | 
|  | 2 | # | 
|  | 3 | # Copyright (C) 2015 The Android Open Source Project | 
|  | 4 | # | 
|  | 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); | 
|  | 6 | # you may not use this file except in compliance with the License. | 
|  | 7 | # You may obtain a copy of the License at | 
|  | 8 | # | 
|  | 9 | #      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 10 | # | 
|  | 11 | # Unless required by applicable law or agreed to in writing, software | 
|  | 12 | # distributed under the License is distributed on an 'AS IS' BASIS, | 
|  | 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 14 | # See the License for the specific language governing permissions and | 
|  | 15 | # limitations under the License. | 
|  | 16 | # | 
|  | 17 | # pylint: disable=bad-indentation,bad-continuation | 
|  | 18 |  | 
| Bernhard Rosenkränzer | c434cf8 | 2016-02-23 20:54:35 +0100 | [diff] [blame] | 19 | from __future__ import print_function | 
| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 20 | import os | 
|  | 21 | import re | 
| Elliott Hughes | bd02a47 | 2016-02-08 14:09:10 -0800 | [diff] [blame] | 22 | import sys | 
| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 23 |  | 
|  | 24 | input_prop_list = [] | 
|  | 25 | ev_list = [] | 
|  | 26 | syn_list = [] | 
|  | 27 | key_list = [] | 
|  | 28 | rel_list = [] | 
|  | 29 | abs_list = [] | 
|  | 30 | sw_list = [] | 
|  | 31 | msc_list = [] | 
|  | 32 | led_list = [] | 
|  | 33 | rep_list = [] | 
|  | 34 | snd_list = [] | 
|  | 35 | mt_tool_list = [] | 
|  | 36 | ff_status_list = [] | 
|  | 37 | ff_list = [] | 
|  | 38 |  | 
|  | 39 | r = re.compile(r'#define\s+(\S+)\s+((?:0x)?\d+)') | 
|  | 40 |  | 
| Elliott Hughes | b22b998 | 2016-06-29 14:12:29 -0700 | [diff] [blame] | 41 | for arg in sys.argv[1:]: | 
|  | 42 | with open(arg, 'r') as f: | 
|  | 43 | for line in f: | 
|  | 44 | m = r.match(line) | 
|  | 45 | if m: | 
|  | 46 | name = m.group(1) | 
|  | 47 | if name.startswith("INPUT_PROP_"): | 
|  | 48 | input_prop_list.append(name) | 
|  | 49 | elif name.startswith("EV_"): | 
|  | 50 | ev_list.append(name) | 
|  | 51 | elif name.startswith("SYN_"): | 
|  | 52 | syn_list.append(name) | 
|  | 53 | elif name.startswith("KEY_") or name.startswith("BTN_"): | 
|  | 54 | key_list.append(name) | 
|  | 55 | elif name.startswith("REL_"): | 
|  | 56 | rel_list.append(name) | 
|  | 57 | elif name.startswith("ABS_"): | 
|  | 58 | abs_list.append(name) | 
|  | 59 | elif name.startswith("SW_"): | 
|  | 60 | sw_list.append(name) | 
|  | 61 | elif name.startswith("MSC_"): | 
|  | 62 | msc_list.append(name) | 
|  | 63 | elif name.startswith("LED_"): | 
|  | 64 | led_list.append(name) | 
|  | 65 | elif name.startswith("REP_"): | 
|  | 66 | rep_list.append(name) | 
|  | 67 | elif name.startswith("SND_"): | 
|  | 68 | snd_list.append(name) | 
|  | 69 | elif name.startswith("MT_TOOL_"): | 
|  | 70 | mt_tool_list.append(name) | 
|  | 71 | elif name.startswith("FF_STATUS_"): | 
|  | 72 | ff_status_list.append(name) | 
|  | 73 | elif name.startswith("FF_"): | 
|  | 74 | ff_list.append(name) | 
| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 75 |  | 
|  | 76 | def Dump(struct_name, values): | 
| Bernhard Rosenkränzer | c434cf8 | 2016-02-23 20:54:35 +0100 | [diff] [blame] | 77 | print('static struct label %s[] = {' % (struct_name)) | 
| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 78 | for value in values: | 
| Bernhard Rosenkränzer | c434cf8 | 2016-02-23 20:54:35 +0100 | [diff] [blame] | 79 | print('    LABEL(%s),' % (value)) | 
|  | 80 | print('    LABEL_END,') | 
|  | 81 | print('};') | 
| Elliott Hughes | c7f3c5c | 2015-03-25 16:40:13 -0700 | [diff] [blame] | 82 |  | 
|  | 83 | Dump("input_prop_labels", input_prop_list) | 
|  | 84 | Dump("ev_labels", ev_list) | 
|  | 85 | Dump("syn_labels", syn_list) | 
|  | 86 | Dump("key_labels", key_list) | 
|  | 87 | Dump("rel_labels", rel_list) | 
|  | 88 | Dump("abs_labels", abs_list) | 
|  | 89 | Dump("sw_labels", sw_list) | 
|  | 90 | Dump("msc_labels", msc_list) | 
|  | 91 | Dump("led_labels", led_list) | 
|  | 92 | Dump("rep_labels", rep_list) | 
|  | 93 | Dump("snd_labels", snd_list) | 
|  | 94 | Dump("mt_tool_labels", mt_tool_list) | 
|  | 95 | Dump("ff_status_labels", ff_status_list) | 
|  | 96 | Dump("ff_labels", ff_list) |