-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdumpkey2h
executable file
·58 lines (48 loc) · 873 Bytes
/
dumpkey2h
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
#!/usr/bin/perl -w
open(I, "dumpkeys|") or die $!;
open(O, ">keytab.h") or die $!;
print O<<EOF;
#ifndef __keytab_h__
#define __keytab_h__
char *keytable[512] = {
EOF
my %keytab = ();
my %name2char = (
"one" => "1",
"two" => "2",
"three" => "3",
"four" => "4",
"five" => "5",
"six" => "6",
"seven" => "7",
"eight" => "8",
"nine" => "9",
"zero" => "0",
"minus" => "-",
"plus" => "+",
"period" => ".",
"space" => " ",
);
while(<I>) {
if (/keycode\s+(\d+)\s+=\s+(\S+)\s+/) {
if (!defined $keytab{$1}) {
$keytab{$1} = $2;
}
}
}
close(I);
my $s = "";
foreach (keys %keytab) {
if (length($keytab{$_}) > 1) {
if (defined $name2char{$keytab{$_}}) {
$s = $name2char{$keytab{$_}};
} else {
$s = "<".$keytab{$_}.">";
}
} else {
$s = $keytab{$_};
}
print O "\t[$_] = \"".$s."\",\n";
}
print O "};\n#endif\n";
close(O);