summaryrefslogtreecommitdiffstats
path: root/drivers/usb/mkmap.adb
blob: 45020d5ccdfc20a12e93ee264b8ca1f87b83cdb7 (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
81
82
83
84
85
86
87
88
#!/usr/bin/perl

($ME = $0) =~ s|.*/||;

$file = "maps/mac.map";
$line = 1;
open(PC, $file) || die("$!");
while(<PC>)
{
    if(/^\s*keycode\s+(\d+|0x[0-9a-fA-F]+)\s*=\s*(\S+)/)
    {
        my($idx) = $1;
        my($sym) = $2;
        if ($idx =~ "0x.*") {
            $idx = hex($idx);
        } else {
            $idx = int($idx);
        }
        if(defined($map{uc($sym)}))
        {
            # print STDERR "$file:$line: warning: `$sym' redefined\n";
        }
        $map{uc($sym)} = $idx;
    }
    $line++;
}
close(PC);

# $file = "maps/fixup.map";
# $line = 1;
# open(FIXUP, $file) || die("$!");
# while(<FIXUP>)
# {
#     if(/^\s*keycode\s+(\d+)\s*=\s*/)
#     {
#       my($idx) = int($1);
#       for $sym (split(/\s+/, $'))
#         {
#           $map{uc($sym)} = $idx;
#       }
#     }
#     $line++;
# }
# close(FIXUP);

$file = "maps/usb.map";
$line = 1;
open(USB, $file) || die("$!");
while(<USB>)
{
    if(/^\s*keycode\s+(\d+)\s*=\s*/)
    {
        my($idx) = int($1);
        for $sym (split(/\s+/, $'))
        {
            my($val) = $map{uc($sym)};
            $map[$idx] = $val;
            if(!defined($val))
            {
                print STDERR "$file:$line: warning: `$sym' undefined\n";
            }
            else
            {
                last;
            }
        }
    }
    $line++;
}
close(USB);

print "unsigned char usb_kbd_map[256] = \n{\n";
for($x = 0; $x < 32; $x++)
{
    if($x && !($x % 2))
    {
        print "\n";
    }
    print "  ";
    for($y = 0; $y < 8; $y++)
    {
        my($idx) = $x * 8 + $y;
        print sprintf("  0x%02x,",
                      int(defined($map[$idx]) ? $map[$idx]:0));
    }
    print "\n";
}
print "};\n";