Generate one file.

This commit is contained in:
Michael Jumper 2014-01-02 21:54:17 -08:00
parent b805e35ca7
commit b840935530
2 changed files with 50 additions and 100 deletions

View File

@ -1,3 +1,2 @@
# Autogenerated code # Autogenerated code
*.c *.c
*.h

View File

@ -34,35 +34,28 @@ sub keymap_symbol {
return 'guac_rdp_keymap_' . $_; return 'guac_rdp_keymap_' . $_;
} }
sub keymap_file { #
my $_ = shift; # rdp_keymap.c
s/-/_/g; #
return 'rdp_keymap_' . $_;
}
@keymaps = (); @keymaps = ();
# open OUTPUT, ">", "rdp_keymaps.c";
# rdp_keymap_*.c print OUTPUT
# '#include "config.h"' . "\n"
. '#include "rdp_keymap.h"' . "\n"
. '#include <freerdp/input.h>' . "\n"
. "\n"
. '#ifdef HAVE_FREERDP_LOCALE_KEYBOARD_H' . "\n"
. '#include <freerdp/locale/keyboard.h>' . "\n"
. '#else' . "\n"
. '#include <freerdp/kbd/layouts.h>' . "\n"
. '#endif' . "\n"
. "\n";
for $filename (@ARGV) { for $filename (@ARGV) {
# Header $content = "";
$src = '/* Autogenerated from ' . $filename . ' */' . "\n"
. "\n"
. '#include "config.h"' . "\n"
. '#include "rdp_keymap.h"' . "\n"
. '#include <freerdp/input.h>' . "\n"
. "\n"
. '#ifdef HAVE_FREERDP_LOCALE_KEYBOARD_H' . "\n"
. '#include <freerdp/locale/keyboard.h>' . "\n"
. '#else' . "\n"
. '#include <freerdp/kbd/layouts.h>' . "\n"
. '#endif' . "\n"
. "\n"
. 'static guac_rdp_keysym_desc __keymap[] = {' . "\n";
$parent = ""; $parent = "";
$layout_name = ""; $layout_name = "";
$freerdp = ""; $freerdp = "";
@ -175,38 +168,38 @@ for $filename (@ARGV) {
# Write keysym/scancode pairs # Write keysym/scancode pairs
for ($i=0; $i<=$#keysyms; $i++) { for ($i=0; $i<=$#keysyms; $i++) {
$src .= " {" $content .= " {"
. " .keysym = " . $keysyms[$i] . "," . " .keysym = " . $keysyms[$i] . ","
. " .scancode = " . $scancodes[$i]; . " .scancode = " . $scancodes[$i];
# Set requirements # Set requirements
if ($set_shift && !$set_altgr) { if ($set_shift && !$set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT"; $content .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT";
} }
elsif (!$set_shift && $set_altgr) { elsif (!$set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_ALTGR"; $content .= ", .set_keysyms = GUAC_KEYSYMS_ALTGR";
} }
elsif ($set_shift && $set_altgr) { elsif ($set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT_ALTGR"; $content .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT_ALTGR";
} }
# Clear requirements # Clear requirements
if ($clear_shift && !$clear_altgr) { if ($clear_shift && !$clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT"; $content .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT";
} }
elsif (!$clear_shift && $clear_altgr) { elsif (!$clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALTGR"; $content .= ", .clear_keysyms = GUAC_KEYSYMS_ALTGR";
} }
elsif ($clear_shift && $clear_altgr) { elsif ($clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT_ALTGR"; $content .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT_ALTGR";
} }
# Flags # Flags
if ($ext_flags) { if ($ext_flags) {
$src .= ", .flags = KBD_FLAGS_EXTENDED"; $content .= ", .flags = KBD_FLAGS_EXTENDED";
} }
$src .= " },\n"; $content .= " },\n";
} }
@ -221,94 +214,52 @@ for $filename (@ARGV) {
} }
close INPUT; close INPUT;
# Map footer # Header
$src .= ' {0}' . "\n" $sym = keymap_symbol($layout_name);
. '};' . "\n"; print OUTPUT
"\n"
. '/* Autogenerated from ' . $filename . ' */' . "\n"
. 'static guac_rdp_keysym_desc __' . $sym . '[] = {' . "\n"
. $content
. ' {0}' . "\n"
. '};' . "\n";
# Desc header # Desc header
$keymap_sym = keymap_symbol($layout_name); print OUTPUT "\n"
$src .= "\n" . 'static const guac_rdp_keymap ' . $sym . ' = { ' . "\n";
. 'const guac_rdp_keymap ' . $keymap_sym . '[] = { ' . "\n";
# Layout name # Layout name
$src .= " .name = \"$layout_name\",\n"; print OUTPUT " .name = \"$layout_name\",\n";
# Parent layout (if any) # Parent layout (if any)
if ($parent) { if ($parent) {
$src .= " .parent = $parent,\n"; print OUTPUT " .parent = $parent,\n";
} }
# FreeRDP layout (if any) # FreeRDP layout (if any)
if ($freerdp) { if ($freerdp) {
$src .= " .freerdp_keyboard_layout = $freerdp,\n"; print OUTPUT " .freerdp_keyboard_layout = $freerdp,\n";
} }
# Desc footer # Desc footer
$src .= ' .mapping = __keymap' . "\n" print OUTPUT
' .mapping = __' . $sym . "\n"
. '};' . "\n"; . '};' . "\n";
$keymaps[++$#keymaps] = $layout_name; $keymaps[++$#keymaps] = $sym;
$filename = keymap_file($layout_name) . '.c'; print STDERR "Added: $layout_name\n";
# Write output
open OUTPUT, ">", "$filename";
print OUTPUT "$src";
close OUTPUT;
print STDERR "Generated \"$filename\".\n";
} }
# print OUTPUT "\n"
# rdp_keymaps.h . 'const guac_rdp_keymap guac_rdp_keymaps[] = {' . "\n";
#
print STDERR "Writing main keymap header... (\"rdp_keymaps.h\")\n";
open OUTPUT, ">", "rdp_keymaps.h";
# Header
print OUTPUT
'#ifndef _GUAC_RDP_KEYMAPS' . "\n"
. '#define _GUAC_RDP_KEYMAPS' . "\n"
. "\n"
. '#include "rdp_keymap.h"' . "\n"
. "\n"
. 'extern const guac_rdp_keymap* guac_rdp_keymaps[];' . "\n";
# Write list of keymaps
foreach $keymap (@keymaps) { foreach $keymap (@keymaps) {
$sym = keymap_symbol($keymap); print OUTPUT " $keymap,\n";
print OUTPUT "extern const guac_rdp_keymap $sym;\n";
} }
# Footer
print OUTPUT print OUTPUT
"\n" ' NULL' . "\n"
. '#endif' . "\n"; . '};' . "\n";
close OUTPUT; close OUTPUT;
#
# rdp_keymaps.c
#
print STDERR "Writing main keymap source... (\"rdp_keymaps.c\")\n";
open OUTPUT, ">", "rdp_keymaps.c";
# Header
print OUTPUT
'#include "rdp_keymaps.h"' . "\n"
. "\n"
. 'const guac_rdp_keymap* guac_rdp_keymaps[] = {' . "\n";
# Write list of keymaps
foreach $keymap (@keymaps) {
$sym = keymap_symbol($keymap);
print OUTPUT " &$sym,\n";
}
# Footer
print OUTPUT
' NULL' . "\n"
. '};' . "\n";
close OUTPUT;