#include <grub/i18n.h>
/* Built-in parser for default options. */
-#define SHORT_ARG_HELP -100
-#define SHORT_ARG_USAGE -101
-
static const struct grub_arg_option help_options[] =
{
- {"help", SHORT_ARG_HELP, 0,
+ {"help", 0, 0,
N_("Display this help and exit."), 0, ARG_TYPE_NONE},
- {"usage", SHORT_ARG_USAGE, 0,
+ {"usage", 0, 0,
N_("Display the usage of this command and exit."), 0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
if (opt->shortarg && grub_isgraph (opt->shortarg))
grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' ');
- else if (opt->shortarg == SHORT_ARG_HELP && ! h_is_used)
+ else if (opt == help_options && ! h_is_used)
grub_printf ("-h, ");
- else if (opt->shortarg == SHORT_ARG_USAGE && ! u_is_used)
+ else if (opt == help_options + 1 && ! u_is_used)
grub_printf ("-u, ");
else
grub_printf (" ");
static int
-parse_option (grub_extcmd_t cmd, int key, char *arg, struct grub_arg_list *usr)
+parse_option (grub_extcmd_t cmd, const struct grub_arg_option *opt,
+ char *arg, struct grub_arg_list *usr)
{
- switch (key)
+ if (opt == help_options)
{
- case SHORT_ARG_HELP:
grub_arg_show_help (cmd);
return -1;
+ }
- case SHORT_ARG_USAGE:
+ if (opt == help_options + 1)
+ {
show_usage (cmd);
return -1;
+ }
+ {
+ int found = opt - cmd->options;
- default:
+ if (opt->flags & GRUB_ARG_OPTION_REPEATABLE)
{
- int found = -1;
- int i = 0;
- const struct grub_arg_option *opt = cmd->options;
-
- while (opt->doc)
- {
- if (opt->shortarg && key == opt->shortarg)
- {
- found = i;
- break;
- }
- opt++;
- i++;
- }
-
- if (found == -1)
- return -1;
-
- if (opt->flags & GRUB_ARG_OPTION_REPEATABLE)
- {
- usr[found].args[usr[found].set++] = arg;
- usr[found].args[usr[found].set] = NULL;
- }
- else
- {
- usr[found].set = 1;
- usr[found].arg = arg;
- }
+ usr[found].args[usr[found].set++] = arg;
+ usr[found].args[usr[found].set] = NULL;
}
- }
+ else
+ {
+ usr[found].set = 1;
+ usr[found].arg = arg;
+ }
+ }
return 0;
}
it can have an argument value. */
if (*curshort)
{
- if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
+ if (parse_option (cmd, opt, 0, usr) || grub_errno)
goto fail;
}
else
/* XXX: Not implemented. */
break;
}
- if (parse_option (cmd, opt->shortarg, option, usr) || grub_errno)
+ if (parse_option (cmd, opt, option, usr) || grub_errno)
goto fail;
}
else
goto fail;
}
- if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
+ if (parse_option (cmd, opt, 0, usr) || grub_errno)
goto fail;
}
}