This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
forked from trevd/android_external_keytable
-
Notifications
You must be signed in to change notification settings - Fork 4
/
gen_keytables.pl
executable file
·216 lines (180 loc) · 4.61 KB
/
gen_keytables.pl
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/perl
use strict;
use File::Find;
my @ir_files = (
"drivers/media/usb/dvb-usb/a800.c",
"drivers/media/usb/dvb-usb/af9005-remote.c",
"drivers/media/usb/dvb-usb-v2/af9015.c",
"drivers/media/usb/dvb-usb-v2/af9015.h",
"drivers/media/usb/dvb-usb-v2/anysee.c",
"drivers/media/usb/dvb-usb/cinergyT2-core.c",
"drivers/media/usb/dvb-usb/cxusb.c",
"drivers/media/usb/dvb-usb/dibusb-common.c",
"drivers/media/usb/dvb-usb/digitv.c",
"drivers/media/usb/dvb-usb/dtt200u.c",
"drivers/media/usb/dvb-usb/dvb-usb-remote.c",
"drivers/media/usb/dvb-usb/dvb-usb.h",
"drivers/media/usb/dvb-usb/dw2102.c",
"drivers/media/usb/dvb-usb/m920x.c",
"drivers/media/usb/dvb-usb/nova-t-usb2.c",
"drivers/media/usb/dvb-usb/opera1.c",
"drivers/media/usb/dvb-usb/vp702x.c",
"drivers/media/usb/dvb-usb/vp7045.c",
);
my $debug = 1;
my $dir="rc_keymaps";
my $deftype = "UNKNOWN";
my $keyname="";
my $out;
my $read=0;
my $type = $deftype;
my $check_type = 0;
my $name;
my $warn;
my $warn_all;
my %rc_map_names;
my $kernel_dir = shift or die "Need a file name to proceed.";
sub flush($)
{
my $filename = shift;
my $defined;
return if (!$keyname || !$out);
print "Creating $dir/$keyname\n";
open OUT, ">$dir/$keyname";
print OUT "# table $keyname, type: $type\n";
print OUT $out;
close OUT;
if (!$name) {
$warn++;
} else {
$defined = 1 if ($rc_map_names{$name});
}
if ($defined) {
printf OUT_MAP "*\t%-24s %s\n", $rc_map_names{$name} , $keyname;
} else {
my $fname = $filename;
$fname =~ s,.*/,,;
printf OUT_MAP "# *\t*\t\t\t %-20s # found in %s\n", $keyname, $fname;
}
$keyname = "";
$out = "";
$type = $deftype;
$name = "";
}
sub parse_file($)
{
my $filename = shift;
$warn = 0;
printf "processing file $filename\n" if ($debug);
open IN, "<$filename" or die "couldn't find $filename";
while (<IN>) {
if (m/struct\s+rc_map_table\s+(\w[\w\d_]+)/) {
flush($filename);
$keyname = $1;
$keyname =~ s/^rc_map_//;
$keyname =~ s/_table$//;
$read = 1;
next;
}
if (m/struct\s+rc_map_list.*=\s+{/) {
$check_type = 1;
next;
}
if ($check_type) {
if (m/\.name\s*=\s*(RC_MAP_[^\s\,]+)/) {
$name = $1;
$keyname = $1;
$keyname =~ s/^RC_MAP_//;
$keyname =~ tr/A-Z/a-z/;
$keyname =~ s/_table$//;
}
if (m/^\s*}/) {
$check_type = 0;
next;
}
if (m/RC_TYPE_([\w\d_]+)/) {
$type = $1;
# Proper name the RC6 protocol
$type =~ s/^RC6_MCE$/RC6/;
}
next;
}
if ($read) {
if (m/(0x[\dA-Fa-f]+)[\s\,]+(KEY|BTN)(\_[^\s\,\}]+)/) {
$out .= "$1 $2$3\n";
next;
}
if (m/\}/) {
$read = 0;
}
}
}
close IN;
flush($filename);
printf STDERR "WARNING: keyboard name not found on %d tables at file $filename\n", $warn if ($warn);
$warn_all += $warn;
}
sub parse_dir()
{
my $file = $File::Find::name;
return if ($file =~ m/^\./);
return if (! ($file =~ m/\.c$/));
parse_file $file;
}
sub sort_dir()
{
sort @_;
}
sub parse_rc_map_names($)
{
my $filename = shift;
$warn = 0;
printf "processing file $filename\n" if ($debug);
open IN, "<$filename" or die "couldn't find $filename";
while (<IN>) {
if (m/^\s*\#define\s+(RC_MAP[^\s]+)\s+\"(.*)\"/) {
$rc_map_names{$1} = $2;
}
}
}
# Main logic
#
parse_rc_map_names "$kernel_dir/include/media/rc-map.h";
open OUT_MAP, ">rc_maps.cfg";
print OUT_MAP << "EOF";
#
# Keymaps table
#
# This table creates an association between a keycode file and a kernel
# driver. It can be used to automatically override a keycode definition.
#
# Although not yet tested, it is mented to be added at udev.
#
# To use, you just need to run:
# ./ir-keytable -a
#
# Or, if the remote is not the first device:
# ./ir-keytable -a -s rc1 # for RC at rc1
#
# Format:
# driver - name of the driver provided via uevent - use * for any driver
# table - RC keymap table, provided via uevent - use * for any table
# file - file name. If directory is not specified, it will default to
# /etc/rc_keymaps.
# For example:
# driver table file
# cx8800 * ./keycodes/rc5_hauppauge_new
# * rc-avermedia-m135a-rm-jx ./keycodes/kworld_315u
# saa7134 rc-avermedia-m135a-rm-jx ./keycodes/keycodes/nec_terratec_cinergy_xs
# em28xx * ./keycodes/kworld_315u
# * * ./keycodes/rc5_hauppauge_new
# Table to automatically load the rc maps for the bundled IR's provided with the
# devices supported by the linux kernel
#driver table file
EOF
find({wanted => \&parse_dir, preprocess => \&sort_dir, no_chdir => 1}, "$kernel_dir/drivers/media/rc/keymaps");
foreach my $file (@ir_files) {
parse_file "$kernel_dir/$file";
}
printf STDERR "WARNING: there are %d tables not defined at rc_maps.h\n", $warn_all if ($warn_all);
close OUT_MAP;