Search
lxdream.org :: lxdream/src/drivers/genkeymap.pl
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/genkeymap.pl
changeset 681:1755a126b109
next917:2146dd5529fd
author nkeynes
date Sun Jun 01 00:47:45 2008 +0000 (14 years ago)
permissions -rwxr-xr-x
last change First cut of the Cocoa GUI implementation
file annotate diff log raw
nkeynes@681
     1
#!/usr/bin/perl
nkeynes@681
     2
nkeynes@681
     3
use POSIX;
nkeynes@681
     4
nkeynes@681
     5
my $dckeysymsfile = "dckeysyms.h";
nkeynes@681
     6
my %dcsyms = ();
nkeynes@681
     7
nkeynes@681
     8
open DCKB, "<$dckeysymsfile" || die "Unable to open keysym file $dckeysymsfile";
nkeynes@681
     9
while(<DCKB>) {
nkeynes@681
    10
    if( /^#define\s+DCKB_([^ ]*)/ ) {
nkeynes@681
    11
        $dcsyms{$1} = "DCKB_$1";
nkeynes@681
    12
    }
nkeynes@681
    13
}
nkeynes@681
    14
nkeynes@681
    15
my %hash = ();
nkeynes@681
    16
my %rhash = ();
nkeynes@681
    17
my $name = shift();
nkeynes@681
    18
while(<ARGV>) {
nkeynes@681
    19
    my ($val, $sym) = split /\s+/;
nkeynes@681
    20
    $ival = POSIX::strtol($val,0);
nkeynes@681
    21
    $hash{$ival} = $sym;
nkeynes@681
    22
    $rhash{$sym} = $ival;
nkeynes@681
    23
}
nkeynes@681
    24
nkeynes@681
    25
print "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n";
nkeynes@681
    26
nkeynes@681
    27
print "const gchar *${name}_keysyms_by_keycode[128] = { ";
nkeynes@681
    28
for( $i=0; $i < 128; $i++ ) {
nkeynes@681
    29
    if( $i != 0 ) { print ", "; }
nkeynes@681
    30
    if( $hash{$i} ) {
nkeynes@681
    31
        print "\"$hash{$i}\"";
nkeynes@681
    32
    } else {
nkeynes@681
    33
        print "NULL";
nkeynes@681
    34
    }
nkeynes@681
    35
}
nkeynes@681
    36
print "};\n\n";
nkeynes@681
    37
nkeynes@681
    38
print "const uint16_t ${name}_keycode_to_dckeysym[128] = { ";
nkeynes@681
    39
for( $i=0; $i<128; $i++ ) {
nkeynes@681
    40
    if( $i != 0 ) { print ", "; }
nkeynes@681
    41
    if( $hash{$i} && $dcsyms{$hash{$i}} ) {
nkeynes@681
    42
        print $dcsyms{$hash{$i}};
nkeynes@681
    43
    } else {
nkeynes@681
    44
        print "DCKB_NONE";
nkeynes@681
    45
    }
nkeynes@681
    46
}
nkeynes@681
    47
print "};\n\n";
nkeynes@681
    48
nkeynes@681
    49
my @keys = sort {uc($a) cmp uc($b)} keys %rhash;
nkeynes@681
    50
print "#define ${name}_keysym_count " . ($#keys+1) . "\n";
nkeynes@681
    51
print "struct ${name}_keymap_struct {\n    const gchar *name;\n    uint16_t keycode;\n};\n\n";
nkeynes@681
    52
print "struct ${name}_keymap_struct ${name}_keysyms[] = { ";
nkeynes@681
    53
foreach my $keysym (@keys) {
nkeynes@681
    54
    print "{\"$keysym\", $rhash{$keysym} }, ";
nkeynes@681
    55
}
nkeynes@681
    56
print "{NULL,-1} };\n\n";
.