summaryrefslogtreecommitdiff
path: root/keytab
blob: fcab7ed6de57b8cdbc76f74161c5d3b7b76cdd13 (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
#! /usr/bin/perl

use Encode;
use Getopt::Long;

sub get_table;
sub do_enc;

$opt_all = 0;
$opt_enc = undef;

GetOptions(
  'all' => \$opt_all,
  'enc=s' => \$opt_enc
);

$keytable = shift;

@us_map{get_table "us"} = () unless $opt_all;
@map = get_table $keytable;

for (keys %us_map) {
  delete $us_map{$_} if /\[\s*0x56/;
}


print "/keymap.$keytable [\n";
for (@map) {
  print $_ unless exists $us_map{$_};
}
print "] def\n";


sub get_table
{
  local $_;
  my ($kt, $map_idx, @map, @psmap, $x, $n, $s, $a);

  $kt = shift;

  open F, "loadkeys -m $kt |";
  while(<F>) {
    $map_idx = 0 if /u_short/;
    if(/u_short\s+plain_map\[/) { $map_idx = 1; $key_idx = 0 }
    if(/u_short\s+shift_map\[/) { $map_idx = 2; $key_idx = 0 }
    if(/u_short\s+altgr_map\[/) { $map_idx = 3; $key_idx = 0 }
    if($map_idx) {
      while(/(0xf\S{3}),/g) {
        $x = $1;
        $map[$key_idx][0] = $key_idx;
        $map[$key_idx][$map_idx] = hex($x) & 0xff if $x =~ /0xf[0b]/;
        $key_idx++;
      }
    }
  }
  close F;

  for (@map) {
    ($n, $s, $a) = ($_->[1], $_->[2], $_->[3]);
    $a = 0 if $a == $n || $a == $s;
    if($n || $s || $a) {
      push @psmap, sprintf("  [ 0x%02x 0x%02x 0x%02x 0x%02x ]\n", $_->[0], do_enc($n), do_enc($s), do_enc($a));
    }
  }

  @psmap;
}


sub do_enc
{
  my ($c);

  $c = shift;

  return $c unless $opt_enc;

  return unpack("V", encode("utf32le", decode($opt_enc, chr($c))));
}