]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Convert grub-emu to argp.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 25 Feb 2012 00:15:29 +0000 (01:15 +0100)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 25 Feb 2012 00:15:29 +0000 (01:15 +0100)
* grub-core/Makefile.core.def (kernel): Add kern/emu/argp_common.c on
emu.
* util/argp_common.c: Rename to ...
* grub-core/kern/emu/argp_common.c: ... this. All users updated.
Add missing includes.
* grub-core/kern/emu/main.c: Convert to argp.
* po/POTFILES.in: Regenerate.
* util/grub-install.in (usage): Make first letter lowcase in messages
for uniformity.
* util/grub-setup.c (options): Likewise.

ChangeLog
Makefile.util.def
grub-core/Makefile.core.def
grub-core/kern/emu/argp_common.c [moved from util/argp_common.c with 95% similarity]
grub-core/kern/emu/main.c
po/POTFILES.in
util/grub-install.in
util/grub-setup.c

index d632d0830b1ea76d6f3471b952486798e55cc72f..658adc705037e8adfee875ccbefd8a5586f3b798 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-02-25  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Convert grub-emu to argp.
+
+       * grub-core/Makefile.core.def (kernel): Add kern/emu/argp_common.c on
+       emu.
+       * util/argp_common.c: Rename to ...
+       * grub-core/kern/emu/argp_common.c: ... this. All users updated.
+       Add missing includes.
+       * grub-core/kern/emu/main.c: Convert to argp.
+       * po/POTFILES.in: Regenerate.
+       * util/grub-install.in (usage): Make first letter lowcase in messages
+       for uniformity.
+       * util/grub-setup.c (options): Likewise.
+
 2012-02-24  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/gfxmenu/gui_progress_bar.c (progress_bar_set_property):
