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>
|
2009-07-06 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* commands/search.c (search_fs): Fix potential NULL pointer
|
* 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;
|
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 *
|
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;
|
struct grub_arg_option *found = 0;
|
||||||
auto struct grub_arg_option *fnd_long (const struct grub_arg_option *opt);
|
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)
|
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;
|
return (struct grub_arg_option *) opt;
|
||||||
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)
|
struct grub_arg_list *usr, char ***args, int *argnum)
|
||||||
{
|
{
|
||||||
int curarg;
|
int curarg;
|
||||||
char *longarg = 0;
|
int arglen;
|
||||||
int complete = 0;
|
int complete = 0;
|
||||||
char **argl = 0;
|
char **argl = 0;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
@ -328,14 +316,14 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
longarg = (char *) grub_strdup (arg);
|
option = grub_strchr (arg, '=');
|
||||||
if (! longarg)
|
if (option) {
|
||||||
goto fail;
|
arglen = option - arg - 2;
|
||||||
|
option++;
|
||||||
|
} else
|
||||||
|
arglen = grub_strlen (arg) - 2;
|
||||||
|
|
||||||
option = find_long_option (longarg);
|
opt = find_long (cmd->options, arg + 2, arglen);
|
||||||
arg = longarg;
|
|
||||||
|
|
||||||
opt = find_long (cmd->options, arg + 2);
|
|
||||||
if (! opt)
|
if (! opt)
|
||||||
{
|
{
|
||||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown argument `%s'\n", arg);
|
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)
|
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
grub_free (longarg);
|
|
||||||
longarg = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete = 1;
|
complete = 1;
|
||||||
|
@ -412,7 +398,5 @@ grub_arg_parse (grub_extcmd_t cmd, int argc, char **argv,
|
||||||
*argnum = num;
|
*argnum = num;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
grub_free (longarg);
|
|
||||||
|
|
||||||
return complete;
|
return complete;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue