From d041c1aaaba329cc985ea27a98d41369598609c5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 3 Jan 2014 01:03:57 -0800 Subject: [PATCH] Fix Unicode support in generator. --- src/protocols/rdp/keymaps/generate.pl | 58 ++++++++++++++------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/protocols/rdp/keymaps/generate.pl b/src/protocols/rdp/keymaps/generate.pl index 2f291e32..f96787ea 100755 --- a/src/protocols/rdp/keymaps/generate.pl +++ b/src/protocols/rdp/keymaps/generate.pl @@ -28,6 +28,8 @@ # into the RDP plugin source. # +use 5.012; + sub keymap_symbol { my $_ = shift; s/-/_/g; @@ -38,7 +40,7 @@ sub keymap_symbol { # _generated_keymaps.c # -@keymaps = (); +my @keymaps = (); open OUTPUT, ">", "_generated_keymaps.c"; print OUTPUT @@ -53,15 +55,16 @@ print OUTPUT . '#endif' . "\n" . "\n"; -for $filename (@ARGV) { +for my $filename (@ARGV) { - $content = ""; - $parent = ""; - $layout_name = ""; - $freerdp = ""; + my $content = ""; + my $parent = ""; + my $layout_name = ""; + my $freerdp = ""; # Parse file open INPUT, '<', "$filename"; + binmode INPUT, ":encoding(utf8)"; while () { chomp; @@ -70,39 +73,39 @@ for $filename (@ARGV) { if (m/^\s*#/) {} # Name - elsif (($name) = m/^\s*name\s+"(.*)"\s*(?:#.*)?$/) { + elsif ((my $name) = m/^\s*name\s+"(.*)"\s*(?:#.*)?$/) { $layout_name = $name; } # Parent map - elsif (($name) = m/^\s*parent\s+"(.*)"\s*(?:#.*)?$/) { + elsif ((my $name) = m/^\s*parent\s+"(.*)"\s*(?:#.*)?$/) { $parent = keymap_symbol($name); } # FreeRDP equiv - elsif (($name) = m/^\s*freerdp\s+"(.*)"\s*(?:#.*)?$/) { + elsif ((my $name) = m/^\s*freerdp\s+"(.*)"\s*(?:#.*)?$/) { $freerdp = $name; } # Map - elsif (($range, $onto) = + elsif ((my $range, my $onto) = m/^\s*map\s+([^~]*)\s+~\s+(".*"|0x[0-9A-Fa-f]+)\s*(?:#.*)?$/) { - @keysyms = (); - @scancodes = (); + my @keysyms = (); + my @scancodes = (); - $ext_flags = 0; - $set_shift = 0; - $set_altgr = 0; + my $ext_flags = 0; + my $set_shift = 0; + my $set_altgr = 0; - $clear_shift = 0; - $clear_altgr = 0; + my $clear_shift = 0; + my $clear_altgr = 0; # Parse ranges and options foreach $_ (split(/\s+/, $range)) { # Set option/modifier - if (($opt) = m/^\+([a-z]+)$/) { + if ((my $opt) = m/^\+([a-z]+)$/) { if ($opt eq "shift") { $set_shift = 1; } elsif ($opt eq "altgr") { $set_altgr = 1; } elsif ($opt eq "ext") { $ext_flags = 1; } @@ -113,7 +116,7 @@ for $filename (@ARGV) { } # Clear option/modifier - elsif (($opt) = m/^-([a-z]+)$/) { + elsif ((my $opt) = m/^-([a-z]+)$/) { if ($opt eq "shift") { $clear_shift = 1; } elsif ($opt eq "altgr") { $clear_altgr = 1; } else { @@ -123,14 +126,14 @@ for $filename (@ARGV) { } # Single scancode - elsif (($scancode) = m/^(0x[0-9A-Fa-f]+)$/) { + elsif ((my $scancode) = m/^(0x[0-9A-Fa-f]+)$/) { $scancodes[++$#scancodes] = hex($scancode); } # Range of scancodes - elsif (($start, $end) = + elsif ((my $start, my $end) = 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; } } @@ -148,8 +151,9 @@ for $filename (@ARGV) { $keysyms[0] = hex($onto); } else { - foreach $char (split("", substr($onto, 1, length($onto)-2))) { - $codepoint = unpack('U0U*', $char); + foreach my $char (split('', + substr($onto, 1, length($onto)-2))) { + my $codepoint = ord($char); if ($codepoint >= 0x0100) { $keysyms[++$#keysyms] = 0x01000000 | $codepoint; } @@ -166,7 +170,7 @@ for $filename (@ARGV) { } # Write keysym/scancode pairs - for ($i=0; $i<=$#keysyms; $i++) { + for (my $i=0; $i<=$#keysyms; $i++) { $content .= " {" . " .keysym = " . $keysyms[$i] . "," @@ -215,7 +219,7 @@ for $filename (@ARGV) { close INPUT; # Header - $sym = keymap_symbol($layout_name); + my $sym = keymap_symbol($layout_name); print OUTPUT "\n" . '/* Autogenerated from ' . $filename . ' */' . "\n" @@ -254,7 +258,7 @@ for $filename (@ARGV) { print OUTPUT "\n" . 'const guac_rdp_keymap* GUAC_KEYMAPS[] = {' . "\n"; -foreach $keymap (@keymaps) { +foreach my $keymap (@keymaps) { print OUTPUT " &$keymap,\n"; } print OUTPUT