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;
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;
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;
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;
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)';
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;
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;
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;
#include <grub/i18n.h>
#include "progname.h"
+#include <argp.h>
#define ENABLE_RELOCATABLE 0
\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);
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"),
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 ();
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 }
};