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
*.c
*.h

View File

@ -34,24 +34,15 @@ sub keymap_symbol {
return 'guac_rdp_keymap_' . $_;
}
sub keymap_file {
my $_ = shift;
s/-/_/g;
return 'rdp_keymap_' . $_;
}
#
# rdp_keymap.c
#
@keymaps = ();
#
# rdp_keymap_*.c
#
for $filename (@ARGV) {
# Header
$src = '/* Autogenerated from ' . $filename . ' */' . "\n"
. "\n"
. '#include "config.h"' . "\n"
open OUTPUT, ">", "rdp_keymaps.c";
print OUTPUT
'#include "config.h"' . "\n"
. '#include "rdp_keymap.h"' . "\n"
. '#include <freerdp/input.h>' . "\n"
. "\n"
@ -60,9 +51,11 @@ for $filename (@ARGV) {
. '#else' . "\n"
. '#include <freerdp/kbd/layouts.h>' . "\n"
. '#endif' . "\n"
. "\n"
. 'static guac_rdp_keysym_desc __keymap[] = {' . "\n";
. "\n";
for $filename (@ARGV) {
$content = "";
$parent = "";
$layout_name = "";
$freerdp = "";
@ -175,38 +168,38 @@ for $filename (@ARGV) {
# Write keysym/scancode pairs
for ($i=0; $i<=$#keysyms; $i++) {
$src .= " {"
$content .= " {"
. " .keysym = " . $keysyms[$i] . ","
. " .scancode = " . $scancodes[$i];
# Set requirements
if ($set_shift && !$set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT";
$content .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT";
}
elsif (!$set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_ALTGR";
$content .= ", .set_keysyms = GUAC_KEYSYMS_ALTGR";
}
elsif ($set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT_ALTGR";
$content .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT_ALTGR";
}
# Clear requirements
if ($clear_shift && !$clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT";
$content .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT";
}
elsif (!$clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALTGR";
$content .= ", .clear_keysyms = GUAC_KEYSYMS_ALTGR";
}
elsif ($clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT_ALTGR";
$content .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT_ALTGR";
}
# 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;
# Map footer
$src .= ' {0}' . "\n"
# Header
$sym = keymap_symbol($layout_name);
print OUTPUT
"\n"
. '/* Autogenerated from ' . $filename . ' */' . "\n"
. 'static guac_rdp_keysym_desc __' . $sym . '[] = {' . "\n"
. $content
. ' {0}' . "\n"
. '};' . "\n";
# Desc header
$keymap_sym = keymap_symbol($layout_name);
$src .= "\n"
. 'const guac_rdp_keymap ' . $keymap_sym . '[] = { ' . "\n";
print OUTPUT "\n"
. 'static const guac_rdp_keymap ' . $sym . ' = { ' . "\n";
# Layout name
$src .= " .name = \"$layout_name\",\n";
print OUTPUT " .name = \"$layout_name\",\n";
# Parent layout (if any)
if ($parent) {
$src .= " .parent = $parent,\n";
print OUTPUT " .parent = $parent,\n";
}
# FreeRDP layout (if any)
if ($freerdp) {
$src .= " .freerdp_keyboard_layout = $freerdp,\n";
print OUTPUT " .freerdp_keyboard_layout = $freerdp,\n";
}
# Desc footer
$src .= ' .mapping = __keymap' . "\n"
print OUTPUT
' .mapping = __' . $sym . "\n"
. '};' . "\n";
$keymaps[++$#keymaps] = $layout_name;
$filename = keymap_file($layout_name) . '.c';
# Write output
open OUTPUT, ">", "$filename";
print OUTPUT "$src";
close OUTPUT;
print STDERR "Generated \"$filename\".\n";
$keymaps[++$#keymaps] = $sym;
print STDERR "Added: $layout_name\n";
}
#
# rdp_keymaps.h
#
print OUTPUT "\n"
. '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) {
$sym = keymap_symbol($keymap);
print OUTPUT "extern const guac_rdp_keymap $sym;\n";
print OUTPUT " $keymap,\n";
}
# Footer
print OUTPUT
"\n"
. '#endif' . "\n";
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;