2004-04-04 Yoshinori K. Okuji <okuji@enbug.org>
All symbols prefixed with PUPA_ and pupa_ are renamed to GRUB_ and grub_, respectively. Because the conversion is trivial and mechanical, I omit the details here. Please refer to the CVS if you need more information.
This commit is contained in:
parent
6a1425510d
commit
4b13b216f4
125 changed files with 6198 additions and 6181 deletions
126
normal/arg.c
126
normal/arg.c
|
@ -1,9 +1,9 @@
|
|||
/* arg.c - argument parser */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* GRUB is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,36 +14,36 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "pupa/arg.h"
|
||||
#include "pupa/misc.h"
|
||||
#include "pupa/mm.h"
|
||||
#include "pupa/err.h"
|
||||
#include "pupa/normal.h"
|
||||
#include "grub/arg.h"
|
||||
#include "grub/misc.h"
|
||||
#include "grub/mm.h"
|
||||
#include "grub/err.h"
|
||||
#include "grub/normal.h"
|
||||
|
||||
/* Build in parser for default options. */
|
||||
static const struct pupa_arg_option help_options[] =
|
||||
static const struct grub_arg_option help_options[] =
|
||||
{
|
||||
{"help", 'h', 0, "Display help", 0, ARG_TYPE_NONE},
|
||||
{"usage", 'u', 0, "Show how to use this command", 0, ARG_TYPE_NONE},
|
||||
{0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
static struct pupa_arg_option *
|
||||
find_short (const struct pupa_arg_option *options, char c)
|
||||
static struct grub_arg_option *
|
||||
find_short (const struct grub_arg_option *options, char c)
|
||||
{
|
||||
struct pupa_arg_option *found = 0;
|
||||
auto struct pupa_arg_option *fnd_short (const struct pupa_arg_option *opt);
|
||||
struct grub_arg_option *found = 0;
|
||||
auto struct grub_arg_option *fnd_short (const struct grub_arg_option *opt);
|
||||
|
||||
struct pupa_arg_option *fnd_short (const struct pupa_arg_option *opt)
|
||||
struct grub_arg_option *fnd_short (const struct grub_arg_option *opt)
|
||||
{
|
||||
while (opt->doc)
|
||||
{
|
||||
if (opt->shortarg == c)
|
||||
return (struct pupa_arg_option *) opt;
|
||||
return (struct grub_arg_option *) opt;
|
||||
opt++;
|
||||
}
|
||||
return 0;
|
||||
|
@ -60,7 +60,7 @@ find_short (const struct pupa_arg_option *options, char c)
|
|||
static char *
|
||||
find_long_option (char *s)
|
||||
{
|
||||
char *argpos = pupa_strchr (s, '=');
|
||||
char *argpos = grub_strchr (s, '=');
|
||||
|
||||
if (argpos)
|
||||
{
|
||||
|
@ -70,18 +70,18 @@ find_long_option (char *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static struct pupa_arg_option *
|
||||
find_long (const struct pupa_arg_option *options, char *s)
|
||||
static struct grub_arg_option *
|
||||
find_long (const struct grub_arg_option *options, char *s)
|
||||
{
|
||||
struct pupa_arg_option *found = 0;
|
||||
auto struct pupa_arg_option *fnd_long (const struct pupa_arg_option *opt);
|
||||
struct grub_arg_option *found = 0;
|
||||
auto struct grub_arg_option *fnd_long (const struct grub_arg_option *opt);
|
||||
|
||||
struct pupa_arg_option *fnd_long (const struct pupa_arg_option *opt)
|
||||
struct grub_arg_option *fnd_long (const struct grub_arg_option *opt)
|
||||
{
|
||||
while (opt->doc)
|
||||
{
|
||||
if (opt->longarg && !pupa_strcmp (opt->longarg, s))
|
||||
return (struct pupa_arg_option *) opt;
|
||||
if (opt->longarg && !grub_strcmp (opt->longarg, s))
|
||||
return (struct grub_arg_option *) opt;
|
||||
opt++;
|
||||
}
|
||||
return 0;
|
||||
|
@ -96,46 +96,46 @@ find_long (const struct pupa_arg_option *options, char *s)
|
|||
}
|
||||
|
||||
static void
|
||||
show_usage (pupa_command_t cmd)
|
||||
show_usage (grub_command_t cmd)
|
||||
{
|
||||
pupa_printf ("Usage: %s\n", cmd->summary);
|
||||
grub_printf ("Usage: %s\n", cmd->summary);
|
||||
}
|
||||
|
||||
static void
|
||||
show_help (pupa_command_t cmd)
|
||||
show_help (grub_command_t cmd)
|
||||
{
|
||||
static void showargs (const struct pupa_arg_option *opt)
|
||||
static void showargs (const struct grub_arg_option *opt)
|
||||
{
|
||||
for (; opt->doc; opt++)
|
||||
{
|
||||
if (opt->shortarg && pupa_isgraph (opt->shortarg))
|
||||
pupa_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' ');
|
||||
if (opt->shortarg && grub_isgraph (opt->shortarg))
|
||||
grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' ');
|
||||
else
|
||||
pupa_printf (" ");
|
||||
grub_printf (" ");
|
||||
if (opt->longarg)
|
||||
{
|
||||
pupa_printf ("--%s", opt->longarg);
|
||||
grub_printf ("--%s", opt->longarg);
|
||||
if (opt->arg)
|
||||
pupa_printf ("=%s", opt->arg);
|
||||
grub_printf ("=%s", opt->arg);
|
||||
}
|
||||
else
|
||||
pupa_printf ("\t");
|
||||
grub_printf ("\t");
|
||||
|
||||
pupa_printf ("\t\t%s\n", opt->doc);
|
||||
grub_printf ("\t\t%s\n", opt->doc);
|
||||
}
|
||||
}
|
||||
|
||||
show_usage (cmd);
|
||||
pupa_printf ("%s\n\n", cmd->description);
|
||||
grub_printf ("%s\n\n", cmd->description);
|
||||
if (cmd->options)
|
||||
showargs (cmd->options);
|
||||
showargs (help_options);
|
||||
pupa_printf ("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
|
||||
grub_printf ("\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
parse_option (pupa_command_t cmd, int key, char *arg, struct pupa_arg_list *usr)
|
||||
parse_option (grub_command_t cmd, int key, char *arg, struct grub_arg_list *usr)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ parse_option (pupa_command_t cmd, int key, char *arg, struct pupa_arg_list *usr)
|
|||
{
|
||||
int found = -1;
|
||||
int i = 0;
|
||||
const struct pupa_arg_option *opt = cmd->options;
|
||||
const struct grub_arg_option *opt = cmd->options;
|
||||
|
||||
while (opt->doc)
|
||||
{
|
||||
|
@ -176,21 +176,21 @@ parse_option (pupa_command_t cmd, int key, char *arg, struct pupa_arg_list *usr)
|
|||
}
|
||||
|
||||
int
|
||||
pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
||||
struct pupa_arg_list *usr, char ***args, int *argnum)
|
||||
grub_arg_parse (grub_command_t cmd, int argc, char **argv,
|
||||
struct grub_arg_list *usr, char ***args, int *argnum)
|
||||
{
|
||||
int curarg;
|
||||
char *longarg = 0;
|
||||
int complete = 0;
|
||||
char **argl = 0;
|
||||
int num = 0;
|
||||
auto pupa_err_t add_arg (char *s);
|
||||
auto grub_err_t add_arg (char *s);
|
||||
|
||||
pupa_err_t add_arg (char *s)
|
||||
grub_err_t add_arg (char *s)
|
||||
{
|
||||
argl = pupa_realloc (argl, (++num) * sizeof (char *));
|
||||
argl = grub_realloc (argl, (++num) * sizeof (char *));
|
||||
if (! args)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
argl[num - 1] = s;
|
||||
return 0;
|
||||
}
|
||||
|
@ -199,11 +199,11 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
for (curarg = 0; curarg < argc; curarg++)
|
||||
{
|
||||
char *arg = argv[curarg];
|
||||
struct pupa_arg_option *opt;
|
||||
struct grub_arg_option *opt;
|
||||
char *option = 0;
|
||||
|
||||
/* No option is used. */
|
||||
if (arg[0] != '-' || pupa_strlen (arg) == 1)
|
||||
if (arg[0] != '-' || grub_strlen (arg) == 1)
|
||||
{
|
||||
if (add_arg (arg) != 0)
|
||||
goto fail;
|
||||
|
@ -221,7 +221,7 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
opt = find_short (cmd->options, *curshort);
|
||||
if (!opt)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT,
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"Unknown argument `-%c'\n", *curshort);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
it can have an argument value. */
|
||||
if (*curshort)
|
||||
{
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || pupa_errno)
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
|
@ -242,8 +242,8 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
if (curarg + 1 < argc)
|
||||
{
|
||||
char *nextarg = argv[curarg + 1];
|
||||
if (!(opt->flags & PUPA_ARG_OPTION_OPTIONAL)
|
||||
|| (pupa_strlen (nextarg) < 2 || nextarg[0] != '-'))
|
||||
if (!(opt->flags & GRUB_ARG_OPTION_OPTIONAL)
|
||||
|| (grub_strlen (nextarg) < 2 || nextarg[0] != '-'))
|
||||
option = argv[++curarg];
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
{
|
||||
/* If the argument "--" is used just pass the other
|
||||
arguments. */
|
||||
if (pupa_strlen (arg) == 2)
|
||||
if (grub_strlen (arg) == 2)
|
||||
{
|
||||
for (curarg++; curarg < argc; curarg++)
|
||||
if (add_arg (arg) != 0)
|
||||
|
@ -264,7 +264,7 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
break;
|
||||
}
|
||||
|
||||
longarg = (char *) pupa_strdup (arg);
|
||||
longarg = (char *) grub_strdup (arg);
|
||||
if (! longarg)
|
||||
goto fail;
|
||||
|
||||
|
@ -274,17 +274,17 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
opt = find_long (cmd->options, arg + 2);
|
||||
if (!opt)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "Unknown argument `%s'\n", arg);
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown argument `%s'\n", arg);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (! (opt->type == ARG_TYPE_NONE
|
||||
|| (!option && (opt->flags & PUPA_ARG_OPTION_OPTIONAL))))
|
||||
|| (!option && (opt->flags & GRUB_ARG_OPTION_OPTIONAL))))
|
||||
{
|
||||
if (!option)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT,
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"Missing mandatory option for `%s'\n", opt->longarg);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -303,10 +303,10 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
{
|
||||
char *tail;
|
||||
|
||||
pupa_strtoul (option, &tail, 0);
|
||||
if (tail == 0 || tail == option || *tail != '\0' || pupa_errno)
|
||||
grub_strtoul (option, &tail, 0);
|
||||
if (tail == 0 || tail == option || *tail != '\0' || grub_errno)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT,
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"The argument `%s' requires an integer.",
|
||||
arg);
|
||||
|
||||
|
@ -322,23 +322,23 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
/* XXX: Not implemented. */
|
||||
break;
|
||||
}
|
||||
if (parse_option (cmd, opt->shortarg, option, usr) || pupa_errno)
|
||||
if (parse_option (cmd, opt->shortarg, option, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT,
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT,
|
||||
"A value was assigned to the argument `%s' while it "
|
||||
"doesn't require an argument\n", arg);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || pupa_errno)
|
||||
if (parse_option (cmd, opt->shortarg, 0, usr) || grub_errno)
|
||||
goto fail;
|
||||
}
|
||||
pupa_free (longarg);
|
||||
grub_free (longarg);
|
||||
longarg = 0;
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ pupa_arg_parse (pupa_command_t cmd, int argc, char **argv,
|
|||
*argnum = num;
|
||||
|
||||
fail:
|
||||
pupa_free (longarg);
|
||||
grub_free (longarg);
|
||||
|
||||
return complete;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue