]> git.proxmox.com Git - grub2.git/blobdiff - util/grub-mklayout.c
* grub-core/genmod.sh.in: Strip before converting to ELF as strip
[grub2.git] / util / grub-mklayout.c
index 6b85ef87f293d1c5b0510b11299992ab57ec6e93..b90546e12a90088a7e6e7a0e7ef22b8ae34ca91d 100644 (file)
@@ -46,13 +46,13 @@ static struct argp_option options[] = {
    N_("set input filename. Default is STDIN"), 0},
   {"output",  'o', N_("FILE"), 0,
    N_("set output filename. Default is STDOUT"), 0},
-  {"verbose",     'v', 0,      0, N_("Print verbose messages."), 0},
+  {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
 
 struct console_grub_equivalence
 {
-  char *layout;
+  const char *layout;
   grub_uint32_t grub;
 };
 
@@ -250,7 +250,7 @@ static grub_uint8_t linux_to_usb_map[128] = {
   /* 0x52 */ GRUB_KEYBOARD_KEY_NUMDOT,      GRUB_KEYBOARD_KEY_NUMDOT, 
   /* 0x54 */ 0,                             0, 
   /* 0x56 */ GRUB_KEYBOARD_KEY_102ND,       GRUB_KEYBOARD_KEY_F11, 
-  /* 0x58 */ GRUB_KEYBOARD_KEY_F12,         0,
+  /* 0x58 */ GRUB_KEYBOARD_KEY_F12,         GRUB_KEYBOARD_KEY_JP_RO,
   /* 0x5a */ 0,                             0,
   /* 0x5c */ 0,                             0,
   /* 0x5e */ 0,                             0,
@@ -261,7 +261,14 @@ static grub_uint8_t linux_to_usb_map[128] = {
   /* 0x68 */ GRUB_KEYBOARD_KEY_PPAGE,       GRUB_KEYBOARD_KEY_LEFT,
   /* 0x6a */ GRUB_KEYBOARD_KEY_RIGHT,       GRUB_KEYBOARD_KEY_END,
   /* 0x6c */ GRUB_KEYBOARD_KEY_DOWN,        GRUB_KEYBOARD_KEY_NPAGE, 
-  /* 0x6e */ GRUB_KEYBOARD_KEY_INSERT,      GRUB_KEYBOARD_KEY_DELETE
+  /* 0x6e */ GRUB_KEYBOARD_KEY_INSERT,      GRUB_KEYBOARD_KEY_DELETE,
+  /* 0x70 */ 0,                             0,
+  /* 0x72 */ 0,                             GRUB_KEYBOARD_KEY_JP_RO,
+  /* 0x74 */ 0,                             0,
+  /* 0x76 */ 0,                             0,
+  /* 0x78 */ 0,                             GRUB_KEYBOARD_KEY_KPCOMMA,
+  /* 0x7a */ 0,                             0,
+  /* 0x7c */ GRUB_KEYBOARD_KEY_JP_YEN,
 }; 
 
 static void
@@ -289,7 +296,8 @@ lookup (char *code, int shift)
     if (strcmp (code, console_grub_equivalences_common[i].layout) == 0)
       return console_grub_equivalences_common[i].grub;
 
-  fprintf (stderr, _("Unknown key %s\n"), code);
+  /* TRANSLATORS: scan identifier is keyboard key symbolic name.  */
+  fprintf (stderr, _("Unknown keyboard scan identifier %s\n"), code);
 
   return '\0';
 }
@@ -309,7 +317,7 @@ get_grub_code (char *layout_code, int shift)
 }
 
 static void