index d5176793c7e6df6634b077107a8230a0128f371d..03d2187f0bcc364af2d3ea3a32881e71b61e22c3 100644 (file)
@@ -142,7 +142,7 @@ program = {
 
   common = util/grub-mkimage.c;
   common = util/resolve.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   extra_dist = util/grub-mkimagexx.c;
 
@@ -160,7 +160,7 @@ program = {
   mansection = 1;
 
   common = util/grub-mkrelpath.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   ldadd = libgrubmods.a;
   ldadd = libgrubgcry.a;
@@ -174,7 +174,7 @@ program = {
   mansection = 1;
 
   common = util/grub-script-check.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   ldadd = libgrubmods.a;
   ldadd = libgrubgcry.a;
@@ -201,7 +201,7 @@ program = {
   mansection = 1;
 
   common = util/grub-mkpasswd-pbkdf2.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   ldadd = libgrubmods.a;
   ldadd = libgrubgcry.a;
@@ -271,7 +271,7 @@ program = {
   mansection = 1;
   common = util/grub-mkfont.c;
   common = grub-core/unidata.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   cflags = '$(freetype_cflags)';
 
@@ -290,7 +290,7 @@ program = {
   mansection = 8;
   common = util/grub-probe.c;
   common = util/ieee1275/ofpath.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   ldadd = libgrubmods.a;
   ldadd = libgrubgcry.a;
@@ -305,7 +305,7 @@ program = {
   mansection = 8;
   common = util/grub-setup.c;
   common = util/lvm.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
   common = grub-core/lib/reed_solomon.c;
 
   sparc64_ieee1275 = util/ieee1275/ofpath.c;
@@ -341,7 +341,7 @@ program = {
   mansection = 1;
 
   common = util/grub-mklayout.c;
-  common = util/argp_common.c;
+  common = grub-core/kern/emu/argp_common.c;
 
   ldadd = libgrubmods.a;
   ldadd = libgrubgcry.a;
index 882c57cdfecee03962263f21c442d96a40944e84..fde7b4f4b758a397c1f2db6dd45bc60f891469d1 100644 (file)
@@ -210,6 +210,7 @@ kernel = {
   emu = kern/emu/hostdisk.c;
   emu = kern/emu/hostfs.c;
   emu = kern/emu/main.c;
+  emu = kern/emu/argp_common.c;
   emu = kern/emu/misc.c;
   emu = kern/emu/mm.c;
   emu = kern/emu/time.c;
similarity index 95%
rename from util/argp_common.c
rename to grub-core/kern/emu/argp_common.c
index b1caf1b0d72a74a289c5b8ffa9d834c46020cee2..d6080ba256c2c39edd59e05055db092c01da9450 100644 (file)
@@ -20,7 +20,9 @@
 #include <config.h>
 
 #define _GNU_SOURCE    1
-#include "progname.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <progname.h>
 #include <argp.h>
 
 /* Print the version information.  */
index 64e72dff645abf5c608e5f78c0af72e02d24f353..941ece0620fd92471f81c112d8b0200d649406a9 100644 (file)
@@ -42,6 +42,7 @@
 #include <grub/i18n.h>
 
 #include "progname.h"
+#include <argp.h>
 
 #define ENABLE_RELOCATABLE 0
 
@@ -81,41 +82,84 @@ grub_machine_fini (void)
 
 \f
 
-static struct option options[] =
-  {
-    {"root-device", required_argument, 0, 'r'},
-    {"device-map", required_argument, 0, 'm'},
-    {"directory", required_argument, 0, 'd'},
-    {"hold", optional_argument, 0, 'H'},
-    {"help", no_argument, 0, 'h'},
-    {"version", no_argument, 0, 'V'},
-    {"verbose", no_argument, 0, 'v'},
-    { 0, 0, 0, 0 }
-  };
-
-static int
-usage (int status)
+static struct argp_option options[] = {
+  {"root",      'r', N_("DEVICE_NAME"), 0, N_("Set root device."), 2},
+  {"device-map",  'm', N_("FILE"), 0,
+   N_("use FILE as the device map [default=%s]"), 0},
+  {"directory",  'd', N_("DIR"), 0,
+   N_("use GRUB files in the directory DIR [default=%s]"), 0},
+  {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
+  {"hold",     'H', N_("SECS"),      OPTION_ARG_OPTIONAL, N_("wait until a debugger will attach"), 0},
+  { 0, 0, 0, 0, 0, 0 }
+};
+
+static char *
+help_filter (int key, const char *text, void *input __attribute__ ((unused)))
 {
-  if (status)
-    fprintf (stderr,
-            _("Try `%s --help' for more information.\n"), program_name);
-  else
-    printf (
-    _("Usage: %s [OPTION]...\n"
-      "\n"
-      "GRUB emulator.\n"
-      "\n"
-      "  -r, --root-device=DEV     use DEV as the root device [default=host]\n"
-      "  -m, --device-map=FILE     use FILE as the device map [default=%s]\n"
-      "  -d, --directory=DIR       use GRUB files in the directory DIR [default=%s]\n"
-      "  -v, --verbose             print verbose messages\n"
-      "  -H, --hold[=SECONDS]      wait until a debugger will attach\n"
-      "  -h, --help                display this message and exit\n"
-      "  -V, --version             print version information and exit\n"
-      "\n"
-      "Report bugs to <%s>.\n"), program_name, DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT);
-  return status;
+  switch (key)
+    {
+    case 'd':
+      return xasprintf (text, DEFAULT_DIRECTORY);
+    case 'm':
+      return xasprintf (text, DEFAULT_DEVICE_MAP);
+    default:
+      return (char *) text;
+    }
 }
+
+struct arguments
+{
+  const char *dev_map;
+  int hold;
+};
+
+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 'r':
+      free (root_dev);
+      root_dev = xstrdup (arg);
+      break;
+    case 'd':
+      free (dir);
+      dir = xstrdup (arg);
+      break;
+    case 'm':
+      arguments->dev_map = arg;
+      break;
+    case 'H':
+      arguments->hold = (arg ? atoi (arg) : -1);
+      break;
+    case 'v':
+      verbosity++;
+      break;
+
+    case ARGP_KEY_ARG:
+      {
+       /* Too many arguments. */
+       fprintf (stderr, _("Unknown extra argument `%s'.\n"), arg);
+       argp_usage (state);
+      }
+      break;
+
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static struct argp argp = {
+  options, argp_parser, NULL,
+  N_("GRUB emulator."),
+  NULL, help_filter, NULL
+};
+
 \f
 
 void grub_hostfs_init (void);
@@ -127,49 +171,24 @@ void grub_emu_init (void);
 int
 main (int argc, char *argv[])
 {
-  const char *dev_map = DEFAULT_DEVICE_MAP;
+  struct arguments arguments =
+    { 
+      .dev_map = DEFAULT_DEVICE_MAP,
+      .hold = 0
+    };
   volatile int hold = 0;
-  int opt;
 
   set_program_name (argv[0]);
 
   dir = xstrdup (DEFAULT_DIRECTORY);
 
-  while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
-    switch (opt)
-      {
-      case 'r':
-       free (root_dev);
-        root_dev = xstrdup (optarg);
-        break;
-      case 'd':
-       free (dir);
-        dir = xstrdup (optarg);
-        break;
-      case 'm':
-        dev_map = optarg;
-        break;
-      case 'v':
-        verbosity++;
-        break;
-      case 'H':
-        hold = (optarg ? atoi (optarg) : -1);
-        break;
-      case 'h':
-        return usage (0);
-      case 'V':
-        printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
-        return 0;
-      default:
-        return usage (1);
-      }
-
-  if (optind < argc)
+  if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
     {
-      fprintf (stderr, _("Unknown extra argument `%s'.\n"), argv[optind]);
-      return usage (1);
+      fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
+      exit(1);
     }
 
+  hold = arguments.hold;
   /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */
   if (hold && verbosity > 0)
     printf (_("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n"),
@@ -188,7 +207,7 @@ main (int argc, char *argv[])
   grub_host_init ();
 
   /* XXX: This is a bit unportable.  */
-  grub_util_biosdisk_init (dev_map);
+  grub_util_biosdisk_init (arguments.dev_map);
 
   grub_init_all ();
 
index 5c31a615d85cf54918cc64755d158d8b1f72e36d..3d10f8f31fb5646f18c92c24597f73176d027d1d 100644 (file)
 ./grub-core/kern/efi/init.c
 ./grub-core/kern/efi/mm.c
 ./grub-core/kern/elf.c
+./grub-core/kern/emu/argp_common.c
 ./grub-core/kern/emu/cache.c
 ./grub-core/kern/emu/full.c
 ./grub-core/kern/emu/hostdisk.c
 ./tests/example_unit_test.c
 ./tests/lib/unit_test.c
 ./tests/printf_unit_test.c
-./util/argp_common.c
 ./util/bin2h.c
 ./util/devicemap.c
 ./util/getroot.c
index 52e2f16f58feece4241bf738d1fbe2af4af5028a..9c8983f33948fccb3ed100ccf9372afbbfde3b48 100644 (file)
@@ -103,7 +103,7 @@ usage () {
     printf "  --grub-mkimage=%-9s%s\n" "$(gettext "FILE")" "$(gettext "use FILE as grub-mkimage")"
     printf "  --grub-mkrelpath=%-7s%s\n" "$(gettext "FILE")" "$(gettext "use FILE as grub-mkrelpath")"
     printf "  --grub-probe=%-11s%s\n" "$(gettext "FILE")" "$(gettext "use FILE as grub-probe")"
-    printf "  --allow-floppy          %s\n" "$(gettext "Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes.")"
+    printf "  --allow-floppy          %s\n" "$(gettext "make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes.")"
     printf "  --recheck               %s\n" "$(gettext "delete device map if it already exists")"
     printf "  --force                 %s\n" "$(gettext "install even if problems are detected")"
 if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
index 66f70501559855d30ede9e0e900fd7cbde10cbdd..9355e38684e43608859e3ef196141e582d0c2d57 100644 (file)
@@ -742,20 +742,20 @@ unable_to_embed:
 
 static struct argp_option options[] = {
   {"boot-image",  'b', N_("FILE"), 0,
-   N_("Use FILE as the boot image [default=%s]"), 0},
+   N_("use FILE as the boot image [default=%s]"), 0},
   {"core-image",  'c', N_("FILE"), 0,
-   N_("Use FILE as the core image [default=%s]"), 0},
+   N_("use FILE as the core image [default=%s]"), 0},
   {"directory",   'd', N_("DIR"),  0,
-   N_("Use GRUB files in the directory DIR [default=%s]"), 0},
+   N_("use GRUB files in the directory DIR [default=%s]"), 0},
   {"device-map",  'm', N_("FILE"), 0,
    N_("use FILE as the device map [default=%s]"), 0},
   {"force",       'f', 0,      0,
    N_("install even if problems are detected"), 0},
   {"skip-fs-probe",'s',0,      0,
-   N_("Do not probe for filesystems in DEVICE"), 0},
+   N_("do not probe for filesystems in DEVICE"), 0},
   {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
   {"allow-floppy", 'a', 0,      0,
-   N_("Make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0},
+   N_("make the drive also bootable as floppy (default for fdX devices). May break on some BIOSes."), 0},
 
   { 0, 0, 0, 0, 0, 0 }
 };