2009-07-07 Pavel Roskin <proski@gnu.org>
* lib/arg.c (find_long_option): Remove. (find_long): Add `len' argument, make `s' const char *. (grub_arg_parse): Parse long options in place, not in a temporary buffer.
This commit is contained in:
parent
99f6804167
commit
8279cade23
2 changed files with 18 additions and 27 deletions
|
@ -1,3 +1,10 @@
|
|||
2009-07-07 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* lib/arg.c (find_long_option): Remove.
|
||||
(find_long): Add `len' argument, make `s' const char *.
|
||||
(grub_arg_parse): Parse long options in place, not in a
|
||||
temporary buffer.
|
||||
|
||||
2009-07-06 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* commands/search.c (search_fs): Fix potential NULL pointer
|
||||
|
|
38
lib/arg.c
38
lib/arg.c
|
@ -76,21 +76,8 @@ find_short (const struct grub_arg_option *options, char c)
|
|||
return found;
|
||||
}
|
||||
|
||||
static char *
|
||||
find_long_option (char *s)
|
||||
{
|
||||
char *argpos = grub_strchr (s, '=');
|
||||
|
||||
if (argpos)
|
||||
{
|
||||
*argpos = '\0';
|
||||
return ++argpos;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_arg_option *
|
||||
find_long (const struct grub_arg_option *options, char *s)
|
||||
find_long (const struct grub_arg_option *options, const char *s, int len)
|
||||
{
|
||||
struct grub_arg_option *found = 0;
|
||||
auto struct grub_arg_option *fnd_long (const struct grub_arg_option *opt);
|
||||
|
@ -99,7 +86,8 @@ find_long (const struct grub_arg_option *options, char *s)
|
|||
{
|
||||
while (opt->doc)
|
||||
{
|
||||
if (opt->longarg && ! grub_strcmp (opt->longarg, s))
|
||||
if (opt->longarg && ! grub_strncmp (opt->longarg, s, len) &&
|
||||
opt->longarg[len] == '\0')
|
||||
return (struct grub_arg_option *) opt;
|
||||
opt++;
|
||||
}
|
||||
|
@ -244,7 +232,7 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
struct grub_arg_list *usr, char ***args, int *argnum)
|
||||
{
|
||||
int curarg;
|
||||
char *longarg = 0;
|
||||
int arglen;
|
||||
int complete = 0;
|
||||
char **argl = 0;
|
||||
int num = 0;
|
||||
|
@ -328,14 +316,14 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
break;
|
||||
}
|
||||
|
||||
longarg = (char *) grub_strdup (arg);
|
||||
if (! longarg)
|
||||
goto fail;
|
||||
option = grub_strchr (arg, '=');
|
||||
if (option) {
|
||||
arglen = option - arg - 2;
|
||||
option++;
|
||||
} else
|
||||
arglen = grub_strlen (arg) - 2;
|
||||
|
||||
option = find_long_option (longarg);
|
||||
arg = longarg;
|
||||
|
||||
opt = find_long (cmd->options, arg + 2);
|
||||
opt = find_long (cmd->options, arg + 2, arglen);
|
||||
if (! opt)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown argument `%s'\n", arg);
|
||||
|
@ -402,8 +390,6 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
grub_free (longarg);
|
||||
longarg = 0;
|
||||
}
|
||||
|
||||
complete = 1;
|
||||
|
@ -412,7 +398,5 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
|||
*argnum = num;
|
||||
|
||||
fail:
|
||||
grub_free (longarg);
|
||||
|
||||
return complete;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue