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:
okuji 2004-04-04 13:46:03 +00:00
parent 6a1425510d
commit 4b13b216f4
125 changed files with 6198 additions and 6181 deletions

View file

@ -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;
}

View file

@ -1,5 +1,5 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -17,16 +17,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/normal.h>
#include <pupa/misc.h>
#include <pupa/term.h>
#include <pupa/err.h>
#include <pupa/types.h>
#include <pupa/mm.h>
#include <pupa/machine/partition.h>
#include <pupa/disk.h>
#include <pupa/file.h>
#include <pupa/env.h>
#include <grub/normal.h>
#include <grub/misc.h>
#include <grub/term.h>
#include <grub/err.h>
#include <grub/types.h>
#include <grub/mm.h>
#include <grub/machine/partition.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/env.h>
static char *kill_buf;
@ -36,11 +36,11 @@ static int hist_pos = 0;
static int hist_end = 0;
static int hist_used = 0;
pupa_err_t
pupa_set_history (int newsize)
grub_err_t
grub_set_history (int newsize)
{
char **old_hist_lines = hist_lines;
hist_lines = pupa_malloc (sizeof (char *) * newsize);
hist_lines = grub_malloc (sizeof (char *) * newsize);
/* Copy the old lines into the new buffer. */
if (old_hist_lines)
@ -57,7 +57,7 @@ pupa_set_history (int newsize)
int pos = hist_end - i;
if (pos > hist_size)
pos -= hist_size;
pupa_free (old_hist_lines[pos]);
grub_free (old_hist_lines[pos]);
}
hist_end -= delsize;
@ -66,23 +66,23 @@ pupa_set_history (int newsize)
}
if (hist_pos < hist_end)
pupa_memmove (hist_lines, old_hist_lines + hist_pos,
grub_memmove (hist_lines, old_hist_lines + hist_pos,
(hist_end - hist_pos) * sizeof (char *));
else
{
/* Copy the first part. */
pupa_memmove (hist_lines, old_hist_lines,
grub_memmove (hist_lines, old_hist_lines,
hist_pos * sizeof (char *));
/* Copy the last part. */
pupa_memmove (hist_lines + hist_pos, old_hist_lines + hist_pos,
grub_memmove (hist_lines + hist_pos, old_hist_lines + hist_pos,
(hist_size - hist_pos) * sizeof (char *));
}
}
pupa_free (old_hist_lines);
grub_free (old_hist_lines);
hist_size = newsize;
hist_pos = 0;
@ -93,7 +93,7 @@ pupa_set_history (int newsize)
/* Get the entry POS from the history where `0' is the newest
entry. */
static char *
pupa_history_get (int pos)
grub_history_get (int pos)
{
pos = (hist_pos + pos) % hist_size;
return hist_lines[pos];
@ -102,7 +102,7 @@ pupa_history_get (int pos)
/* Insert a new history line S on the top of the history. */
static void
pupa_history_add (char *s)
grub_history_add (char *s)
{
/* Remove the oldest entry in the history to make room for a new
entry. */
@ -112,7 +112,7 @@ pupa_history_add (char *s)
if (hist_end < 0)
hist_end = hist_size + hist_end;
pupa_free (hist_lines[hist_end]);
grub_free (hist_lines[hist_end]);
}
else
hist_used++;
@ -123,16 +123,16 @@ pupa_history_add (char *s)
hist_pos = hist_size + hist_pos;
/* Insert into history. */
hist_lines[hist_pos] = pupa_strdup (s);
hist_lines[hist_pos] = grub_strdup (s);
}
/* Replace the history entry on position POS with the string S. */
static void
pupa_history_replace (int pos, char *s)
grub_history_replace (int pos, char *s)
{
pos = (hist_pos + pos) % hist_size;
pupa_free (hist_lines[pos]);
hist_lines[pos] = pupa_strdup (s);
grub_free (hist_lines[pos]);
hist_lines[pos] = grub_strdup (s);
}
/* Try to complete the string in BUF, return the characters that
@ -140,7 +140,7 @@ pupa_history_replace (int pos, char *s)
completions, in that case set RESTORE to 1 so the caller can
restore the prompt. */
static char *
pupa_tab_complete (char *buf, int *restore)
grub_tab_complete (char *buf, int *restore)
{
char *pos = buf;
char *path;
@ -151,8 +151,8 @@ pupa_tab_complete (char *buf, int *restore)
int len;
int numfound = 0;
/* The disk that is used for pupa_partition_iterate. */
pupa_device_t partdev;
/* The disk that is used for grub_partition_iterate. */
grub_device_t partdev;
/* String that is added when matched. */
char *matchstr;
@ -162,22 +162,22 @@ pupa_tab_complete (char *buf, int *restore)
auto int NESTED_FUNC_ATTR add_completion (const char *comp, const char *match,
const char *what,
void (*print_completion) (char *));
auto int iterate_commands (pupa_command_t cmd);
auto int iterate_commands (grub_command_t cmd);
auto int iterate_dev (const char *devname);
auto int iterate_part (const pupa_partition_t p);
auto int iterate_part (const grub_partition_t p);
auto int iterate_dir (const char *filename, int dir);
void print_simple_completion (char *comp)
{
pupa_printf (" %s", comp);
grub_printf (" %s", comp);
}
void print_partition_completion (char *comp)
{
pupa_print_partinfo (partdev, comp);
pupa_errno = 0;
grub_print_partinfo (partdev, comp);
grub_errno = 0;
}
/* Add a string to the list of possible completions. COMP is the
@ -193,21 +193,21 @@ pupa_tab_complete (char *buf, int *restore)
void (*print_completion) (char *))
{
/* Bug in strncmp then len ==0. */
if (!len || pupa_strncmp (pos, comp, len) == 0)
if (!len || grub_strncmp (pos, comp, len) == 0)
{
numfound++;
if (numfound == 1)
{
begin = len;
found = pupa_strdup (comp);
end = pupa_strlen (found);
found = grub_strdup (comp);
end = grub_strlen (found);
matchstr = (char *) match;
}
/* Multiple matches found, print the first instead of completing. */
else if (numfound == 2)
{
pupa_printf ("\nPossible %s are: ", what);
grub_printf ("\nPossible %s are: ", what);
print_completion (found);
}
@ -233,9 +233,9 @@ pupa_tab_complete (char *buf, int *restore)
return 0;
}
int iterate_part (const pupa_partition_t p)
int iterate_part (const grub_partition_t p)
{
add_completion (pupa_partition_get_name (p), ")", "partitions",
add_completion (grub_partition_get_name (p), ")", "partitions",
print_partition_completion);
return 0;
}
@ -246,9 +246,9 @@ pupa_tab_complete (char *buf, int *restore)
add_completion (filename, " ", "files", print_simple_completion);
else
{
char fname[pupa_strlen (filename) + 2];
pupa_strcpy (fname, filename);
pupa_sprintf (fname, "%s/", filename);
char fname[grub_strlen (filename) + 2];
grub_strcpy (fname, filename);
grub_sprintf (fname, "%s/", filename);
add_completion (fname, "", "files", print_simple_completion);
}
return 0;
@ -256,10 +256,10 @@ pupa_tab_complete (char *buf, int *restore)
int iterate_dev (const char *devname)
{
pupa_device_t dev;
grub_device_t dev;
/* Complete the partition part. */
dev = pupa_device_open (devname);
dev = grub_device_open (devname);
if (dev)
{
@ -269,13 +269,13 @@ pupa_tab_complete (char *buf, int *restore)
add_completion (devname, ")", "disks", print_simple_completion);
}
pupa_errno = PUPA_ERR_NONE;
grub_errno = GRUB_ERR_NONE;
return 0;
}
int iterate_commands (pupa_command_t cmd)
int iterate_commands (grub_command_t cmd)
{
if (cmd->flags & PUPA_COMMAND_FLAG_CMDLINE)
if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)
add_completion (cmd->name, " ", "commands", print_simple_completion);
return 0;
}
@ -285,14 +285,14 @@ pupa_tab_complete (char *buf, int *restore)
pos++;
/* Check if the string is a command or path. */
path = pupa_strchr (pos, ' ');
path = grub_strchr (pos, ' ');
if (!path)
{
/* Tab complete a command. */
len = pupa_strlen (pos);
len = grub_strlen (pos);
pupa_iterate_commands (iterate_commands);
grub_iterate_commands (iterate_commands);
}
else
{
@ -303,17 +303,17 @@ pupa_tab_complete (char *buf, int *restore)
pos++;
/* Check if this is a completion for a device name. */
if (*pos == '(' && !pupa_strchr (pos, ')'))
if (*pos == '(' && !grub_strchr (pos, ')'))
{
/* Check if this is a device or partition. */
char *partition = pupa_strchr (++pos, ',');
char *partition = grub_strchr (++pos, ',');
if (!partition)
{
/* Complete the disk part. */
len = pupa_strlen (pos);
pupa_disk_dev_iterate (iterate_dev);
if (pupa_errno)
len = grub_strlen (pos);
grub_disk_dev_iterate (iterate_dev);
if (grub_errno)
goto fail;
}
else
@ -321,23 +321,23 @@ pupa_tab_complete (char *buf, int *restore)
*partition = '\0';
/* Complete the partition part. */
partdev = pupa_device_open (pos);
partdev = grub_device_open (pos);
*partition = ',';
pupa_errno = PUPA_ERR_NONE;
grub_errno = GRUB_ERR_NONE;
if (partdev)
{
if (partdev->disk && partdev->disk->has_partitions)
{
pos = partition + 1;
len = pupa_strlen (pos);
len = grub_strlen (pos);
pupa_partition_iterate (partdev->disk, iterate_part);
if (pupa_errno)
pupa_errno = 0;
grub_partition_iterate (partdev->disk, iterate_part);
if (grub_errno)
grub_errno = 0;
}
pupa_device_close (partdev);
grub_device_close (partdev);
}
else
goto fail;
@ -345,53 +345,53 @@ pupa_tab_complete (char *buf, int *restore)
}
else
{
char *device = pupa_file_get_device_name (pos);
pupa_device_t dev;
pupa_fs_t fs;
char *device = grub_file_get_device_name (pos);
grub_device_t dev;
grub_fs_t fs;
dev = pupa_device_open (device);
dev = grub_device_open (device);
if (!dev)
goto fail;
fs = pupa_fs_probe (dev);
if (pupa_errno)
fs = grub_fs_probe (dev);
if (grub_errno)
goto fail;
pos = pupa_strrchr (pos, '/');
pos = grub_strrchr (pos, '/');
if (pos)
{
char *dir;
char *dirfile;
pos++;
len = pupa_strlen (pos);
len = grub_strlen (pos);
dir = pupa_strchr (path, '/');
dir = grub_strchr (path, '/');
if (!dir)
{
*restore = 0;
return 0;
}
dir = pupa_strdup (dir);
dir = grub_strdup (dir);
/* Cut away the filename part. */
dirfile = pupa_strrchr (dir, '/');
dirfile = grub_strrchr (dir, '/');
dirfile[1] = '\0';
/* Tab complete a file. */
(fs->dir) (dev, dir, iterate_dir);
if (dev)
pupa_device_close (dev);
grub_device_close (dev);
pupa_free (device);
pupa_free (dir);
grub_free (device);
grub_free (dir);
if (pupa_errno)
if (grub_errno)
goto fail;
}
else
{
found = pupa_strdup ("/");
found = grub_strdup ("/");
matchstr = "";
numfound = 1;
begin = 0;
@ -412,29 +412,29 @@ pupa_tab_complete (char *buf, int *restore)
if (end && found)
{
char *insert;
insert = pupa_malloc (end - begin + 1 + sizeof (matchstr));
pupa_strncpy (insert, found + begin, end - begin);
insert = grub_malloc (end - begin + 1 + sizeof (matchstr));
grub_strncpy (insert, found + begin, end - begin);
insert[end - begin] = '\0';
if (numfound == 1)
pupa_strcat (insert, matchstr);
pupa_free (found);
grub_strcat (insert, matchstr);
grub_free (found);
return insert;
}
fail:
pupa_free (found);
pupa_errno = PUPA_ERR_NONE;
grub_free (found);
grub_errno = GRUB_ERR_NONE;
return 0;
}
void
pupa_cmdline_run (int nested)
grub_cmdline_run (int nested)
{
pupa_normal_init_page ();
grub_normal_init_page ();
pupa_printf ("\
grub_printf ("\
[ Minimal BASH-like line editing is supported. For the first word, TAB\n\
lists possible command completions. Anywhere else TAB lists possible\n\
device/file completions.%s ]\n\n",
@ -442,20 +442,20 @@ pupa_cmdline_run (int nested)
while (1)
{
static char cmdline[PUPA_MAX_CMDLINE];
static char cmdline[GRUB_MAX_CMDLINE];
pupa_print_error ();
pupa_errno = PUPA_ERR_NONE;
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
cmdline[0] = '\0';
if (! pupa_cmdline_get ("pupa> ", cmdline, sizeof (cmdline), 0, 1)
if (! grub_cmdline_get ("grub> ", cmdline, sizeof (cmdline), 0, 1)
&& nested)
return;
if (! *cmdline)
continue;
pupa_command_execute (cmdline);
grub_command_execute (cmdline);
}
}
@ -464,12 +464,12 @@ pupa_cmdline_run (int nested)
available. If ESC is pushed, return non-zero, otherwise return zero. */
/* FIXME: The dumb interface is not supported yet. */
int
pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
int echo_char, int readline)
{
unsigned xpos, ypos, ystart;
pupa_size_t lpos, llen;
pupa_size_t plen;
grub_size_t lpos, llen;
grub_size_t plen;
char buf[max_len];
int key;
int histpos = 0;
@ -482,7 +482,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
{
xpos = (plen + lpos) % 79;
ypos = ystart + (plen + lpos) / 79;
pupa_gotoxy (xpos, ypos);
grub_gotoxy (xpos, ypos);
}
void cl_print (int pos, int c)
@ -493,30 +493,30 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
{
if (xpos++ > 78)
{
pupa_putchar ('\n');
grub_putchar ('\n');
xpos = 1;
if (ypos == (unsigned) (pupa_getxy () & 0xFF))
if (ypos == (unsigned) (grub_getxy () & 0xFF))
ystart--;
else
ypos++;
}
if (c)
pupa_putchar (c);
grub_putchar (c);
else
pupa_putchar (*p);
grub_putchar (*p);
}
}
void cl_insert (const char *str)
{
pupa_size_t len = pupa_strlen (str);
grub_size_t len = grub_strlen (str);
if (len + llen < max_len)
{
pupa_memmove (buf + lpos + len, buf + lpos, llen - lpos + 1);
pupa_memmove (buf + lpos, str, len);
grub_memmove (buf + lpos + len, buf + lpos, llen - lpos + 1);
grub_memmove (buf + lpos, str, len);
llen += len;
lpos += len;
@ -529,7 +529,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
{
if (lpos + len <= llen)
{
pupa_size_t saved_lpos = lpos;
grub_size_t saved_lpos = lpos;
lpos = llen - len;
cl_set_pos ();
@ -537,30 +537,30 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
lpos = saved_lpos;
cl_set_pos ();
pupa_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1);
grub_memmove (buf + lpos, buf + lpos + len, llen - lpos + 1);
llen -= len;
cl_print (lpos, echo_char);
cl_set_pos ();
}
}
plen = pupa_strlen (prompt);
plen = grub_strlen (prompt);
lpos = llen = 0;
buf[0] = '\0';
if ((pupa_getxy () >> 8) != 0)
pupa_putchar ('\n');
if ((grub_getxy () >> 8) != 0)
grub_putchar ('\n');
pupa_printf (prompt);
grub_printf (prompt);
xpos = plen;
ystart = ypos = (pupa_getxy () & 0xFF);
ystart = ypos = (grub_getxy () & 0xFF);
cl_insert (cmdline);
pupa_history_add (buf);
grub_history_add (buf);
while ((key = PUPA_TERM_ASCII_CHAR (pupa_getkey ())) != '\n' && key != '\r')
while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r')
{
if (readline)
{
@ -603,22 +603,22 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
buf[lpos] = '\0';
insert = pupa_tab_complete (buf, &restore);
insert = grub_tab_complete (buf, &restore);
/* Restore the original string. */
buf[lpos] = backup;
if (restore)
{
/* Restore the prompt. */
pupa_printf ("\n%s%s", prompt, buf);
grub_printf ("\n%s%s", prompt, buf);
xpos = plen;
ystart = ypos = (pupa_getxy () & 0xFF);
ystart = ypos = (grub_getxy () & 0xFF);
}
if (insert)
{
cl_insert (insert);
pupa_free (insert);
grub_free (insert);
}
}
break;
@ -627,10 +627,10 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
if (lpos < llen)
{
if (kill_buf)
pupa_free (kill_buf);
grub_free (kill_buf);
kill_buf = pupa_strdup (buf + lpos);
pupa_errno = PUPA_ERR_NONE;
kill_buf = grub_strdup (buf + lpos);
grub_errno = GRUB_ERR_NONE;
cl_delete (llen - lpos);
}
@ -646,7 +646,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
histpos--;
cl_delete (llen);
hist = pupa_history_get (histpos);
hist = grub_history_get (histpos);
cl_insert (hist);
break;
@ -661,7 +661,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
histpos++;
cl_delete (llen);
hist = pupa_history_get (histpos);
hist = grub_history_get (histpos);
cl_insert (hist);
}
@ -670,16 +670,16 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
case 21: /* Ctrl-u */
if (lpos > 0)
{
pupa_size_t n = lpos;
grub_size_t n = lpos;
if (kill_buf)
pupa_free (kill_buf);
grub_free (kill_buf);
kill_buf = pupa_malloc (n + 1);
pupa_errno = PUPA_ERR_NONE;
kill_buf = grub_malloc (n + 1);
grub_errno = GRUB_ERR_NONE;
if (kill_buf)
{
pupa_memcpy (kill_buf, buf, n);
grub_memcpy (kill_buf, buf, n);
kill_buf[n] = '\0';
}
@ -715,7 +715,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
break;
default:
if (pupa_isprint (key))
if (grub_isprint (key))
{
char str[2];
@ -726,11 +726,11 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
break;
}
pupa_history_replace (histpos, buf);
grub_history_replace (histpos, buf);
}
pupa_putchar ('\n');
pupa_refresh ();
grub_putchar ('\n');
grub_refresh ();
/* If ECHO_CHAR is NUL, remove leading spaces. */
lpos = 0;
@ -738,7 +738,7 @@ pupa_cmdline_get (const char *prompt, char cmdline[], unsigned max_len,
while (buf[lpos] == ' ')
lpos++;
pupa_memcpy (cmdline, buf + lpos, llen - lpos + 1);
grub_memcpy (cmdline, buf + lpos, llen - lpos + 1);
return 1;
}

View file

@ -1,5 +1,5 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -17,28 +17,28 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/normal.h>
#include <pupa/misc.h>
#include <pupa/mm.h>
#include <pupa/err.h>
#include <pupa/term.h>
#include <pupa/env.h>
#include <pupa/dl.h>
#include <grub/normal.h>
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/term.h>
#include <grub/env.h>
#include <grub/dl.h>
static pupa_command_t pupa_command_list;
static grub_command_t grub_command_list;
void
pupa_register_command (const char *name,
pupa_err_t (*func) (struct pupa_arg_list *state,
grub_register_command (const char *name,
grub_err_t (*func) (struct grub_arg_list *state,
int argc, char **args),
unsigned flags,
const char *summary,
const char *description,
const struct pupa_arg_option *options)
const struct grub_arg_option *options)
{
pupa_command_t cmd, *p;
grub_command_t cmd, *p;
cmd = (pupa_command_t) pupa_malloc (sizeof (*cmd));
cmd = (grub_command_t) grub_malloc (sizeof (*cmd));
if (! cmd)
return;
@ -50,10 +50,10 @@ pupa_register_command (const char *name,
cmd->options = options;
/* Keep the list sorted for simplicity. */
p = &pupa_command_list;
p = &grub_command_list;
while (*p)
{
if (pupa_strcmp ((*p)->name, name) > 0)
if (grub_strcmp ((*p)->name, name) > 0)
break;
p = &((*p)->next);
@ -64,35 +64,35 @@ pupa_register_command (const char *name,
}
void
pupa_unregister_command (const char *name)
grub_unregister_command (const char *name)
{
pupa_command_t *p, q;
grub_command_t *p, q;
for (p = &pupa_command_list, q = *p; q; p = &(q->next), q = q->next)
if (pupa_strcmp (name, q->name) == 0)
for (p = &grub_command_list, q = *p; q; p = &(q->next), q = q->next)
if (grub_strcmp (name, q->name) == 0)
{
*p = q->next;
pupa_free (q);
grub_free (q);
break;
}
}
pupa_command_t
pupa_command_find (char *cmdline)
grub_command_t
grub_command_find (char *cmdline)
{
char *first_space;
pupa_command_t cmd;
grub_command_t cmd;
first_space = pupa_strchr (cmdline, ' ');
first_space = grub_strchr (cmdline, ' ');
if (first_space)
*first_space = '\0';
for (cmd = pupa_command_list; cmd; cmd = cmd->next)
if (pupa_strcmp (cmdline, cmd->name) == 0)
for (cmd = grub_command_list; cmd; cmd = cmd->next)
if (grub_strcmp (cmdline, cmd->name) == 0)
break;
if (! cmd)
pupa_error (PUPA_ERR_UNKNOWN_COMMAND, "unknown command `%s'", cmdline);
grub_error (GRUB_ERR_UNKNOWN_COMMAND, "unknown command `%s'", cmdline);
if (first_space)
*first_space = ' ';
@ -101,226 +101,226 @@ pupa_command_find (char *cmdline)
}
int
pupa_iterate_commands (int (*iterate) (pupa_command_t))
grub_iterate_commands (int (*iterate) (grub_command_t))
{
pupa_command_t cmd;
for (cmd = pupa_command_list; cmd; cmd = cmd->next)
grub_command_t cmd;
for (cmd = grub_command_list; cmd; cmd = cmd->next)
iterate (cmd);
return 0;
}
int
pupa_command_execute (char *cmdline)
grub_command_execute (char *cmdline)
{
auto pupa_err_t cmdline_get (char **s);
pupa_err_t cmdline_get (char **s)
auto grub_err_t cmdline_get (char **s);
grub_err_t cmdline_get (char **s)
{
*s = pupa_malloc (PUPA_MAX_CMDLINE);
*s = grub_malloc (GRUB_MAX_CMDLINE);
*s[0] = '\0';
return pupa_cmdline_get (">", *s, PUPA_MAX_CMDLINE, 0, 1);
return grub_cmdline_get (">", *s, GRUB_MAX_CMDLINE, 0, 1);
}
pupa_command_t cmd;
pupa_err_t ret = 0;
grub_command_t cmd;
grub_err_t ret = 0;
char *pager;
int num;
char **args;
struct pupa_arg_list *state;
struct pupa_arg_option *parser;
struct grub_arg_list *state;
struct grub_arg_option *parser;
int maxargs = 0;
char **arglist;
int numargs;
if (pupa_split_cmdline (cmdline, cmdline_get, &num, &args))
if (grub_split_cmdline (cmdline, cmdline_get, &num, &args))
return 0;
/* In case of an assignment set the environment accordingly instead
of calling a function. */
if (num == 0 && pupa_strchr (args[0], '='))
if (num == 0 && grub_strchr (args[0], '='))
{
char *val = pupa_strchr (args[0], '=');
char *val = grub_strchr (args[0], '=');
val[0] = 0;
pupa_env_set (args[0], val + 1);
grub_env_set (args[0], val + 1);
val[0] = '=';
return 0;
}
cmd = pupa_command_find (args[0]);
cmd = grub_command_find (args[0]);
if (! cmd)
return -1;
/* Enable the pager if the environment pager is set to 1. */
pager = pupa_env_get ("pager");
if (pager && (! pupa_strcmp (pager, "1")))
pupa_set_more (1);
pager = grub_env_get ("pager");
if (pager && (! grub_strcmp (pager, "1")))
grub_set_more (1);
parser = (struct pupa_arg_option *) cmd->options;
parser = (struct grub_arg_option *) cmd->options;
while (parser && (parser++)->doc)
maxargs++;
state = pupa_malloc (sizeof (struct pupa_arg_list) * maxargs);
pupa_memset (state, 0, sizeof (struct pupa_arg_list) * maxargs);
if (pupa_arg_parse (cmd, num, &args[1], state, &arglist, &numargs))
state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
if (grub_arg_parse (cmd, num, &args[1], state, &arglist, &numargs))
ret = (cmd->func) (state, numargs, arglist);
pupa_free (state);
grub_free (state);
if (pager && (! pupa_strcmp (pager, "1")))
pupa_set_more (0);
if (pager && (! grub_strcmp (pager, "1")))
grub_set_more (0);
pupa_free (args);
grub_free (args);
return ret;
}
static pupa_err_t
rescue_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
rescue_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
pupa_longjmp (pupa_exit_env, 0);
grub_longjmp (grub_exit_env, 0);
/* Never reach here. */
return 0;
}
static pupa_err_t
set_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
set_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc, char **args)
{
char *var;
char *val;
auto int print_env (struct pupa_env_var *env);
int print_env (struct pupa_env_var *env)
auto int print_env (struct grub_env_var *env);
int print_env (struct grub_env_var *env)
{
pupa_printf ("%s=%s\n", env->name, env->value);
grub_printf ("%s=%s\n", env->name, env->value);
return 0;
}
if (! argc)
{
pupa_env_iterate (print_env);
grub_env_iterate (print_env);
return 0;
}
var = args[0];
val = pupa_strchr (var, '=');
val = grub_strchr (var, '=');
if (! val)
{
pupa_error (PUPA_ERR_BAD_ARGUMENT, "not an assignment");
return pupa_errno;
grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment");
return grub_errno;
}
val[0] = 0;
pupa_env_set (var, val + 1);
grub_env_set (var, val + 1);
val[0] = '=';
return 0;
}
static pupa_err_t
unset_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
unset_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc, char **args)
{
if (argc < 1)
return pupa_error (PUPA_ERR_BAD_ARGUMENT,
return grub_error (GRUB_ERR_BAD_ARGUMENT,
"no environment variable specified");
pupa_env_unset (args[0]);
grub_env_unset (args[0]);
return 0;
}
static pupa_err_t
insmod_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
insmod_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc, char **args)
{
char *p;
pupa_dl_t mod;
grub_dl_t mod;
if (argc == 0)
return pupa_error (PUPA_ERR_BAD_ARGUMENT, "no module specified");
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
p = pupa_strchr (args[0], '/');
p = grub_strchr (args[0], '/');
if (! p)
mod = pupa_dl_load (args[0]);
mod = grub_dl_load (args[0]);
else
mod = pupa_dl_load_file (args[0]);
mod = grub_dl_load_file (args[0]);
if (mod)
pupa_dl_ref (mod);
grub_dl_ref (mod);
return 0;
}
static pupa_err_t
rmmod_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
rmmod_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc, char **args)
{
pupa_dl_t mod;
grub_dl_t mod;
if (argc == 0)
return pupa_error (PUPA_ERR_BAD_ARGUMENT, "no module specified");
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
mod = pupa_dl_get (args[0]);
mod = grub_dl_get (args[0]);
if (! mod)
return pupa_error (PUPA_ERR_BAD_ARGUMENT, "no such module");
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
if (! pupa_dl_unref (mod))
pupa_dl_unload (mod);
if (! grub_dl_unref (mod))
grub_dl_unload (mod);
return 0;
}
static pupa_err_t
lsmod_command (struct pupa_arg_list *state __attribute__ ((unused)),
static grub_err_t
lsmod_command (struct grub_arg_list *state __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char **args __attribute__ ((unused)))
{
auto int print_module (pupa_dl_t mod);
auto int print_module (grub_dl_t mod);
int print_module (pupa_dl_t mod)
int print_module (grub_dl_t mod)
{
pupa_dl_dep_t dep;
grub_dl_dep_t dep;
pupa_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
for (dep = mod->dep; dep; dep = dep->next)
{
if (dep != mod->dep)
pupa_putchar (',');
grub_putchar (',');
pupa_printf ("%s", dep->mod->name);
grub_printf ("%s", dep->mod->name);
}
pupa_putchar ('\n');
pupa_refresh ();
grub_putchar ('\n');
grub_refresh ();
return 0;
}
pupa_printf ("Name\tRef Count\tDependencies\n");
pupa_dl_iterate (print_module);
grub_printf ("Name\tRef Count\tDependencies\n");
grub_dl_iterate (print_module);
return 0;
}
void
pupa_command_init (void)
grub_command_init (void)
{
/* This is a special command, because this never be called actually. */
pupa_register_command ("title", 0, PUPA_COMMAND_FLAG_TITLE, 0, 0, 0);
grub_register_command ("title", 0, GRUB_COMMAND_FLAG_TITLE, 0, 0, 0);
pupa_register_command ("rescue", rescue_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("rescue", rescue_command, GRUB_COMMAND_FLAG_BOTH,
"rescue", "Enter into the rescue mode.", 0);
pupa_register_command ("set", set_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("set", set_command, GRUB_COMMAND_FLAG_BOTH,
"unset ENVVAR", "Set an environment variable.", 0);
pupa_register_command ("unset", unset_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("unset", unset_command, GRUB_COMMAND_FLAG_BOTH,
"set [ENVVAR=VALUE]", "Remove an environment variable.", 0);
pupa_register_command ("insmod", insmod_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("insmod", insmod_command, GRUB_COMMAND_FLAG_BOTH,
"insmod MODULE|FILE", "Insert a module.", 0);
pupa_register_command ("rmmod", rmmod_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("rmmod", rmmod_command, GRUB_COMMAND_FLAG_BOTH,
"rmmod MODULE", "Remove a module.", 0);
pupa_register_command ("lsmod", lsmod_command, PUPA_COMMAND_FLAG_BOTH,
grub_register_command ("lsmod", lsmod_command, GRUB_COMMAND_FLAG_BOTH,
"lsmod", "Show loaded modules.", 0);
}

View file

@ -1,5 +1,5 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -17,16 +17,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/symbol.h>
#include <grub/symbol.h>
.file "setjmp.S"
.text
/*
* int pupa_setjmp (pupa_jmp_buf env)
* int grub_setjmp (grub_jmp_buf env)
*/
FUNCTION(pupa_setjmp)
FUNCTION(grub_setjmp)
movl %ebx, 0(%eax) /* EBX */
movl %esi, 4(%eax) /* ESI */
movl %edi, 8(%eax) /* EDI */
@ -39,9 +39,9 @@ FUNCTION(pupa_setjmp)
/*
* int pupa_longjmp (pupa_jmp_buf env, int val)
* int grub_longjmp (grub_jmp_buf env, int val)
*/
FUNCTION(pupa_longjmp)
FUNCTION(grub_longjmp)
movl 0(%eax), %ebx
movl 4(%eax), %esi
movl 8(%eax), %edi

View file

@ -1,6 +1,6 @@
/* main.c - the normal mode main routine */
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2000,2001,2002,2003 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -18,23 +18,23 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/kernel.h>
#include <pupa/normal.h>
#include <pupa/dl.h>
#include <pupa/rescue.h>
#include <pupa/misc.h>
#include <pupa/file.h>
#include <pupa/mm.h>
#include <pupa/term.h>
#include <pupa/env.h>
#include <grub/kernel.h>
#include <grub/normal.h>
#include <grub/dl.h>
#include <grub/rescue.h>
#include <grub/misc.h>
#include <grub/file.h>
#include <grub/mm.h>
#include <grub/term.h>
#include <grub/env.h>
pupa_jmp_buf pupa_exit_env;
grub_jmp_buf grub_exit_env;
#define PUPA_DEFAULT_HISTORY_SIZE 50
#define GRUB_DEFAULT_HISTORY_SIZE 50
/* Read a line from the file FILE. */
static int
get_line (pupa_file_t file, char cmdline[], int max_len)
get_line (grub_file_t file, char cmdline[], int max_len)
{
char c;
int pos = 0;
@ -43,7 +43,7 @@ get_line (pupa_file_t file, char cmdline[], int max_len)
while (1)
{
if (pupa_file_read (file, &c, 1) != 1)
if (grub_file_read (file, &c, 1) != 1)
break;
/* Skip all carriage returns. */
@ -82,7 +82,7 @@ get_line (pupa_file_t file, char cmdline[], int max_len)
{
if (c == '#')
comment = 1;
else if (! pupa_isspace (c))
else if (! grub_isspace (c))
cmdline[pos++] = c;
}
else
@ -101,51 +101,51 @@ get_line (pupa_file_t file, char cmdline[], int max_len)
}
static void
free_menu (pupa_menu_t menu)
free_menu (grub_menu_t menu)
{
pupa_menu_entry_t entry = menu->entry_list;
grub_menu_entry_t entry = menu->entry_list;
while (entry)
{
pupa_menu_entry_t next_entry = entry->next;
pupa_command_list_t cmd = entry->command_list;
grub_menu_entry_t next_entry = entry->next;
grub_command_list_t cmd = entry->command_list;
while (cmd)
{
pupa_command_list_t next_cmd = cmd->next;
grub_command_list_t next_cmd = cmd->next;
pupa_free ((void *) cmd->command);
grub_free ((void *) cmd->command);
cmd = next_cmd;
}
pupa_free ((void *) entry->title);
grub_free ((void *) entry->title);
entry = next_entry;
}
pupa_free (menu);
grub_free (menu);
}
/* Read the config file CONFIG and return a menu. If no entry is present,
return NULL. */
static pupa_menu_t
static grub_menu_t
read_config_file (const char *config)
{
pupa_file_t file;
static char cmdline[PUPA_MAX_CMDLINE];
pupa_menu_t menu;
pupa_menu_entry_t *next_entry, cur_entry = 0;
pupa_command_list_t *next_cmd, cur_cmd;
grub_file_t file;
static char cmdline[GRUB_MAX_CMDLINE];
grub_menu_t menu;
grub_menu_entry_t *next_entry, cur_entry = 0;
grub_command_list_t *next_cmd, cur_cmd;
/* Try to open the config file. */
file = pupa_file_open (config);
file = grub_file_open (config);
if (! file)
return 0;
/* Initialize the menu. */
menu = (pupa_menu_t) pupa_malloc (sizeof (*menu));
menu = (grub_menu_t) grub_malloc (sizeof (*menu));
if (! menu)
{
pupa_file_close (file);
grub_file_close (file);
return 0;
}
menu->default_entry = 0;
@ -160,33 +160,33 @@ read_config_file (const char *config)
/* Read each line. */
while (get_line (file, cmdline, sizeof (cmdline)))
{
pupa_command_t cmd;
grub_command_t cmd;
cmd = pupa_command_find (cmdline);
pupa_errno = PUPA_ERR_NONE;
cmd = grub_command_find (cmdline);
grub_errno = GRUB_ERR_NONE;
if (! cmd)
{
pupa_printf ("Unknown command `%s' is ignored.\n", cmdline);
grub_printf ("Unknown command `%s' is ignored.\n", cmdline);
continue;
}
if (cmd->flags & PUPA_COMMAND_FLAG_TITLE)
if (cmd->flags & GRUB_COMMAND_FLAG_TITLE)
{
char *p;
cur_entry = (pupa_menu_entry_t) pupa_malloc (sizeof (*cur_entry));
cur_entry = (grub_menu_entry_t) grub_malloc (sizeof (*cur_entry));
if (! cur_entry)
goto fail;
p = pupa_strchr (cmdline, ' ');
p = grub_strchr (cmdline, ' ');
if (p)
cur_entry->title = pupa_strdup (p);
cur_entry->title = grub_strdup (p);
else
cur_entry->title = pupa_strdup ("");
cur_entry->title = grub_strdup ("");
if (! cur_entry->title)
{
pupa_free (cur_entry);
grub_free (cur_entry);
goto fail;
}
@ -204,28 +204,28 @@ read_config_file (const char *config)
else if (! cur_entry)
{
/* Run the command if possible. */
if (cmd->flags & PUPA_COMMAND_FLAG_MENU)
if (cmd->flags & GRUB_COMMAND_FLAG_MENU)
{
pupa_command_execute (cmdline);
pupa_print_error ();
pupa_errno = PUPA_ERR_NONE;
grub_command_execute (cmdline);
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
}
else
{
pupa_printf ("Invalid command `%s' is ignored.\n", cmdline);
grub_printf ("Invalid command `%s' is ignored.\n", cmdline);
continue;
}
}
else
{
cur_cmd = (pupa_command_list_t) pupa_malloc (sizeof (*cur_cmd));
cur_cmd = (grub_command_list_t) grub_malloc (sizeof (*cur_cmd));
if (! cur_cmd)
goto fail;
cur_cmd->command = pupa_strdup (cmdline);
cur_cmd->command = grub_strdup (cmdline);
if (! cur_cmd->command)
{
pupa_free (cur_cmd);
grub_free (cur_cmd);
goto fail;
}
@ -240,10 +240,10 @@ read_config_file (const char *config)
fail:
pupa_file_close (file);
grub_file_close (file);
/* If no entry was found or any error occurred, return NULL. */
if (menu->size == 0 || pupa_errno != PUPA_ERR_NONE)
if (menu->size == 0 || grub_errno != GRUB_ERR_NONE)
{
free_menu (menu);
return 0;
@ -269,46 +269,46 @@ read_config_file (const char *config)
/* This starts the normal mode. */
void
pupa_enter_normal_mode (const char *config)
grub_enter_normal_mode (const char *config)
{
if (pupa_setjmp (pupa_exit_env) == 0)
pupa_normal_execute (config, 0);
if (grub_setjmp (grub_exit_env) == 0)
grub_normal_execute (config, 0);
}
/* Initialize the screen. */
void
pupa_normal_init_page (void)
grub_normal_init_page (void)
{
pupa_cls ();
pupa_printf ("\n\
PUPA version %s\n\n",
grub_cls ();
grub_printf ("\n\
GRUB version %s\n\n",
PACKAGE_VERSION);
}
/* Read the config file CONFIG and execute the menu interface or
the command-line interface. */
void
pupa_normal_execute (const char *config, int nested)
grub_normal_execute (const char *config, int nested)
{
pupa_menu_t menu = 0;
grub_menu_t menu = 0;
if (config)
{
menu = read_config_file (config);
/* Ignore any error. */
pupa_errno = PUPA_ERR_NONE;
grub_errno = GRUB_ERR_NONE;
}
if (menu)
pupa_menu_run (menu, nested);
grub_menu_run (menu, nested);
else
pupa_cmdline_run (nested);
grub_cmdline_run (nested);
}
/* Enter normal mode from rescue mode. */
static void
pupa_rescue_cmd_normal (int argc, char *argv[])
grub_rescue_cmd_normal (int argc, char *argv[])
{
if (argc == 0)
{
@ -316,65 +316,65 @@ pupa_rescue_cmd_normal (int argc, char *argv[])
char *config;
const char *prefix;
prefix = pupa_env_get ("prefix");
prefix = grub_env_get ("prefix");
if (prefix)
{
config = pupa_malloc (pupa_strlen (prefix) + sizeof ("/pupa.cfg"));
config = grub_malloc (grub_strlen (prefix) + sizeof ("/grub.cfg"));
if (! config)
return;
pupa_sprintf (config, "%s/pupa.cfg", prefix);
pupa_enter_normal_mode (config);
pupa_free (config);
grub_sprintf (config, "%s/grub.cfg", prefix);
grub_enter_normal_mode (config);
grub_free (config);
}
else
pupa_enter_normal_mode (0);
grub_enter_normal_mode (0);
}
else
pupa_enter_normal_mode (argv[0]);
grub_enter_normal_mode (argv[0]);
}
#ifdef PUPA_UTIL
#ifdef GRUB_UTIL
void
pupa_normal_init (void)
grub_normal_init (void)
{
pupa_set_history (PUPA_DEFAULT_HISTORY_SIZE);
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
/* Register a command "normal" for the rescue mode. */
pupa_rescue_register_command ("normal", pupa_rescue_cmd_normal,
grub_rescue_register_command ("normal", grub_rescue_cmd_normal,
"enter normal mode");
/* This registers some built-in commands. */
pupa_command_init ();
grub_command_init ();
}
void
pupa_normal_fini (void)
grub_normal_fini (void)
{
pupa_set_history (0);
pupa_rescue_unregister_command ("normal");
grub_set_history (0);
grub_rescue_unregister_command ("normal");
}
#else /* ! PUPA_UTIL */
PUPA_MOD_INIT
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
/* Normal mode shouldn't be unloaded. */
pupa_dl_ref (mod);
grub_dl_ref (mod);
pupa_set_history (PUPA_DEFAULT_HISTORY_SIZE);
grub_set_history (GRUB_DEFAULT_HISTORY_SIZE);
/* Register a command "normal" for the rescue mode. */
pupa_rescue_register_command ("normal", pupa_rescue_cmd_normal,
grub_rescue_register_command ("normal", grub_rescue_cmd_normal,
"enter normal mode");
/* This registers some built-in commands. */
pupa_command_init ();
grub_command_init ();
}
PUPA_MOD_FINI
GRUB_MOD_FINI
{
pupa_set_history (0);
pupa_rescue_unregister_command ("normal");
grub_set_history (0);
grub_rescue_unregister_command ("normal");
}
#endif /* ! PUPA_UTIL */
#endif /* ! GRUB_UTIL */

View file

@ -1,5 +1,5 @@
/*
* PUPA -- Preliminary Universal Programming Architecture for GRUB
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2003 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
@ -17,9 +17,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <pupa/normal.h>
#include <pupa/term.h>
#include <pupa/misc.h>
#include <grub/normal.h>
#include <grub/term.h>
#include <grub/misc.h>
/* FIXME: These below are all runaround. */
@ -39,55 +39,55 @@ draw_border (void)
{
unsigned i;
pupa_setcolorstate (PUPA_TERM_COLOR_NORMAL);
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
pupa_gotoxy (1, 3);
pupa_putcode (DISP_UL);
grub_gotoxy (1, 3);
grub_putcode (DISP_UL);
for (i = 0; i < 73; i++)
pupa_putcode (DISP_HLINE);
pupa_putcode (DISP_UR);
grub_putcode (DISP_HLINE);
grub_putcode (DISP_UR);
i = 1;
while (1)
{
pupa_gotoxy (1, 3 + i);
grub_gotoxy (1, 3 + i);
if (i > 12)
break;
pupa_putcode (DISP_VLINE);
pupa_gotoxy (75, 3 + i);
pupa_putcode (DISP_VLINE);
grub_putcode (DISP_VLINE);
grub_gotoxy (75, 3 + i);
grub_putcode (DISP_VLINE);
i++;
}
pupa_putcode (DISP_LL);
grub_putcode (DISP_LL);
for (i = 0; i < 73; i++)
pupa_putcode (DISP_HLINE);
pupa_putcode (DISP_LR);
grub_putcode (DISP_HLINE);
grub_putcode (DISP_LR);
pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
}
static void
print_message (int nested)
{
pupa_printf ("\n\
grub_printf ("\n\
Use the %C and %C keys to select which entry is highlighted.\n",
(pupa_uint32_t) DISP_UP, (pupa_uint32_t) DISP_DOWN);
pupa_printf ("\
(grub_uint32_t) DISP_UP, (grub_uint32_t) DISP_DOWN);
grub_printf ("\
Press enter to boot the selected OS, \'e\' to edit the\n\
commands before booting, or \'c\' for a command-line.");
if (nested)
pupa_printf ("\
grub_printf ("\
ESC to return previous menu.");
}
static pupa_menu_entry_t
get_entry (pupa_menu_t menu, int no)
static grub_menu_entry_t
get_entry (grub_menu_t menu, int no)
{
pupa_menu_entry_t e;
grub_menu_entry_t e;
for (e = menu->entry_list; e && no > 0; e = e->next, no--)
;
@ -96,48 +96,48 @@ get_entry (pupa_menu_t menu, int no)
}
static void
print_entry (int y, int highlight, pupa_menu_entry_t entry)
print_entry (int y, int highlight, grub_menu_entry_t entry)
{
int x;
const char *title;
title = entry ? entry->title : "";
pupa_setcolorstate (highlight
? PUPA_TERM_COLOR_HIGHLIGHT
: PUPA_TERM_COLOR_NORMAL);
grub_setcolorstate (highlight
? GRUB_TERM_COLOR_HIGHLIGHT
: GRUB_TERM_COLOR_NORMAL);
pupa_gotoxy (2, y);
pupa_putchar (' ');
grub_gotoxy (2, y);
grub_putchar (' ');
for (x = 3; x < 75; x++)
{
if (*title && x <= 72)
{
if (x == 72)
pupa_putcode (DISP_RIGHT);
grub_putcode (DISP_RIGHT);
else
pupa_putchar (*title++);
grub_putchar (*title++);
}
else
pupa_putchar (' ');
grub_putchar (' ');
}
pupa_gotoxy (74, y);
grub_gotoxy (74, y);
pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
}
static void
print_entries (pupa_menu_t menu, int first, int offset)
print_entries (grub_menu_t menu, int first, int offset)
{
pupa_menu_entry_t e;
grub_menu_entry_t e;
int i;
pupa_gotoxy (77, 4);
grub_gotoxy (77, 4);
if (first)
pupa_putcode (DISP_UP);
grub_putcode (DISP_UP);
else
pupa_putchar (' ');
grub_putchar (' ');
e = get_entry (menu, first);
@ -148,30 +148,30 @@ print_entries (pupa_menu_t menu, int first, int offset)
e = e->next;
}
pupa_gotoxy (77, 4 + 12);
grub_gotoxy (77, 4 + 12);
if (e)
pupa_putcode (DISP_DOWN);
grub_putcode (DISP_DOWN);
else
pupa_putchar (' ');
grub_putchar (' ');
pupa_gotoxy (74, 4 + offset);
grub_gotoxy (74, 4 + offset);
}
static void
init_page (int nested)
{
pupa_normal_init_page ();
grub_normal_init_page ();
draw_border ();
print_message (nested);
}
static int
run_menu (pupa_menu_t menu, int nested)
run_menu (grub_menu_t menu, int nested)
{
int first, offset;
pupa_setcursor (0);
grub_setcursor (0);
first = 0;
offset = menu->default_entry;
@ -183,13 +183,13 @@ run_menu (pupa_menu_t menu, int nested)
init_page (nested);
print_entries (menu, first, offset);
pupa_refresh ();
grub_refresh ();
while (1)
{
int c;
c = PUPA_TERM_ASCII_CHAR (pupa_getkey ());
c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
switch (c)
{
case 16:
@ -230,21 +230,21 @@ run_menu (pupa_menu_t menu, int nested)
case '\n':
case '\r':
case 6:
pupa_setcursor (1);
grub_setcursor (1);
return first + offset;
case '\e':
if (nested)
{
pupa_setcursor (1);
grub_setcursor (1);
return -1;
}
break;
case 'c':
pupa_setcursor (1);
pupa_cmdline_run (1);
pupa_setcursor (0);
grub_setcursor (1);
grub_cmdline_run (1);
grub_setcursor (0);
init_page (nested);
print_entries (menu, first, offset);
break;
@ -253,7 +253,7 @@ run_menu (pupa_menu_t menu, int nested)
break;
}
pupa_refresh ();
grub_refresh ();
}
/* Never reach here. */
@ -261,7 +261,7 @@ run_menu (pupa_menu_t menu, int nested)
}
void
pupa_menu_run (pupa_menu_t menu, int nested)
grub_menu_run (grub_menu_t menu, int nested)
{
while (1)
{