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.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-25 01:15:29 +01:00
parent 1e3f8ae86f
commit 6a656b0ea5
8 changed files with 120 additions and 83 deletions

View File

@ -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):

View 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;

View 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;

View 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. */

View 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)
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 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 int
usage (int status)
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
};
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 ();

View File

@ -252,6 +252,7 @@
./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
@ -537,7 +538,6 @@
./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

View 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

View 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 }
};