2004-03-14 Marco Gerards <metgerards@student.han.nl>
* commands/boot.c: New file. * commands/cat.c: Likewise. * commands/cmp.c: Likewise. * commands/ls.c: Likewise. * commands/terminal.c: Likewise. * normal/command.c: Include <pupa/env.h> and <pupa/dl.h>. (pupa_register_command): Changed interface to match the new argument parser. (pupa_command_execute): Changed (almost rewritten) so it uses pupa_split_command. Added support for setting variables using the syntax `foo=bar'. (rescue_command): Changed to work with the new argument parser. (terminal_command): Moved from here to commands/terminal.c. (set_command): New function. (unset_command): New function. (insmod_command): New function. (rmmod_command): New function. (lsmod_command): New function. (pupa_command_init): Don't initialize the command terminal anymore. Initialize the commands set, unset, insmod, rmmod and lsmod. * conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/env.c. (kernel_img_HEADERS): Add arg.h and env.h. (pupa_mkimage_LDFLAGS): Add kern/env.c. (pupa_emu_SOURCES): Add kern/env.c, commands/ls.c, commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c, normal/arg.c. (pkgdata_MODULES): Add ls.mod, boot.mod, cmp.mod, cat.mod and terminal.mod. (normal_mod_SOURCES): Add normal/arg.c and normal/arg.c. (boot_mod_SOURCES): New variable. (terminal_mod_SOURCES): Likewise. (ls_mod_SOURCES): Likewise. (cmp_mod_SOURCES): Likewise. (cat_mod_SOURCES): Likewise. * normal/arg.c: New file. * kern/env.c: Likewise. * include/pupa/arg.h: Likewise. * include/pupa/env.h: Likewise. * font/manager.c (font_command): Changed to match argument parsing interface changes. (PUPA_MOD_INIT): Likewise. * hello/hello.c (pupa_cmd_hello): Likewise. (PUPA_MOD_INIT): Likewise. * include/pupa/disk.h: Include <pupa/device.h>. (pupa_print_partinfo): New prototype. * include/pupa/dl.h (pupa_dl_set_prefix): Prototype removed. (pupa_dl_get_prefix): Likewise. * include/pupa/misc.h: Include <pupa/err.h>. (pupa_isgraph): New prototype. (pupa_isdigit): Likewise. (pupa_split_cmdline): Likewise. * include/pupa/normal.h: Include <pupa/arg.h>. (pupa_command): Changed the prototype of the member `func' to match the argument parsing interface. Added member `options'. (pupa_register_command): Updated to match function. (pupa_arg_parse): New prototype. (pupa_hello_init) [PUPA_UTIL]: New prototype. (pupa_hello_fini) [PUPA_UTIL]: Likewise. (pupa_ls_init) [PUPA_UTIL]: Likewise. (pupa_ls_fini) [PUPA_UTIL]: Likewise. (pupa_cat_init) [PUPA_UTIL]: Likewise. (pupa_cat_fini) [PUPA_UTIL]: Likewise. (pupa_boot_init) [PUPA_UTIL]: Likewise. (pupa_boot_fini) [PUPA_UTIL]: Likewise. (pupa_cmp_init) [PUPA_UTIL]: Likewise. (pupa_cmp_fini) [PUPA_UTIL]: Likewise. (pupa_terminal_init) [PUPA_UTIL]: Likewise. (pupa_terminal_fini) [PUPA_UTIL]: Likewise. * kern/disk.c: Include <pupa/file.h>. (pupa_print_partinfo): New function. * kern/dl.c: Include <pupa/env.h>. (pupa_dl_dir): Variable removed. (pupa_dl_load): Use the environment variable `prefix' instead of the variable pupa_dl_dir. (pupa_dl_set_prefix): Function removed. (pupa_dl_get_prefix): Likewise. * kern/i386/pc/init.c: Include <pupa/env.h>. (pupa_machine_init): Use the environment variable `prefix' instead of using pupa_dl_set_prefix to set the prefix. * kern/main.c: Include <pupa/env.h>. (pupa_set_root_dev): Use the environment variable `prefix' instead of using pupa_dl_get_prefix to get the prefix. * kern/misc.c: Include <pupa/env.h>. (pupa_isdigit): New function. (pupa_isgraph): Likewise. (pupa_ftoa): Likewise. (pupa_vsprintf): Added support for printing values of the type `double'. Make it possible to format variable output when using formatting like `%1.2%f'. (pupa_split_cmdline): New function. * kern/rescue.c: Include <pupa/env.h>. (next_word): Removed function. (pupa_rescue_cmd_prefix): Likewise. (pupa_rescue_cmd_set): New function. (pupa_rescue_cmd_unset): New function. (pupa_enter_rescue_mode): Use the `pupa_split_cmdline' function to split the command line instead of splitting it here. Added support for setting variables using the syntax `foo=bar'. Don't initialize the prefix command anymore. Initialized the set and unset commands. * normal/cmdline.c: Include <pupa/env.h>. (pupa_tab_complete): Added prototypes for print_simple_completion, print_partition_completion, add_completion, iterate_commands, iterate_dev, iterate_part and iterate_dir. Moved code to print partition information from here to kern/disk.c. (pupa_cmdline_run): Don't check if the funtion exists anymore. * normal/main.c: Include <pupa/env.h>. (pupa_rescue_cmd_normal): Use the environment variable `prefix' instead of using pupa_dl_get_prefix to get the prefix. * term/i386/pc/vga.c: Include <pupa/arg.h>. (check_vga_mem): Cast pointers to `void *' to silence a gcc warning. (pupa_vga_putchar) [! DEBUG_VGA]: Removed for this case. (pupa_vga_setcolor): Declare unused variables with `__attribute__ ((unused))' to silence a gcc warning. (pupa_vga_setcolor): Likewise. (debug_command): Changed to match argument parsing interface changes. * util/pupa-emu.c: Include <pupa/env.h>. (options): Added 0's for unused fields to silence a gcc warning. (argp): Likewise. (main): Use the environment variable `prefix' instead of using pupa_dl_set_prefix to set the prefix. Initialize the commands ls, boot, cmp, cat and terminal. Finish the commands boot, cmp, cat and terminal. * util/i386/pc/getroot.c: Include <pupa/i386/pc/util/biosdisk.h>. * util/misc.c: Include <malloc.h>. (pupa_malloc): Rewritten so errors are correctly reported. (pupa_realloc): Likewise. (pupa_memalign): Likewise. (pupa_mm_init_region): Declare unused variables with `__attribute__ ((unused))' to silence a gcc warning. * normal/i386/setjmp.S: Remove tab at the end of the file to silence a gcc warning. * loader/i386/pc/linux.c (pupa_rescue_cmd_initrd): Declare unused variables with `__attribute__ ((unused))' to silence a gcc warning. * loader/i386/pc/multiboot.c (pupa_multiboot_unload): Make the local variable i unsigned to silence a gcc warning. * kern/term.c: Include <pupa/misc.h>. (pupa_more_lines): New variable. (pupa_more): Likewise. (pupa_putcode): When the pager is active pause at the end of every screen. (pupa_set_more): New function. * include/pupa/term.h (pupa_set_more): New prototype.
This commit is contained in:
parent
3b1139cb9d
commit
db1771cfbe
35 changed files with 2607 additions and 285 deletions
148
kern/rescue.c
148
kern/rescue.c
|
@ -1,7 +1,7 @@
|
|||
/* rescue.c - rescue mode */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,6 +29,7 @@
|
|||
#include <pupa/loader.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/machine/partition.h>
|
||||
#include <pupa/env.h>
|
||||
|
||||
#define PUPA_RESCUE_BUF_SIZE 256
|
||||
#define PUPA_RESCUE_MAX_ARGS 20
|
||||
|
@ -116,29 +117,6 @@ pupa_rescue_get_command_line (const char *prompt)
|
|||
pupa_refresh ();
|
||||
}
|
||||
|
||||
/* Get the next word in STR and return a next pointer. */
|
||||
static char *
|
||||
next_word (char **str)
|
||||
{
|
||||
char *word;
|
||||
char *p = *str;
|
||||
|
||||
/* Skip spaces. */
|
||||
while (*p && pupa_isspace (*p))
|
||||
p++;
|
||||
|
||||
word = p;
|
||||
|
||||
/* Find a space. */
|
||||
while (*p && ! pupa_isspace (*p))
|
||||
p++;
|
||||
|
||||
*p = '\0';
|
||||
*str = p + 1;
|
||||
|
||||
return word;
|
||||
}
|
||||
|
||||
/* boot */
|
||||
static void
|
||||
pupa_rescue_cmd_boot (int argc __attribute__ ((unused)),
|
||||
|
@ -506,27 +484,6 @@ pupa_rescue_cmd_dump (int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
/* prefix [DIR] */
|
||||
static void
|
||||
pupa_rescue_cmd_prefix (int argc, char *argv[])
|
||||
{
|
||||
static char prefix[100];
|
||||
|
||||
if (argc == 0)
|
||||
pupa_printf ("%s\n", pupa_dl_get_prefix ());
|
||||
else
|
||||
{
|
||||
if (pupa_strlen (argv[0]) >= sizeof (prefix))
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "too long prefix");
|
||||
return;
|
||||
}
|
||||
|
||||
pupa_strcpy (prefix, argv[0]);
|
||||
pupa_dl_set_prefix (prefix);
|
||||
}
|
||||
}
|
||||
|
||||
/* insmod MODULE */
|
||||
static void
|
||||
pupa_rescue_cmd_insmod (int argc, char *argv[])
|
||||
|
@ -602,6 +559,52 @@ pupa_rescue_cmd_lsmod (int argc __attribute__ ((unused)),
|
|||
pupa_dl_iterate (print_module);
|
||||
}
|
||||
|
||||
/* set ENVVAR=VALUE */
|
||||
static void
|
||||
pupa_rescue_cmd_set (int argc, char *argv[])
|
||||
{
|
||||
char *var;
|
||||
char *val;
|
||||
|
||||
auto int print_env (struct pupa_env_var *env);
|
||||
|
||||
int print_env (struct pupa_env_var *env)
|
||||
{
|
||||
pupa_printf ("%s=%s\n", env->name, env->value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_env_iterate (print_env);
|
||||
return;
|
||||
}
|
||||
|
||||
var = argv[0];
|
||||
val = pupa_strchr (var, '=');
|
||||
if (! val)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "not an assignment");
|
||||
return;
|
||||
}
|
||||
|
||||
val[0] = 0;
|
||||
pupa_env_set (var, val + 1);
|
||||
val[0] = '=';
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_rescue_cmd_unset (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no environment variable specified");
|
||||
return;
|
||||
}
|
||||
|
||||
pupa_env_unset (argv[0]);
|
||||
}
|
||||
|
||||
static void
|
||||
attempt_normal_mode (void)
|
||||
{
|
||||
|
@ -621,6 +624,15 @@ attempt_normal_mode (void)
|
|||
void
|
||||
pupa_enter_rescue_mode (void)
|
||||
{
|
||||
auto pupa_err_t getline (char **line);
|
||||
|
||||
pupa_err_t getline (char **line)
|
||||
{
|
||||
pupa_rescue_get_command_line ("> ");
|
||||
*line = linebuf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* First of all, attempt to execute the normal mode. */
|
||||
attempt_normal_mode ();
|
||||
|
||||
|
@ -638,14 +650,16 @@ pupa_enter_rescue_mode (void)
|
|||
"set the root device");
|
||||
pupa_rescue_register_command ("dump", pupa_rescue_cmd_dump,
|
||||
"dump memory");
|
||||
pupa_rescue_register_command ("prefix", pupa_rescue_cmd_prefix,
|
||||
"set the prefix");
|
||||
pupa_rescue_register_command ("insmod", pupa_rescue_cmd_insmod,
|
||||
"insert a module");
|
||||
pupa_rescue_register_command ("rmmod", pupa_rescue_cmd_rmmod,
|
||||
"remove a module");
|
||||
pupa_rescue_register_command ("lsmod", pupa_rescue_cmd_lsmod,
|
||||
"show loaded modules");
|
||||
pupa_rescue_register_command ("set", pupa_rescue_cmd_set,
|
||||
"set an environment variable");
|
||||
pupa_rescue_register_command ("unset", pupa_rescue_cmd_unset,
|
||||
"remove an environment variable");
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -653,36 +667,42 @@ pupa_enter_rescue_mode (void)
|
|||
char *name;
|
||||
int n;
|
||||
pupa_rescue_command_t cmd;
|
||||
char *args[PUPA_RESCUE_MAX_ARGS + 1];
|
||||
char **args;
|
||||
|
||||
/* Print an error, if any. */
|
||||
pupa_print_error ();
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
|
||||
/* Get a command line. */
|
||||
pupa_rescue_get_command_line ("pupa rescue> ");
|
||||
|
||||
if (pupa_split_cmdline (line, getline, &n, &args))
|
||||
continue;
|
||||
|
||||
/* In case of an assignment set the environment accordingly
|
||||
instead of calling a function. */
|
||||
if (n == 0 && pupa_strchr (line, '='))
|
||||
{
|
||||
char *val = pupa_strchr (args[0], '=');
|
||||
val[0] = 0;
|
||||
pupa_env_set (args[0], val + 1);
|
||||
val[0] = '=';
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Get the command name. */
|
||||
name = next_word (&line);
|
||||
name = args[0];
|
||||
|
||||
/* If nothing is specified, restart. */
|
||||
if (*name == '\0')
|
||||
continue;
|
||||
|
||||
/* Get arguments. */
|
||||
for (n = 0; n <= PUPA_RESCUE_MAX_ARGS; n++)
|
||||
{
|
||||
char *arg = next_word (&line);
|
||||
|
||||
if (*arg)
|
||||
args[n] = arg;
|
||||
else
|
||||
break;
|
||||
}
|
||||
args[n] = 0;
|
||||
|
||||
/* Find the command and execute it. */
|
||||
for (cmd = pupa_rescue_command_list; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (pupa_strcmp (name, cmd->name) == 0)
|
||||
{
|
||||
(cmd->func) (n, args);
|
||||
(cmd->func) (n, &args[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -693,9 +713,5 @@ pupa_enter_rescue_mode (void)
|
|||
pupa_printf ("Unknown command `%s'\n", name);
|
||||
pupa_printf ("Try `help' for usage\n");
|
||||
}
|
||||
|
||||
/* Print an error, if any. */
|
||||
pupa_print_error ();
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue