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 Sun Feb 12 16:30:26 2012 +1000 (12 years ago)
permissions -rwxr-xr-x
last change Add -Werror for mregparm check, so it actually fails if mregparm isn't
accepted
view annotate diff log raw
     1 #!/usr/bin/perl
     2 use POSIX;
     4 if( $#ARGV != 3 ) {
     5     die "Usage: genkeymap.pl <keysym-name> <dckeysyms.h> <keymap.txt> <output.h>\n";
     6 }
     8 my $name = shift();
     9 my $dckeysymsfile = shift();
    10 my $keymapfile = shift();
    11 my $outputfile = shift();
    12 my %dcsyms = ();
    14 my %hash = ();
    15 my %rhash = ();
    17 open(DCKB, "<$dckeysymsfile") || die "Unable to open dckeysym file $dckeysymsfile";
    18 while(<DCKB>) {
    19     if( /^#define\s+DCKB_([^ ]*)/ ) {
    20         $dcsyms{$1} = "DCKB_$1";
    21     }
    22 }
    23 close DCKB;
    25 open(KM, "<$keymapfile") || die "Unable to open keymap file $keymapfile";
    26 while(<KM>) {
    27     my ($val, $sym) = split /\s+/;
    28     $ival = POSIX::strtol($val,0);
    29     $hash{$ival} = $sym;
    30     $rhash{$sym} = $ival;
    31 }
    32 close KM;
    34 open(OUT, ">$outputfile") || die "Unable to open output file $outputfile";
    35 print OUT "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n";
    36 print OUT "const gchar *${name}_keysyms_by_keycode[128] = { ";
    38 for( $i=0; $i < 128; $i++ ) {
    39     if( $i != 0 ) { 
    40         print OUT ", "; 
    41     }
    42     if( defined($hash{$i}) ) {
    43         print OUT "\"$hash{$i}\"";
    44     } else {
    45         print OUT "NULL";
    46     }
    47 }
    48 print OUT "};\n\n";
    50 print OUT "const uint16_t ${name}_keycode_to_dckeysym[128] = { ";
    51 for( $i=0; $i<128; $i++ ) {
    52     if( $i != 0 ) { 
    53         print OUT ", "; 
    54     }
    55     if( defined($hash{$i}) && $dcsyms{$hash{$i}} ) {
    56         print OUT $dcsyms{$hash{$i}};
    57     } else {
    58         print OUT "DCKB_NONE";
    59     }
    60 }
    61 print OUT "};\n\n";
    63 my @keys = sort {uc($a) cmp uc($b)} keys %rhash;
    64 print OUT "#define ${name}_keysym_count " . ($#keys+1) . "\n";
    65 print OUT "struct ${name}_keymap_struct {\n    const gchar *name;\n    uint16_t keycode;\n};\n\n";
    66 print OUT "struct ${name}_keymap_struct ${name}_keysyms[] = { ";
    67 foreach my $keysym (@keys) {
    68     print OUT "{\"$keysym\", $rhash{$keysym} }, ";
    69 }
    70 print OUT "{NULL,-1} };\n\n";
    71 close OUT;
.