-write_file (FILE *out, struct grub_keyboard_layout *layout)
+write_file (FILE *out, const char *fname, struct grub_keyboard_layout *layout)
 {
   grub_uint32_t version;
   unsigned i;
@@ -331,14 +339,21 @@ write_file (FILE *out, struct grub_keyboard_layout *layout)
     layout->keyboard_map_shift_l3[i]
       = grub_cpu_to_le32(layout->keyboard_map_shift_l3[i]);
 
-  fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
-         GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out);
-  fwrite (&version, sizeof (version), 1, out);
-  fwrite (layout, 1, sizeof (*layout), out);
+  if (fwrite (GRUB_KEYBOARD_LAYOUTS_FILEMAGIC, 1,
+             GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE, out)
+      != GRUB_KEYBOARD_LAYOUTS_FILEMAGIC_SIZE
+      || fwrite (&version, sizeof (version), 1, out) != 1
+      || fwrite (layout, 1, sizeof (*layout), out) != sizeof (*layout))
+    {
+      if (fname)
+       grub_util_error ("cannot write to `%s': %s", fname, strerror (errno));
+      else
+       grub_util_error ("cannot write to the stdout: %s", strerror (errno));
+    }
 }
 
 static void
-write_keymaps (FILE *in, FILE *out)
+write_keymaps (FILE *in, FILE *out, const char *out_filename)
 {
   struct grub_keyboard_layout layout;
   char line[2048];
@@ -385,7 +400,8 @@ write_keymaps (FILE *in, FILE *out)
          if (keycode_usb == 0
              || keycode_usb >= GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
            {
-             fprintf (stderr, _("Unknown keycode 0x%02x\n"), keycode_linux);
+             /* TRANSLATORS: scan code is keyboard key numeric identifier.  */
+             fprintf (stderr, _("Unknown keyboard scan code 0x%02x\n"), keycode_linux);
              continue;
            }
          if (keycode_usb < GRUB_KEYBOARD_LAYOUTS_ARRAY_SIZE)
@@ -403,13 +419,15 @@ write_keymaps (FILE *in, FILE *out)
 
   if (ok == 0)
     {
-      fprintf (stderr, "%s", _("ERROR: no keycodes found. Check the input.\n"));
+      /* TRANSLATORS: this error is triggered when input doesn't contain any
+        key descriptions.  */
+      fprintf (stderr, "%s", _("ERROR: no valid keyboard layout found. Check the input.\n"));
       exit (1);
     }
 
   add_special_keys (&layout);
 
-  write_file (out, &layout);
+  write_file (out, out_filename, &layout);
 }
 
 static error_t
@@ -419,8 +437,6 @@ argp_parser (int key, char *arg, struct argp_state *state)
      know is a pointer to our arguments structure. */
   struct arguments *arguments = state->input;
 
-  char *p;
-
   switch (key)
     {
     case 'i':
@@ -444,6 +460,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
 
 static struct argp argp = {
   options, argp_parser, N_("[OPTIONS]"),
+  /* TRANSLATORS: "one" is a shortcut for "keyboard layout".  */
   N_("Generate GRUB keyboard layout from Linux console one."),
   NULL, NULL, NULL
 };
@@ -454,7 +471,7 @@ main (int argc, char *argv[])
   FILE *in, *out;
   struct arguments arguments;
 
-  set_program_name (argv[0]);
+  grub_util_host_init (&argc, &argv);
 
   /* Check for options.  */
   memset (&arguments, 0, sizeof (struct arguments));
@@ -465,7 +482,7 @@ main (int argc, char *argv[])
     }
 
   if (arguments.input)
-    in = fopen (arguments.input, "r");
+    in = grub_util_fopen (arguments.input, "r");
   else
     in = stdin;
 
@@ -474,7 +491,7 @@ main (int argc, char *argv[])
                     strerror (errno));
 
   if (arguments.output)
-    out = fopen (arguments.output, "wb");
+    out = grub_util_fopen (arguments.output, "wb");
   else
     out = stdout;
 
@@ -486,7 +503,7 @@ main (int argc, char *argv[])
                       strerror (errno));
     }
 
-  write_keymaps (in, out);
+  write_keymaps (in, out, arguments.output);
 
   if (in != stdin)
     fclose (in);