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