Search
lxdream.org :: lxdream/src/drivers/genkeymap.pl
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/genkeymap.pl
changeset 1183:425d9de21c78
prev917:2146dd5529fd
author nkeynes
date Tue Nov 29 16:15:38 2011 +1000 (11 years ago)
permissions -rwxr-xr-x
last change Fix out-of-tree builds of the mac keymaps
file annotate diff log raw
nkeynes@681
     1
#!/usr/bin/perl
nkeynes@681
     2
use POSIX;
nkeynes@681
     3
nkeynes@1183
     4
if( $#ARGV != 3 ) {
nkeynes@1183
     5
    die "Usage: genkeymap.pl <keysym-name> <dckeysyms.h> <keymap.txt> <output.h>\n";
nkeynes@1183
     6
}
nkeynes@1183
     7
nkeynes@1183
     8
my $name = shift();
nkeynes@1183
     9
my $dckeysymsfile = shift();
nkeynes@1183
    10
my $keymapfile = shift();
nkeynes@1183
    11
my $outputfile = shift();
nkeynes@681
    12
my %dcsyms = ();
nkeynes@681
    13
nkeynes@1183
    14
my %hash = ();
nkeynes@1183
    15
my %rhash = ();
nkeynes@1183
    16
nkeynes@1183
    17
open(DCKB, "<$dckeysymsfile") || die "Unable to open dckeysym file $dckeysymsfile";
nkeynes@681
    18
while(<DCKB>) {
nkeynes@681
    19
    if( /^#define\s+DCKB_([^ ]*)/ ) {
nkeynes@681
    20
        $dcsyms{$1} = "DCKB_$1";
nkeynes@681
    21
    }
nkeynes@681
    22
}
nkeynes@1183
    23
close DCKB;
nkeynes@681
    24
nkeynes@1183
    25
open(KM, "<$keymapfile") || die "Unable to open keymap file $keymapfile";
nkeynes@1183
    26
while(<KM>) {
nkeynes@681
    27
    my ($val, $sym) = split /\s+/;
nkeynes@681
    28
    $ival = POSIX::strtol($val,0);
nkeynes@681
    29
    $hash{$ival} = $sym;
nkeynes@681
    30
    $rhash{$sym} = $ival;
nkeynes@681
    31
}
nkeynes@1183
    32
close KM;
nkeynes@681
    33
nkeynes@1183
    34
open(OUT, ">$outputfile") || die "Unable to open output file $outputfile";
nkeynes@1183
    35
print OUT "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n";
nkeynes@1183
    36
print OUT "const gchar *${name}_keysyms_by_keycode[128] = { ";
nkeynes@681
    37
nkeynes@681
    38
for( $i=0; $i < 128; $i++ ) {
nkeynes@1183
    39
    if( $i != 0 ) { 
nkeynes@1183
    40
        print OUT ", "; 
nkeynes@1183
    41
    }
nkeynes@917
    42
    if( defined($hash{$i}) ) {
nkeynes@1183
    43
        print OUT "\"$hash{$i}\"";
nkeynes@681
    44
    } else {
nkeynes@1183
    45
        print OUT "NULL";
nkeynes@681
    46
    }
nkeynes@681
    47
}
nkeynes@1183
    48
print OUT "};\n\n";
nkeynes@681
    49
nkeynes@1183
    50
print OUT "const uint16_t ${name}_keycode_to_dckeysym[128] = { ";
nkeynes@681
    51
for( $i=0; $i<128; $i++ ) {
nkeynes@1183
    52
    if( $i != 0 ) { 
nkeynes@1183
    53
        print OUT ", "; 
nkeynes@1183
    54
    }
nkeynes@917
    55
    if( defined($hash{$i}) && $dcsyms{$hash{$i}} ) {
nkeynes@1183
    56
        print OUT $dcsyms{$hash{$i}};
nkeynes@681
    57
    } else {
nkeynes@1183
    58
        print OUT "DCKB_NONE";
nkeynes@681
    59
    }
nkeynes@681
    60
}
nkeynes@1183
    61
print OUT "};\n\n";
nkeynes@681
    62
nkeynes@681
    63
my @keys = sort {uc($a) cmp uc($b)} keys %rhash;
nkeynes@1183
    64
print OUT "#define ${name}_keysym_count " . ($#keys+1) . "\n";
nkeynes@1183
    65
print OUT "struct ${name}_keymap_struct {\n    const gchar *name;\n    uint16_t keycode;\n};\n\n";
nkeynes@1183
    66
print OUT "struct ${name}_keymap_struct ${name}_keysyms[] = { ";
nkeynes@681
    67
foreach my $keysym (@keys) {
nkeynes@1183
    68
    print OUT "{\"$keysym\", $rhash{$keysym} }, ";
nkeynes@681
    69
}
nkeynes@1183
    70
print OUT "{NULL,-1} };\n\n";
nkeynes@1183
    71
close OUT;
.