[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About the CLI of both grub-mkrescue versions
From: |
Andrei Borzenkov |
Subject: |
Re: About the CLI of both grub-mkrescue versions |
Date: |
Fri, 10 Oct 2014 22:19:04 +0400 |
В Wed, 01 Oct 2014 09:25:12 +0200
"Thomas Schmitt" <address@hidden> пишет:
> Hi,
>
> to substantiate my proposal of renaming young grub-mkrescue.c to
> grub-mkiso.c and to add a built-in emulation of grub-mkrescue(.in),
> here the necessary code which i tested standalone with valgrind.
Well, below is much more simple patch which is reusing argp
infrastructure. The only problem - it needs small patch for gnulib
otherwise --help does not work. IMHO this is a bug in gnulib. If you
convince them to fix it ...
I do not say that I particular like it, but looks better than
reimplement parser from scratch.
---
grub-core/gnulib/argp-parse.c | 7 +++++--
util/grub-mkrescue.c | 37 ++++++++++++++++++++++++++++---------
2 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/grub-core/gnulib/argp-parse.c b/grub-core/gnulib/argp-parse.c
index 67ea32c..8fb50e1 100644
--- a/grub-core/gnulib/argp-parse.c
+++ b/grub-core/gnulib/argp-parse.c
@@ -89,13 +89,16 @@ static const struct argp_option argp_default_options[] =
static error_t
argp_default_parser (int key, char *arg, struct argp_state *state)
{
+ struct argp_state help_state = *state;
+
+ help_state.flags &= ~ARGP_NO_ERRS;
switch (key)
{
case '?':
- __argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
+ __argp_state_help (&help_state, state->out_stream, ARGP_HELP_STD_HELP);
break;
case OPT_USAGE:
- __argp_state_help (state, state->out_stream,
+ __argp_state_help (&help_state, state->out_stream,
ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
break;
diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c
index e719839..8decb4e 100644
--- a/util/grub-mkrescue.c
+++ b/util/grub-mkrescue.c
@@ -70,6 +70,19 @@ xorriso_push (const char *val)
}
static void
+xorriso_push_tail (const char *val)
+{
+ if (xorriso_tail_arg_alloc <= xorriso_tail_argc)
+ {
+ xorriso_tail_arg_alloc = 2 * (4 + xorriso_tail_argc);
+ xorriso_tail_argv = xrealloc (xorriso_tail_argv,
+ sizeof (xorriso_tail_argv[0])
+ * xorriso_tail_arg_alloc);
+ }
+ xorriso_tail_argv[xorriso_tail_argc++] = xstrdup (val);
+}
+
+static void
xorriso_link (const char *from, const char *to)
{
char *tof = grub_util_path_concat (2, iso9660_dir, to);
@@ -156,6 +169,12 @@ enum {
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
+ if (state->quoted && !(int *)state->input)
+ {
+ *(int *)state->input = 1;
+ xorriso_push_tail ("--");
+ }
+
if (grub_install_parse (key, arg))
return 0;
switch (key)
@@ -216,14 +235,7 @@ argp_parser (int key, char *arg, struct argp_state *state)
return 0;
case ARGP_KEY_ARG:
- if (xorriso_tail_arg_alloc <= xorriso_tail_argc)
- {
- xorriso_tail_arg_alloc = 2 * (4 + xorriso_tail_argc);
- xorriso_tail_argv = xrealloc (xorriso_tail_argv,
- sizeof (xorriso_tail_argv[0])
- * xorriso_tail_arg_alloc);
- }
- xorriso_tail_argv[xorriso_tail_argc++] = xstrdup (arg);
+ xorriso_push_tail (arg);
return 0;
default:
return ARGP_ERR_UNKNOWN;
@@ -380,6 +392,8 @@ main (int argc, char *argv[])
char *romdir;
char *sysarea_img = NULL;
const char *pkgdatadir;
+ int quote_seen = 0;
+ int unknown;
grub_util_host_init (&argc, &argv);
grub_util_disable_fd_syncs ();
@@ -391,7 +405,12 @@ main (int argc, char *argv[])
xorriso = xstrdup ("xorriso");
label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
- argp_parse (&argp, argc, argv, 0, 0, 0);
+ while (argc > 0 && argp_parse (&argp, argc, argv, ARGP_NO_ERRS, &unknown,
"e_seen))
+ {
+ xorriso_push_tail (argv[unknown]);
+ argv += unknown;
+ argc -= unknown;
+ }
if (!output_image)
grub_util_error ("%s", _("output file must be specified"));
--
tg: (77063f4..) u/grub-mkrescue-options (depends on: master)