summaryrefslogtreecommitdiffstats
path: root/perl-install/install/share/kmap2bkmap
blob: 9870ef3ef92abcc6b8ed039866ee294a197d9e33 (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
#!/usr/bin/perl

use lib "/usr/lib/libDrakX";
use c;

my $KMAP_MAGIC = 0x8B39C07F;

BEGIN { @ARGV == 1 or die "usage: kmap2bkmap <keymap>\n" }

# load unicode keymap
my $unimap = $ARGV[0] . ".uni";
system("sudo loadkeys $unimap") == 0 or die;
open my $F, "dumpkeys -n -f |";
<$F> =~ /^keymaps\s+(.*)/ or die;

my @keymaps;
foreach (split ',', $1) {
    my @l = /(\d+)-(\d+)/;
    my ($i, $j) = @l ? @l : ($_,$_);
    $keymaps[$_] = 1 foreach $i .. $j;
}

print pack("I", $KMAP_MAGIC);
print map { pack "i", $keymaps[$_] || 0 } 0 .. c::MAX_NR_KEYMAPS()-1;

my @L;
foreach (<$F>) {
    s/\+0x/0x/g;
    my ($keycode, $key, undef, @l) = split;
    $keycode eq 'keycode' or next;
    my $i = 0;
    $L[$i++][$key] = hex $_ foreach @l;
}
close $F or die "dumpkeys failed";

foreach (@L) {
    foreach my $i (0 .. c::NR_KEYS()-1) {
	print pack "s", defined $_->[$i] ? $_->[$i] : 0x200;
    }
}

exit 0;