You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Kaleidoscope/tools/generate_keymaps.pl

56 lines
1004 B

use warnings;
use strict;
my @data = <STDIN>;
use Data::Dumper;
my $name = 'Unnamed';
my @map;
for my $line (@data) {
chomp($line);
if ($line =~ /^#NAME: (.*)/i) {
$name = $1;
next
}
my @keys = split(/\s+/, $line);
push @map, join(', ', map{ ''.lookup($_).'' } @keys);
}
print "#define KEYMAP_$name { /* Generated keymap for $name */ ";
for my $line (@map) {
print "\t{". $line ."},\\\n";
}
print "},\n";
sub lookup {
my %table = (
'{' => 'Key_LCurlyBracket',
'}' => 'Key_RCurlyBracket',
'['=> 'Key_LSquareBracket',
']'=> 'Key_RSquareBracket',
'|'=> 'Key_Pipe',
'\\' => 'Key_Backslash',
';' => 'Key_Semicolon',
',' => 'Key_Comma',
'.' => 'Key_Period',
'/' => 'Key_Slash',
"'" => 'Key_Quote',
'`' => 'Key_Backtick',
'-' => 'Key_Minus',
'=' => 'Key_Equals',
'___' => '___',
'XXX' => 'XXX');
my $x = shift;
return $x if $x =~ /\(.*\)/;
return '___' if ($x =~ /_{2,}/);
return 'XXX' if ($x =~ /X{2,}/);
return 'Key_'.$x unless defined $table{$x};
return $table{$x};
}