From ff2b3cd928f281f9168b57355f571aad7373f983 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 28 Feb 2013 11:00:59 +0100 Subject: [PATCH] * grub-core/lib/arg.c (grub_arg_show_help): Move showargs out of its parent. --- ChangeLog | 5 ++ grub-core/lib/arg.c | 109 ++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6601c421b..21ec9a9a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-02-28 Vladimir Serbinenko + + * grub-core/lib/arg.c (grub_arg_show_help): Move showargs + out of its parent. + 2013-02-28 Vladimir Serbinenko * grub-core/fs/jfs.c: Remove nested functions. diff --git a/grub-core/lib/arg.c b/grub-core/lib/arg.c index a2d94165e..da44e3025 100644 --- a/grub-core/lib/arg.c +++ b/grub-core/lib/arg.c @@ -109,69 +109,70 @@ show_usage (grub_extcmd_t cmd) grub_printf ("%s %s %s\n", _("Usage:"), cmd->cmd->name, _(cmd->cmd->summary)); } +static void +showargs (const struct grub_arg_option *opt, + int h_is_used, int u_is_used) +{ + for (; opt->doc; opt++) + { + int spacing = 20; + + if (opt->shortarg && grub_isgraph (opt->shortarg)) + grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' '); + else if (opt == help_options && ! h_is_used) + grub_printf ("-h, "); + else if (opt == help_options + 1 && ! u_is_used) + grub_printf ("-u, "); + else + grub_printf (" "); + + if (opt->longarg) + { + grub_printf ("--%s", opt->longarg); + spacing -= grub_strlen (opt->longarg) + 2; + + if (opt->arg) + { + grub_printf ("=%s", opt->arg); + spacing -= grub_strlen (opt->arg) + 1; + } + } + + if (spacing < 0) + spacing = 3; + + while (spacing--) + grub_xputs (" "); + + grub_printf ("%s\n", _(opt->doc)); + } +} + void grub_arg_show_help (grub_extcmd_t cmd) { - auto void showargs (const struct grub_arg_option *opt); int h_is_used = 0; int u_is_used = 0; - - auto void showargs (const struct grub_arg_option *opt) - { - for (; opt->doc; opt++) - { - int spacing = 20; - - if (opt->shortarg && grub_isgraph (opt->shortarg)) - grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' '); - else if (opt == help_options && ! h_is_used) - grub_printf ("-h, "); - else if (opt == help_options + 1 && ! u_is_used) - grub_printf ("-u, "); - else - grub_printf (" "); - - if (opt->longarg) - { - grub_printf ("--%s", opt->longarg); - spacing -= grub_strlen (opt->longarg) + 2; - - if (opt->arg) - { - grub_printf ("=%s", opt->arg); - spacing -= grub_strlen (opt->arg) + 1; - } - } - - if (spacing < 0) - spacing = 3; - - while (spacing--) - grub_xputs (" "); - - grub_printf ("%s\n", _(opt->doc)); - - switch (opt->shortarg) - { - case 'h': - h_is_used = 1; - break; - - case 'u': - u_is_used = 1; - break; - - default: - break; - } - } - } + const struct grub_arg_option *opt; show_usage (cmd); grub_printf ("%s\n\n", _(cmd->cmd->description)); + + for (opt = cmd->options; opt->doc; opt++) + switch (opt->shortarg) + { + case 'h': + h_is_used = 1; + break; + + case 'u': + u_is_used = 1; + break; + } + if (cmd->options) - showargs (cmd->options); - showargs (help_options); + showargs (cmd->options, h_is_used, u_is_used); + showargs (help_options, h_is_used, u_is_used); #if 0 grub_printf ("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); #endif