--- a/src/drivers/genkeymap.pl Fri Nov 07 07:53:31 2008 +0000 +++ b/src/drivers/genkeymap.pl Tue Nov 29 16:15:38 2011 +1000 @@ -1,56 +1,71 @@ #!/usr/bin/perl - use POSIX; -my $dckeysymsfile = "dckeysyms.h"; +if( $#ARGV != 3 ) { + die "Usage: genkeymap.pl \n"; +} + +my $name = shift(); +my $dckeysymsfile = shift(); +my $keymapfile = shift(); +my $outputfile = shift(); my %dcsyms = (); -open DCKB, "<$dckeysymsfile" || die "Unable to open keysym file $dckeysymsfile"; +my %hash = (); +my %rhash = (); + +open(DCKB, "<$dckeysymsfile") || die "Unable to open dckeysym file $dckeysymsfile"; while() { if( /^#define\s+DCKB_([^ ]*)/ ) { $dcsyms{$1} = "DCKB_$1"; } } +close DCKB; -my %hash = (); -my %rhash = (); -my $name = shift(); -while() { +open(KM, "<$keymapfile") || die "Unable to open keymap file $keymapfile"; +while() { my ($val, $sym) = split /\s+/; $ival = POSIX::strtol($val,0); $hash{$ival} = $sym; $rhash{$sym} = $ival; } +close KM; -print "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n"; +open(OUT, ">$outputfile") || die "Unable to open output file $outputfile"; +print OUT "/**\n * $name keyboard map autogenerated by genkeymap.pl\n */\n\n"; +print OUT "const gchar *${name}_keysyms_by_keycode[128] = { "; -print "const gchar *${name}_keysyms_by_keycode[128] = { "; for( $i=0; $i < 128; $i++ ) { - if( $i != 0 ) { print ", "; } + if( $i != 0 ) { + print OUT ", "; + } if( defined($hash{$i}) ) { - print "\"$hash{$i}\""; + print OUT "\"$hash{$i}\""; } else { - print "NULL"; + print OUT "NULL"; } } -print "};\n\n"; +print OUT "};\n\n"; -print "const uint16_t ${name}_keycode_to_dckeysym[128] = { "; +print OUT "const uint16_t ${name}_keycode_to_dckeysym[128] = { "; for( $i=0; $i<128; $i++ ) { - if( $i != 0 ) { print ", "; } + if( $i != 0 ) { + print OUT ", "; + } if( defined($hash{$i}) && $dcsyms{$hash{$i}} ) { - print $dcsyms{$hash{$i}}; + print OUT $dcsyms{$hash{$i}}; } else { - print "DCKB_NONE"; + print OUT "DCKB_NONE"; } } -print "};\n\n"; +print OUT "};\n\n"; my @keys = sort {uc($a) cmp uc($b)} keys %rhash; -print "#define ${name}_keysym_count " . ($#keys+1) . "\n"; -print "struct ${name}_keymap_struct {\n const gchar *name;\n uint16_t keycode;\n};\n\n"; -print "struct ${name}_keymap_struct ${name}_keysyms[] = { "; +print OUT "#define ${name}_keysym_count " . ($#keys+1) . "\n"; +print OUT "struct ${name}_keymap_struct {\n const gchar *name;\n uint16_t keycode;\n};\n\n"; +print OUT "struct ${name}_keymap_struct ${name}_keysyms[] = { "; foreach my $keysym (@keys) { - print "{\"$keysym\", $rhash{$keysym} }, "; + print OUT "{\"$keysym\", $rhash{$keysym} }, "; } -print "{NULL,-1} };\n\n"; +print OUT "{NULL,-1} };\n\n"; +close OUT;