filename | src/drivers/genkeymap.pl |
changeset | 1183:425d9de21c78 |
prev | 917:2146dd5529fd |
author | nkeynes |
date | Mon Mar 05 11:41:03 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Small cleanups: Refactor the post-windowing setup into gl_init_driver() in video_gl.c Move gl_sl.c into src/drivers and tidy up a bit. Fix OS X compiling plugins with -mdynamic-no-pic |
file | annotate | diff | log | raw |
1.1 --- a/src/drivers/genkeymap.pl Fri Nov 07 07:53:31 2008 +00001.2 +++ b/src/drivers/genkeymap.pl Mon Mar 05 11:41:03 2012 +10001.3 @@ -1,56 +1,71 @@1.4 #!/usr/bin/perl1.5 -1.6 use POSIX;1.8 -my $dckeysymsfile = "dckeysyms.h";1.9 +if( $#ARGV != 3 ) {1.10 + die "Usage: genkeymap.pl <keysym-name> <dckeysyms.h> <keymap.txt> <output.h>\n";1.11 +}1.12 +1.13 +my $name = shift();1.14 +my $dckeysymsfile = shift();1.15 +my $keymapfile = shift();1.16 +my $outputfile = shift();1.17 my %dcsyms = ();1.19 -open DCKB, "<$dckeysymsfile" || die "Unable to open keysym file $dckeysymsfile";1.20 +my %hash = ();1.21 +my %rhash = ();1.22 +1.23 +open(DCKB, "<$dckeysymsfile") || die "Unable to open dckeysym file $dckeysymsfile";1.24 while(<DCKB>) {1.25 if( /^#define\s+DCKB_([^ ]*)/ ) {1.26 $dcsyms{$1} = "DCKB_$1";1.27 }1.28 }1.29 +close DCKB;1.31 -my %hash = ();1.32 -my %rhash = ();1.33 -my $name = shift();1.34 -while(<ARGV>) {1.35 +open(KM, "<$keymapfile") || die "Unable to open keymap file $keymapfile";1.36 +while(<KM>) {1.37 my ($val, $sym) = split /\s+/;1.38 $ival = POSIX::strtol($val,0);1.39 $hash{$ival} = $sym;1.40 $rhash{$sym} = $ival;1.41 }1.42 +close KM;1.44 -print "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n";1.45 +open(OUT, ">$outputfile") || die "Unable to open output file $outputfile";1.46 +print OUT "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n";1.47 +print OUT "const gchar *${name}_keysyms_by_keycode[128] = { ";1.49 -print "const gchar *${name}_keysyms_by_keycode[128] = { ";1.50 for( $i=0; $i < 128; $i++ ) {1.51 - if( $i != 0 ) { print ", "; }1.52 + if( $i != 0 ) {1.53 + print OUT ", ";1.54 + }1.55 if( defined($hash{$i}) ) {1.56 - print "\"$hash{$i}\"";1.57 + print OUT "\"$hash{$i}\"";1.58 } else {1.59 - print "NULL";1.60 + print OUT "NULL";1.61 }1.62 }1.63 -print "};\n\n";1.64 +print OUT "};\n\n";1.66 -print "const uint16_t ${name}_keycode_to_dckeysym[128] = { ";1.67 +print OUT "const uint16_t ${name}_keycode_to_dckeysym[128] = { ";1.68 for( $i=0; $i<128; $i++ ) {1.69 - if( $i != 0 ) { print ", "; }1.70 + if( $i != 0 ) {1.71 + print OUT ", ";1.72 + }1.73 if( defined($hash{$i}) && $dcsyms{$hash{$i}} ) {1.74 - print $dcsyms{$hash{$i}};1.75 + print OUT $dcsyms{$hash{$i}};1.76 } else {1.77 - print "DCKB_NONE";1.78 + print OUT "DCKB_NONE";1.79 }1.80 }1.81 -print "};\n\n";1.82 +print OUT "};\n\n";1.84 my @keys = sort {uc($a) cmp uc($b)} keys %rhash;1.85 -print "#define ${name}_keysym_count " . ($#keys+1) . "\n";1.86 -print "struct ${name}_keymap_struct {\n const gchar *name;\n uint16_t keycode;\n};\n\n";1.87 -print "struct ${name}_keymap_struct ${name}_keysyms[] = { ";1.88 +print OUT "#define ${name}_keysym_count " . ($#keys+1) . "\n";1.89 +print OUT "struct ${name}_keymap_struct {\n const gchar *name;\n uint16_t keycode;\n};\n\n";1.90 +print OUT "struct ${name}_keymap_struct ${name}_keysyms[] = { ";1.91 foreach my $keysym (@keys) {1.92 - print "{\"$keysym\", $rhash{$keysym} }, ";1.93 + print OUT "{\"$keysym\", $rhash{$keysym} }, ";1.94 }1.95 -print "{NULL,-1} };\n\n";1.96 +print OUT "{NULL,-1} };\n\n";1.97 +close OUT;
.