2010-08-19 00:15:29 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2010 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-09-24 07:19:57 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
#include <grub/util/misc.h>
|
|
|
|
#include <grub/i18n.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/keyboard_layouts.h>
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-02-03 20:45:43 +00:00
|
|
|
#include <argp.h>
|
2010-08-19 00:15:29 +00:00
|
|
|
#include <unistd.h>
|
2010-08-19 18:43:40 +00:00
|
|
|
#include <errno.h>
|
2010-08-19 00:15:29 +00:00
|
|
|
|
|
|
|
#include "progname.h"
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
struct arguments
|
|
|
|
{
|
|
|
|
char *input;
|
|
|
|
char *output;
|
|
|
|
int verbosity;
|
|
|
|
};
|
2010-08-19 00:15:29 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
static struct argp_option options[] = {
|
|
|
|
{"input", 'i', N_("FILE"), 0,
|
|
|
|
N_("set input filename. Default is STDIN"), 0},
|
|
|
|
{"output", 'o', N_("FILE"), 0,
|
|
|
|
N_("set output filename. Default is STDOUT"), 0},
|
2012-02-05 10:23:47 +00:00
|
|
|
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
|
2012-02-03 20:45:43 +00:00
|
|
|
{ 0, 0, 0, 0, 0, 0 }
|
2010-08-19 00:15:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct console_grub_equivalence
|
|
|
|
{
|
2012-02-10 12:42:00 +00:00
|
|
|
const char *layout;
|
2010-08-19 00:15:29 +00:00
|
|
|
grub_uint32_t grub;
|
|
|
|
};
|
|
|
|
|
2010-08-22 14:06:09 +00:00
|
|
|
static struct console_grub_equivalence console_grub_equivalences_shift[] = {
|
|
|
|
{"KP_0", '0'},
|
|
|
|
{"KP_1", '1'},
|
|
|
|
{"KP_2", '2'},
|
|
|
|
{"KP_3", '3'},
|
|
|
|
{"KP_4", '4'},
|
|
|
|
{"KP_5", '5'},
|
|
|
|
{"KP_6", '6'},
|
|
|
|
{"KP_7", '7'},
|
|
|
|
{"KP_8", '8'},
|
|
|
|
{"KP_9", '9'},
|
|
|
|
{"KP_Period", '.'},
|
2011-01-11 15:08:57 +00:00
|
|
|
|
|
|
|
{NULL, '\0'}
|
2010-08-22 14:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct console_grub_equivalence console_grub_equivalences_unshift[] = {
|
|
|
|
{"KP_0", GRUB_TERM_KEY_INSERT},
|
|
|
|
{"KP_1", GRUB_TERM_KEY_END},
|
|
|
|
{"KP_2", GRUB_TERM_KEY_DOWN},
|
|
|
|
{"KP_3", GRUB_TERM_KEY_NPAGE},
|
|
|
|
{"KP_4", GRUB_TERM_KEY_LEFT},
|
|
|
|
{"KP_5", GRUB_TERM_KEY_CENTER},
|
|
|
|
{"KP_6", GRUB_TERM_KEY_RIGHT},
|
|
|
|
{"KP_7", GRUB_TERM_KEY_HOME},
|
|
|
|
{"KP_8", GRUB_TERM_KEY_UP},
|
|
|
|
{"KP_9", GRUB_TERM_KEY_PPAGE},
|
|
|
|
{"KP_Period", GRUB_TERM_KEY_DC},
|
2011-01-11 15:08:57 +00:00
|
|
|
|
|
|
|
{NULL, '\0'}
|
2010-08-22 14:06:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct console_grub_equivalence console_grub_equivalences_common[] = {
|
2010-08-19 14:12:18 +00:00
|
|
|
{"Escape", GRUB_TERM_ESC},
|
|
|
|
{"Tab", GRUB_TERM_TAB},
|
|
|
|
{"Delete", GRUB_TERM_BACKSPACE},
|
|
|
|
|
2010-08-22 14:06:09 +00:00
|
|
|
{"KP_Enter", '\n'},
|
|
|
|
{"Return", '\n'},
|
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
{"KP_Multiply", '*'},
|
2010-08-19 17:17:36 +00:00
|
|
|
{"KP_Subtract", '-'},
|
2010-08-19 00:15:29 +00:00
|
|
|
{"KP_Add", '+'},
|
|
|
|
{"KP_Divide", '/'},
|
|
|
|
|
2010-08-19 17:17:36 +00:00
|
|
|
{"F1", GRUB_TERM_KEY_F1},
|
|
|
|
{"F2", GRUB_TERM_KEY_F2},
|
|
|
|
{"F3", GRUB_TERM_KEY_F3},
|
|
|
|
{"F4", GRUB_TERM_KEY_F4},
|
|
|
|
{"F5", GRUB_TERM_KEY_F5},
|
|
|
|
{"F6", GRUB_TERM_KEY_F6},
|
|
|
|
{"F7", GRUB_TERM_KEY_F7},
|
|
|
|
{"F8", GRUB_TERM_KEY_F8},
|
|
|
|
{"F9", GRUB_TERM_KEY_F9},
|
|
|
|
{"F10", GRUB_TERM_KEY_F10},
|
|
|
|
{"F11", GRUB_TERM_KEY_F11},
|
|
|
|
{"F12", GRUB_TERM_KEY_F12},
|
|
|
|
{"F13", GRUB_TERM_KEY_F1 | GRUB_TERM_SHIFT},
|
|
|
|
{"F14", GRUB_TERM_KEY_F2 | GRUB_TERM_SHIFT},
|
|
|
|
{"F15", GRUB_TERM_KEY_F3 | GRUB_TERM_SHIFT},
|
|
|
|
{"F16", GRUB_TERM_KEY_F4 | GRUB_TERM_SHIFT},
|
|
|
|
{"F17", GRUB_TERM_KEY_F5 | GRUB_TERM_SHIFT},
|
|
|
|
{"F18", GRUB_TERM_KEY_F6 | GRUB_TERM_SHIFT},
|
|
|
|
{"F19", GRUB_TERM_KEY_F7 | GRUB_TERM_SHIFT},
|
|
|
|
{"F20", GRUB_TERM_KEY_F8 | GRUB_TERM_SHIFT},
|
|
|
|
{"F21", GRUB_TERM_KEY_F9 | GRUB_TERM_SHIFT},
|
|
|
|
{"F22", GRUB_TERM_KEY_F10 | GRUB_TERM_SHIFT},
|
|
|
|
{"F23", GRUB_TERM_KEY_F11 | GRUB_TERM_SHIFT},
|
|
|
|
{"F24", GRUB_TERM_KEY_F12 | GRUB_TERM_SHIFT},
|
|
|
|
{"Console_13", GRUB_TERM_KEY_F1 | GRUB_TERM_ALT},
|
|
|
|
{"Console_14", GRUB_TERM_KEY_F2 | GRUB_TERM_ALT},
|
|
|
|
{"Console_15", GRUB_TERM_KEY_F3 | GRUB_TERM_ALT},
|
|
|
|
{"Console_16", GRUB_TERM_KEY_F4 | GRUB_TERM_ALT},
|
|
|
|
{"Console_17", GRUB_TERM_KEY_F5 | GRUB_TERM_ALT},
|
|
|
|
{"Console_18", GRUB_TERM_KEY_F6 | GRUB_TERM_ALT},
|
|
|
|
{"Console_19", GRUB_TERM_KEY_F7 | GRUB_TERM_ALT},
|
|
|
|
{"Console_20", GRUB_TERM_KEY_F8 | GRUB_TERM_ALT},
|
|
|
|
{"Console_21", GRUB_TERM_KEY_F9 | GRUB_TERM_ALT},
|
|
|
|
{"Console_22", GRUB_TERM_KEY_F10 | GRUB_TERM_ALT},
|
|
|
|
{"Console_23", GRUB_TERM_KEY_F11 | GRUB_TERM_ALT},
|
|
|
|
{"Console_24", GRUB_TERM_KEY_F12 | GRUB_TERM_ALT},
|
|
|
|
{"Console_25", GRUB_TERM_KEY_F1 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_26", GRUB_TERM_KEY_F2 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_27", GRUB_TERM_KEY_F3 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_28", GRUB_TERM_KEY_F4 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_29", GRUB_TERM_KEY_F5 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_30", GRUB_TERM_KEY_F6 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_31", GRUB_TERM_KEY_F7 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_32", GRUB_TERM_KEY_F8 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_33", GRUB_TERM_KEY_F9 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_34", GRUB_TERM_KEY_F10 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_35", GRUB_TERM_KEY_F11 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
{"Console_36", GRUB_TERM_KEY_F12 | GRUB_TERM_SHIFT | GRUB_TERM_ALT},
|
|
|
|
|
|
|
|
{"Insert", GRUB_TERM_KEY_INSERT},
|
|
|
|
{"Down", GRUB_TERM_KEY_DOWN},
|
|
|
|
{"Up", GRUB_TERM_KEY_UP},
|
|
|
|
{"Home", GRUB_TERM_KEY_HOME},
|
|
|
|
{"End", GRUB_TERM_KEY_END},
|
|
|
|
{"Right", GRUB_TERM_KEY_RIGHT},
|
|
|
|
{"Left", GRUB_TERM_KEY_LEFT},
|
2010-08-22 14:06:09 +00:00
|
|
|
{"Next", GRUB_TERM_KEY_NPAGE},
|
|
|
|
{"Prior", GRUB_TERM_KEY_PPAGE},
|
|
|
|
{"Remove", GRUB_TERM_KEY_DC},
|
2010-08-19 17:17:36 +00:00
|
|
|
{"VoidSymbol", 0},
|
|
|
|
|
|
|
|
/* "Undead" keys since no dead key support in GRUB. */
|
|
|
|
{"dead_acute", '\''},
|
|
|
|
{"dead_circumflex", '^'},
|
|
|
|
{"dead_grave", '`'},
|
|
|
|
{"dead_tilde", '~'},
|
|
|
|
{"dead_diaeresis", '"'},
|
|
|
|
|
|
|
|
/* Following ones don't provide any useful symbols for shell. */
|
|
|
|
{"dead_cedilla", 0},
|
|
|
|
{"dead_ogonek", 0},
|
|
|
|
{"dead_caron", 0},
|
|
|
|
{"dead_breve", 0},
|
|
|
|
{"dead_doubleacute", 0},
|
|
|
|
|
|
|
|
/* Unused in GRUB. */
|
|
|
|
{"Pause", 0},
|
|
|
|
{"Scroll_Forward", 0},
|
|
|
|
{"Scroll_Backward", 0},
|
|
|
|
{"Hex_0", 0},
|
|
|
|
{"Hex_1", 0},
|
|
|
|
{"Hex_2", 0},
|
|
|
|
{"Hex_3", 0},
|
|
|
|
{"Hex_4", 0},
|
|
|
|
{"Hex_5", 0},
|
|
|
|
{"Hex_6", 0},
|
|
|
|
{"Hex_7", 0},
|
|
|
|
{"Hex_8", 0},
|
|
|
|
{"Hex_9", 0},
|
|
|
|
{"Hex_A", 0},
|
|
|
|
{"Hex_B", 0},
|
|
|
|
{"Hex_C", 0},
|
|
|
|
{"Hex_D", 0},
|
|
|
|
{"Hex_E", 0},
|
|
|
|
{"Hex_F", 0},
|
|
|
|
{"Scroll_Lock", 0},
|
|
|
|
{"Show_Memory", 0},
|
|
|
|
{"Show_Registers", 0},
|
|
|
|
{"Control_backslash", 0},
|
2010-08-19 23:23:33 +00:00
|
|
|
{"Compose", 0},
|
2010-08-19 17:17:36 +00:00
|
|
|
|
|
|
|
{NULL, '\0'}
|
2010-08-19 00:15:29 +00:00
|
|
|
};
|
|
|
|
|
2010-08-22 20:53:31 +00:00
|
|
|
static grub_uint8_t linux_to_usb_map[128] = {
|
2010-08-22 21:56:41 +00:00
|
|
|
/* 0x00 */ 0 /* Unused */, GRUB_KEYBOARD_KEY_ESCAPE,
|
|
|
|
/* 0x02 */ GRUB_KEYBOARD_KEY_1, GRUB_KEYBOARD_KEY_2,
|
|
|
|
/* 0x04 */ GRUB_KEYBOARD_KEY_3, GRUB_KEYBOARD_KEY_4,
|
|
|
|
/* 0x06 */ GRUB_KEYBOARD_KEY_5, GRUB_KEYBOARD_KEY_6,
|
|
|
|
/* 0x08 */ GRUB_KEYBOARD_KEY_7, GRUB_KEYBOARD_KEY_8,
|
|
|
|
/* 0x0a */ GRUB_KEYBOARD_KEY_9, GRUB_KEYBOARD_KEY_0,
|
|
|
|
/* 0x0c */ GRUB_KEYBOARD_KEY_DASH, GRUB_KEYBOARD_KEY_EQUAL,
|
|
|
|
/* 0x0e */ GRUB_KEYBOARD_KEY_BACKSPACE, GRUB_KEYBOARD_KEY_TAB,
|
|
|
|
/* 0x10 */ GRUB_KEYBOARD_KEY_Q, GRUB_KEYBOARD_KEY_W,
|
|
|
|
/* 0x12 */ GRUB_KEYBOARD_KEY_E, GRUB_KEYBOARD_KEY_R,
|
|
|
|
/* 0x14 */ GRUB_KEYBOARD_KEY_T, GRUB_KEYBOARD_KEY_Y,
|
|
|
|
/* 0x16 */ GRUB_KEYBOARD_KEY_U, GRUB_KEYBOARD_KEY_I,
|
|
|
|
/* 0x18 */ GRUB_KEYBOARD_KEY_O, GRUB_KEYBOARD_KEY_P,
|
|
|
|
/* 0x1a */ GRUB_KEYBOARD_KEY_LBRACKET, GRUB_KEYBOARD_KEY_RBRACKET,
|
|
|
|
/* 0x1c */ GRUB_KEYBOARD_KEY_ENTER, GRUB_KEYBOARD_KEY_LEFT_CTRL,
|
|
|
|
/* 0x1e */ GRUB_KEYBOARD_KEY_A, GRUB_KEYBOARD_KEY_S,
|
|
|
|
/* 0x20 */ GRUB_KEYBOARD_KEY_D, GRUB_KE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ARD_KEY_LEFT,
|
2010-08-22 21:56:41 +00:00
|
|
|
/* 0x6a */ GRUB_KEYBOARD_KEY_RIGHT, GRUB_KEYBOARD_KEY_END,
|
2010-08-23 18:40:06 +00:00
|
|
|
/* 0x6c */ GRUB_KEYBOARD_KEY_DOWN, GRUB_KEYBOARD_KEY_NPAGE,
|
2010-08-22 21:56:41 +00:00
|
|
|
/* 0x6e */ GRUB_KEYBOARD_KEY_INSERT, GRUB_KEYBOARD_KEY_DELETE
|
2010-08-22 20:53:31 +00:00
|
|
|
};
|
|
|
|
|
2010-08-22 14:06:09 +00:00
|
|
|
static void
|
2010-08-19 13:00:31 +00:00
|
|
|
add_special_keys (struct grub_keyboard_layout *layout)
|
|
|
|
{
|
2010-08-22 14:06:09 +00:00
|
|
|
(void) layout;
|
2010-08-19 13:00:31 +00:00
|
|
|
}
|
|
|
|
|
2010-08-20 21:33:41 +00:00
|
|
|
static unsigned
|
2010-08-22 14:06:09 +00:00
|
|
|
lookup (char *code, int shift)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-08-22 14:06:09 +00:00
|
|
|
struct console_grub_equivalence *pr;
|
|
|
|
|
|
|
|
if (shift)
|
|
|
|
pr = console_grub_equivalences_shift;
|
|
|
|
else
|
|
|
|
pr = console_grub_equivalences_unshift;
|
2010-08-19 00:15:29 +00:00
|
|
|
|
2010-08-22 14:06:09 +00:00
|
|
|
for (i = 0; pr[i].layout != NULL; i++)
|
|
|
|
if (strcmp (code, pr[i].layout) == 0)
|
|
|
|
return pr[i].grub;
|
|
|
|
|
|
|
|
for (i = 0; console_grub_equivalences_common[i].layout != NULL; i++)
|
|
|
|
if (strcmp (code, console_grub_equivalences_common[i].layout) == 0)
|
|
|
|
return console_grub_equivalences_common[i].grub;
|
2010-08-19 00:15:29 +00:00
|
|
|
|
2012-03-02 14:09:10 +00:00
|
|
|
/* TRANSLATORS: scan identifier is keyboard key symbolic name. */
|
2012-02-08 18:26:01 +00:00
|
|
|
fprintf (stderr, _("Unknown keyboard scan identifier %s\n"), code);
|
2010-08-19 17:17:36 +00:00
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
return '\0';
|
|
|
|
}
|
|
|
|
|
2010-08-19 13:00:31 +00:00
|
|
|
static unsigned int
|
2010-08-22 14:06:09 +00:00
|
|
|
get_grub_code (char *layout_code, int shift)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
|
|
|
unsigned int code;
|
|
|
|
|
|
|
|
if (strncmp (layout_code, "U+", sizeof ("U+") - 1) == 0)
|
|
|
|
sscanf (layout_code, "U+%x", &code);
|
|
|
|
else if (strncmp (layout_code, "+U+", sizeof ("+U+") - 1) == 0)
|
|
|
|
sscanf (layout_code, "+U+%x", &code);
|
|
|
|
else
|
2010-08-22 14:06:09 +00:00
|
|
|
code = lookup (layout_code, shift);
|
2010-08-19 00:15:29 +00:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2010-08-19 13:00:31 +00:00
|
|
|
static void
|
2010-08-19 18:43:40 +00:00
|
|
|
write_file (FILE *out, struct grub_keyboard_layout *layout)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
|
|
|
grub_uint32_t version;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
version = grub_cpu_to_le32 (GRUB_KEYBOARD_LAYOUTS_VERSION);
|
|
|
|
|
2010-08-19 13:32:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map); i++)
|
|
|
|
layout->keyboard_map[i] = grub_cpu_to_le32(layout->keyboard_map[i]);
|
2010-08-19 13:00:31 +00:00
|
|
|
|
2010-08-19 13:32:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_shift); i++)
|
|
|
|
layout->keyboard_map_shift[i]
|
|
|
|
= grub_cpu_to_le32(layout->keyboard_map_shift[i]);
|
2010-08-19 13:00:31 +00:00
|
|
|
|
2010-08-19 13:32:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_l3); i++)
|
|
|
|
layout->keyboard_map_l3[i]
|
|
|
|
= grub_cpu_to_le32(layout->keyboard_map_l3[i]);
|
2010-08-19 13:00:31 +00:00
|
|
|
|
2010-08-19 13:32:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE (layout->keyboard_map_shift_l3); i++)
|
|
|
|
layout->keyboard_map_shift_l3[i]
|
|
|
|
= grub_cpu_to_le32(layout->keyboard_map_shift_l3[i]);
|
2010-08-19 09:44:49 +00:00
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
|
2010-08-19 18:43:40 +00:00
|
|
|
GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out);
|
|
|
|
fwrite (&version, sizeof (version), 1, out);
|
|
|
|
fwrite (layout, 1, sizeof (*layout), out);
|
2010-08-19 00:15:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-19 13:00:31 +00:00
|
|
|
static void
|
2010-08-19 18:43:40 +00:00
|
|
|
write_keymaps (FILE *in, FILE *out)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
2010-08-19 13:00:31 +00:00
|
|
|
struct grub_keyboard_layout layout;
|
2010-08-19 00:15:29 +00:00
|
|
|
char line[2048];
|
|
|
|
int ok;
|
|
|
|
|
2010-08-19 13:00:31 +00:00
|
|
|
memset (&layout, 0, sizeof (layout));
|
2010-08-19 00:15:29 +00:00
|
|
|
|
|
|
|
/* Process the ckbcomp output and prepare the layouts. */
|
|
|
|
ok = 0;
|
2010-08-19 18:43:40 +00:00
|
|
|
while (fgets (line, sizeof (line), in))
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
|
|
|
if (strncmp (line, "keycode", sizeof ("keycode") - 1) == 0)
|
|
|
|
{
|
2010-08-22 20:53:31 +00:00
|
|
|
unsigned keycode_linux;
|
2010-08-22 14:06:09 +00:00
|
|
|
unsigned keycode_usb;
|
2010-08-19 00:15:29 +00:00
|
|
|
char normal[64];
|
|
|
|
char shift[64];
|
2010-08-19 09:44:49 +00:00
|
|
|
char normalalt[64];
|
|
|
|
char shiftalt[64];
|
2010-08-22 20:53:31 +00:00
|
|
|
|
|
|
|
sscanf (line, "keycode %u = %60s %60s %60s %60s", &keycode_linux,
|
2010-08-19 09:44:49 +00:00
|
|
|
normal, shift, normalalt, shiftalt);
|
2010-08-22 14:06:09 +00:00
|
|
|
|
|
|
|
/* Not used. */
|
2010-08-22 20:53:31 +00:00
|
|
|
if (keycode_linux == 0x77 /* Pause */
|
2010-08-22 14:06:09 +00:00
|
|
|
/* Some obscure keys */
|
2010-08-22 20:53:31 +00:00
|
|
|
|| keycode_linux == 0x63 || keycode_linux == 0x7d
|
|
|
|
|| keycode_linux == 0x7e)
|
2010-08-22 14:06:09 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Not remappable. */
|
2010-08-22 20:53:31 +00:00
|
|
|
if (keycode_linux == 0x1d /* Left CTRL */
|
2010-08-23 11:21:26 +00:00
|
|
|
|| keycode_linux == 0x61 /* Right CTRL */
|
2010-08-22 20:53:31 +00:00
|
|
|
|| keycode_linux == 0x2a /* Left Shift. */
|
|
|
|
|| keycode_linux == 0x36 /* Right Shift. */
|
|
|
|
|| keycode_linux == 0x38 /* Left ALT. */
|
2010-08-23 11:21:26 +00:00
|
|
|
|| keycode_linux == 0x64 /* Right ALT. */
|
2010-08-22 20:53:31 +00:00
|
|
|
|| keycode_linux == 0x3a /* CapsLock. */
|
|
|
|
|| keycode_linux == 0x45 /* NumLock. */
|
|
|
|
|| keycode_linux == 0x46 /* ScrollLock. */)
|
2010-08-22 14:06:09 +00:00
|
|
|
continue;
|
|
|
|
|
2010-08-22 20:53:31 +00:00
|
|
|
keycode_usb = linux_to_usb_map[keycode_linux];
|
2010-08-22 14:06:09 +00:00
|
|
|
if (keycode_usb == 0
|
|
|
|
|| keycode_usb >= GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
|
|
|
|
{
|
2012-03-02 14:09:10 +00:00
|
|
|
/* TRANSLATORS: scan code is keyboard key numeric identifier. */
|
2012-02-08 18:26:01 +00:00
|
|
|
fprintf (stderr, _("Unknown keyboard scan code 0x%02x\n"), keycode_linux);
|
2010-08-22 14:06:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (keycode_usb < GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
|
2010-08-19 13:00:31 +00:00
|
|
|
{
|
2010-08-22 14:06:09 +00:00
|
|
|
layout.keyboard_map[keycode_usb] = get_grub_code (normal, 0);
|
|
|
|
layout.keyboard_map_shift[keycode_usb] = get_grub_code (shift, 1);
|
|
|
|
layout.keyboard_map_l3[keycode_usb]
|
|
|
|
= get_grub_code (normalalt, 0);
|
|
|
|
layout.keyboard_map_shift_l3[keycode_usb]
|
|
|
|
= get_grub_code (shiftalt, 1);
|
2010-08-19 13:00:31 +00:00
|
|
|
ok = 1;
|
|
|
|
}
|
2010-08-19 00:15:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ok == 0)
|
|
|
|
{
|
2012-03-02 14:09:10 +00:00
|
|
|
/* TRANSLATORS: this error is triggered when input doesn't contain any
|
|
|
|
key descriptions. */
|
2012-02-08 18:26:01 +00:00
|
|
|
fprintf (stderr, "%s", _("ERROR: no valid keyboard layout found. Check the input.\n"));
|
2010-08-19 00:15:29 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2010-08-19 13:00:31 +00:00
|
|
|
add_special_keys (&layout);
|
|
|
|
|
2010-08-19 18:43:40 +00:00
|
|
|
write_file (out, &layout);
|
2010-08-19 00:15:29 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
static error_t
|
|
|
|
argp_parser (int key, char *arg, struct argp_state *state)
|
|
|
|
{
|
|
|
|
/* Get the input argument from argp_parse, which we
|
|
|
|
know is a pointer to our arguments structure. */
|
|
|
|
struct arguments *arguments = state->input;
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case 'i':
|
|
|
|
arguments->input = xstrdup (arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
arguments->output = xstrdup (arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
arguments->verbosity++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return ARGP_ERR_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct argp argp = {
|
|
|
|
options, argp_parser, N_("[OPTIONS]"),
|
2012-03-05 15:42:26 +00:00
|
|
|
/* TRANSLATORS: "one" is a shortcut for "keyboard layout". */
|
2012-02-03 20:45:43 +00:00
|
|
|
N_("Generate GRUB keyboard layout from Linux console one."),
|
|
|
|
NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
2010-08-19 00:15:29 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-08-19 18:43:40 +00:00
|
|
|
FILE *in, *out;
|
2012-02-03 20:45:43 +00:00
|
|
|
struct arguments arguments;
|
2010-08-19 00:15:29 +00:00
|
|
|
|
|
|
|
set_program_name (argv[0]);
|
|
|
|
|
|
|
|
/* Check for options. */
|
2012-02-03 20:45:43 +00:00
|
|
|
memset (&arguments, 0, sizeof (struct arguments));
|
|
|
|
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
2012-02-03 20:45:43 +00:00
|
|
|
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
|
|
|
|
exit(1);
|
2010-08-19 00:15:29 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
if (arguments.input)
|
|
|
|
in = fopen (arguments.input, "r");
|
2010-08-19 18:43:40 +00:00
|
|
|
else
|
|
|
|
in = stdin;
|
|
|
|
|
|
|
|
if (!in)
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_error (_("cannot open `%s': %s"), arguments.input ? : "stdin",
|
|
|
|
strerror (errno));
|
2010-08-19 00:15:29 +00:00
|
|
|
|
2012-02-03 20:45:43 +00:00
|
|
|
if (arguments.output)
|
|
|
|
out = fopen (arguments.output, "wb");
|
2010-08-19 18:43:40 +00:00
|
|
|
else
|
|
|
|
out = stdout;
|
|
|
|
|
|
|
|
if (!out)
|
2010-08-19 00:15:29 +00:00
|
|
|
{
|
2010-08-19 18:43:40 +00:00
|
|
|
if (in != stdin)
|
|
|
|
fclose (in);
|
2012-02-05 10:07:33 +00:00
|
|
|
grub_util_error (_("cannot open `%s': %s"), arguments.output ? : "stdout",
|
|
|
|
strerror (errno));
|
2010-08-19 00:15:29 +00:00
|
|
|
}
|
2010-08-19 18:43:40 +00:00
|
|
|
|
|
|
|
write_keymaps (in, out);
|
|
|
|
|
|
|
|
if (in != stdin)
|
|
|
|
fclose (in);
|
|
|
|
|
|
|
|
if (out != stdout)
|
|
|
|
fclose (out);
|
2010-08-19 00:15:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|