Fix Unicode support in generator.
This commit is contained in:
parent
6027084b05
commit
d041c1aaab
@ -28,6 +28,8 @@
|
|||||||
# into the RDP plugin source.
|
# into the RDP plugin source.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
use 5.012;
|
||||||
|
|
||||||
sub keymap_symbol {
|
sub keymap_symbol {
|
||||||
my $_ = shift;
|
my $_ = shift;
|
||||||
s/-/_/g;
|
s/-/_/g;
|
||||||
@ -38,7 +40,7 @@ sub keymap_symbol {
|
|||||||
# _generated_keymaps.c
|
# _generated_keymaps.c
|
||||||
#
|
#
|
||||||
|
|
||||||
@keymaps = ();
|
my @keymaps = ();
|
||||||
|
|
||||||
open OUTPUT, ">", "_generated_keymaps.c";
|
open OUTPUT, ">", "_generated_keymaps.c";
|
||||||
print OUTPUT
|
print OUTPUT
|
||||||
@ -53,15 +55,16 @@ print OUTPUT
|
|||||||
. '#endif' . "\n"
|
. '#endif' . "\n"
|
||||||
. "\n";
|
. "\n";
|
||||||
|
|
||||||
for $filename (@ARGV) {
|
for my $filename (@ARGV) {
|
||||||
|
|
||||||
$content = "";
|
my $content = "";
|
||||||
$parent = "";
|
my $parent = "";
|
||||||
$layout_name = "";
|
my $layout_name = "";
|
||||||
$freerdp = "";
|
my $freerdp = "";
|
||||||
|
|
||||||
# Parse file
|
# Parse file
|
||||||
open INPUT, '<', "$filename";
|
open INPUT, '<', "$filename";
|
||||||
|
binmode INPUT, ":encoding(utf8)";
|
||||||
while (<INPUT>) {
|
while (<INPUT>) {
|
||||||
|
|
||||||
chomp;
|
chomp;
|
||||||
@ -70,39 +73,39 @@ for $filename (@ARGV) {
|
|||||||
if (m/^\s*#/) {}
|
if (m/^\s*#/) {}
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
elsif (($name) = m/^\s*name\s+"(.*)"\s*(?:#.*)?$/) {
|
elsif ((my $name) = m/^\s*name\s+"(.*)"\s*(?:#.*)?$/) {
|
||||||
$layout_name = $name;
|
$layout_name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parent map
|
# Parent map
|
||||||
elsif (($name) = m/^\s*parent\s+"(.*)"\s*(?:#.*)?$/) {
|
elsif ((my $name) = m/^\s*parent\s+"(.*)"\s*(?:#.*)?$/) {
|
||||||
$parent = keymap_symbol($name);
|
$parent = keymap_symbol($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
# FreeRDP equiv
|
# FreeRDP equiv
|
||||||
elsif (($name) = m/^\s*freerdp\s+"(.*)"\s*(?:#.*)?$/) {
|
elsif ((my $name) = m/^\s*freerdp\s+"(.*)"\s*(?:#.*)?$/) {
|
||||||
$freerdp = $name;
|
$freerdp = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Map
|
# Map
|
||||||
elsif (($range, $onto) =
|
elsif ((my $range, my $onto) =
|
||||||
m/^\s*map\s+([^~]*)\s+~\s+(".*"|0x[0-9A-Fa-f]+)\s*(?:#.*)?$/) {
|
m/^\s*map\s+([^~]*)\s+~\s+(".*"|0x[0-9A-Fa-f]+)\s*(?:#.*)?$/) {
|
||||||
|
|
||||||
@keysyms = ();
|
my @keysyms = ();
|
||||||
@scancodes = ();
|
my @scancodes = ();
|
||||||
|
|
||||||
$ext_flags = 0;
|
my $ext_flags = 0;
|
||||||
$set_shift = 0;
|
my $set_shift = 0;
|
||||||
$set_altgr = 0;
|
my $set_altgr = 0;
|
||||||
|
|
||||||
$clear_shift = 0;
|
my $clear_shift = 0;
|
||||||
$clear_altgr = 0;
|
my $clear_altgr = 0;
|
||||||
|
|
||||||
# Parse ranges and options
|
# Parse ranges and options
|
||||||
foreach $_ (split(/\s+/, $range)) {
|
foreach $_ (split(/\s+/, $range)) {
|
||||||
|
|
||||||
# Set option/modifier
|
# Set option/modifier
|
||||||
if (($opt) = m/^\+([a-z]+)$/) {
|
if ((my $opt) = m/^\+([a-z]+)$/) {
|
||||||
if ($opt eq "shift") { $set_shift = 1; }
|
if ($opt eq "shift") { $set_shift = 1; }
|
||||||
elsif ($opt eq "altgr") { $set_altgr = 1; }
|
elsif ($opt eq "altgr") { $set_altgr = 1; }
|
||||||
elsif ($opt eq "ext") { $ext_flags = 1; }
|
elsif ($opt eq "ext") { $ext_flags = 1; }
|
||||||
@ -113,7 +116,7 @@ for $filename (@ARGV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Clear option/modifier
|
# Clear option/modifier
|
||||||
elsif (($opt) = m/^-([a-z]+)$/) {
|
elsif ((my $opt) = m/^-([a-z]+)$/) {
|
||||||
if ($opt eq "shift") { $clear_shift = 1; }
|
if ($opt eq "shift") { $clear_shift = 1; }
|
||||||
elsif ($opt eq "altgr") { $clear_altgr = 1; }
|
elsif ($opt eq "altgr") { $clear_altgr = 1; }
|
||||||
else {
|
else {
|
||||||
@ -123,14 +126,14 @@ for $filename (@ARGV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Single scancode
|
# Single scancode
|
||||||
elsif (($scancode) = m/^(0x[0-9A-Fa-f]+)$/) {
|
elsif ((my $scancode) = m/^(0x[0-9A-Fa-f]+)$/) {
|
||||||
$scancodes[++$#scancodes] = hex($scancode);
|
$scancodes[++$#scancodes] = hex($scancode);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Range of scancodes
|
# Range of scancodes
|
||||||
elsif (($start, $end) =
|
elsif ((my $start, my $end) =
|
||||||
m/^(0x[0-9A-Fa-f]+)\.\.(0x[0-9A-Fa-f]+)$/) {
|
m/^(0x[0-9A-Fa-f]+)\.\.(0x[0-9A-Fa-f]+)$/) {
|
||||||
for ($i=hex($start); $i<=hex($end); $i++) {
|
for (my $i=hex($start); $i<=hex($end); $i++) {
|
||||||
$scancodes[++$#scancodes] = $i;
|
$scancodes[++$#scancodes] = $i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,8 +151,9 @@ for $filename (@ARGV) {
|
|||||||
$keysyms[0] = hex($onto);
|
$keysyms[0] = hex($onto);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach $char (split("", substr($onto, 1, length($onto)-2))) {
|
foreach my $char (split('',
|
||||||
$codepoint = unpack('U0U*', $char);
|
substr($onto, 1, length($onto)-2))) {
|
||||||
|
my $codepoint = ord($char);
|
||||||
if ($codepoint >= 0x0100) {
|
if ($codepoint >= 0x0100) {
|
||||||
$keysyms[++$#keysyms] = 0x01000000 | $codepoint;
|
$keysyms[++$#keysyms] = 0x01000000 | $codepoint;
|
||||||
}
|
}
|
||||||
@ -166,7 +170,7 @@ for $filename (@ARGV) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Write keysym/scancode pairs
|
# Write keysym/scancode pairs
|
||||||
for ($i=0; $i<=$#keysyms; $i++) {
|
for (my $i=0; $i<=$#keysyms; $i++) {
|
||||||
|
|
||||||
$content .= " {"
|
$content .= " {"
|
||||||
. " .keysym = " . $keysyms[$i] . ","
|
. " .keysym = " . $keysyms[$i] . ","
|
||||||
@ -215,7 +219,7 @@ for $filename (@ARGV) {
|
|||||||
close INPUT;
|
close INPUT;
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
$sym = keymap_symbol($layout_name);
|
my $sym = keymap_symbol($layout_name);
|
||||||
print OUTPUT
|
print OUTPUT
|
||||||
"\n"
|
"\n"
|
||||||
. '/* Autogenerated from ' . $filename . ' */' . "\n"
|
. '/* Autogenerated from ' . $filename . ' */' . "\n"
|
||||||
@ -254,7 +258,7 @@ for $filename (@ARGV) {
|
|||||||
print OUTPUT "\n"
|
print OUTPUT "\n"
|
||||||
. 'const guac_rdp_keymap* GUAC_KEYMAPS[] = {' . "\n";
|
. 'const guac_rdp_keymap* GUAC_KEYMAPS[] = {' . "\n";
|
||||||
|
|
||||||
foreach $keymap (@keymaps) {
|
foreach my $keymap (@keymaps) {
|
||||||
print OUTPUT " &$keymap,\n";
|
print OUTPUT " &$keymap,\n";
|
||||||
}
|
}
|
||||||
print OUTPUT
|
print OUTPUT
|
||||||
|
Loading…
Reference in New Issue
Block a user