From 990cf3aa8acf16f95434555f815df3391ffa0822 Mon Sep 17 00:00:00 2001 From: marco_g Date: Mon, 31 Jan 2005 21:40:25 +0000 Subject: [PATCH] 2005-01-31 Marco Gerards * commands/help.c: New file. * normal/arg.c (show_help): Renamed to... (grub_arg_show_help): ... this. * commands/i386/pc/halt.c: New file. * commands/i386/pc/reboot.c: Likewise. * conf/i386-pc.rmk (grub_emu_SOURCES): Add `commands/help.c'. (pkgdata_MODULES): Add `reboot.mod', `halt.mod' and `help.mod'. (help_mod_SOURCES, help_mod_CFLAGS, reboot_mod_SOURCES) (reboot_mod_CFLAGS, halt_mod_SOURCES, halt_mod_CFLAGS): New variables. * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Add `commands/help.c'. (pkgdata_MODULES): Add `help.mod'. (help_mod_SOURCES, help_mod_CFLAGS): New variables. * grub/i386/pc/init.h (grub_reboot): New prototype. (grub_halt): Likewise. * include/grub/normal.h (grub_arg_show_help): New prototype. (grub_help_init): Likewise. (grub_help_fini): Likewise. * util/grub-emu.c (main): Initialize and deinitialize the help command. * normal/cmdline.c (grub_cmdline_get): Doc fix. * normal/command.c (grub_command_init): Fixed the description of the `set' and `unset' commands. --- ChangeLog | 31 +++++++++- commands/help.c | 115 ++++++++++++++++++++++++++++++++++++ commands/i386/pc/halt.c | 74 +++++++++++++++++++++++ commands/i386/pc/reboot.c | 63 ++++++++++++++++++++ conf/i386-pc.rmk | 17 +++++- conf/powerpc-ieee1275.rmk | 8 ++- include/grub/i386/pc/init.h | 10 +++- include/grub/normal.h | 5 +- normal/arg.c | 6 +- normal/cmdline.c | 4 +- normal/command.c | 6 +- util/grub-emu.c | 2 + 12 files changed, 326 insertions(+), 15 deletions(-) create mode 100644 commands/help.c create mode 100644 commands/i386/pc/halt.c create mode 100644 commands/i386/pc/reboot.c diff --git a/ChangeLog b/ChangeLog index 48769265b..5ef2c0182 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,33 @@ -2005-01-30 Marco Gerards +2005-01-31 Marco Gerards + + * commands/help.c: New file. + * normal/arg.c (show_help): Renamed to... + (grub_arg_show_help): ... this. + * commands/i386/pc/halt.c: New file. + * commands/i386/pc/reboot.c: Likewise. + * conf/i386-pc.rmk (grub_emu_SOURCES): Add `commands/help.c'. + (pkgdata_MODULES): Add `reboot.mod', `halt.mod' and `help.mod'. + (help_mod_SOURCES, help_mod_CFLAGS, reboot_mod_SOURCES) + (reboot_mod_CFLAGS, halt_mod_SOURCES, halt_mod_CFLAGS): New + variables. + * conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Add + `commands/help.c'. + (pkgdata_MODULES): Add `help.mod'. + (help_mod_SOURCES, help_mod_CFLAGS): New variables. + * grub/i386/pc/init.h (grub_reboot): New prototype. + (grub_halt): Likewise. + * include/grub/normal.h (grub_arg_show_help): New prototype. + (grub_help_init): Likewise. + (grub_help_fini): Likewise. + * util/grub-emu.c (main): Initialize and deinitialize the help + command. + + * normal/cmdline.c (grub_cmdline_get): Doc fix. + + * normal/command.c (grub_command_init): Fixed the description of + the `set' and `unset' commands. + +2005-01-31 Marco Gerards * boot/powerpc/ieee1275/ieee1275.c (grub_ieee1275_interpret): New function. diff --git a/commands/help.c b/commands/help.c new file mode 100644 index 000000000..5f36e279e --- /dev/null +++ b/commands/help.c @@ -0,0 +1,115 @@ +/* help.c - command to show a help text. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +/* XXX: This has to be changed into a function so the screen can be + optimally used. */ +#define TERM_WIDTH 80 + +static grub_err_t +grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)), int argc, + char **args) + +{ + int cnt = 0; + char *currarg; + + auto int print_command_info (grub_command_t cmd); + auto int print_command_help (grub_command_t cmd); + + int print_command_info (grub_command_t cmd) + { + if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE) + { + char description[TERM_WIDTH / 2]; + int desclen = grub_strlen (cmd->summary); + + /* Make a string with a length of TERM_WIDTH / 2 - 1 filled + with the description followed by spaces. */ + grub_memset (description, ' ', TERM_WIDTH / 2 - 1); + description[TERM_WIDTH / 2 - 1] = '\0'; + grub_memcpy (description, cmd->summary, + (desclen < TERM_WIDTH / 2 - 1 + ? desclen : TERM_WIDTH / 2 - 1)); + + grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " "); + } + + return 0; + } + + int print_command_help (grub_command_t cmd) + { + if (!grub_strncmp (cmd->name, currarg, grub_strlen (currarg))) + { + grub_arg_show_help (cmd); + grub_printf ("\n\n"); + } + return 0; + } + + if (argc == 0) + grub_iterate_commands (print_command_info); + else + { + int i; + + for (i = 0; i < argc; i++) + { + currarg = args[i]; + grub_iterate_commands (print_command_help); + } + } + + return 0; +} + + + +#ifdef GRUB_UTIL +void +grub_help_init (void) +{ + grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE, + "help [PATTERN ...]", "Shows a help message", 0); +} + +void +grub_help_fini (void) +{ + grub_unregister_command ("help"); +} +#else /* ! GRUB_UTIL */ +GRUB_MOD_INIT +{ + (void)mod; /* To stop warning. */ + grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE, + "help [PATTERN ...]", "Shows a help message", 0); +} + +GRUB_MOD_FINI +{ + grub_unregister_command ("help"); +} +#endif /* ! GRUB_UTIL */ diff --git a/commands/i386/pc/halt.c b/commands/i386/pc/halt.c new file mode 100644 index 000000000..4923676f7 --- /dev/null +++ b/commands/i386/pc/halt.c @@ -0,0 +1,74 @@ +/* halt.c - command to halt the computer. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +static const struct grub_arg_option options[] = + { + {"no-apm", 'n', 0, "Don't use APM to halt the computer", 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + +static grub_err_t +grub_cmd_halt (struct grub_arg_list *state, + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) + +{ + int no_apm = 0; + if (state[0].set) + no_apm = 1; + grub_halt (no_apm); + return 0; +} + + + +#ifdef GRUB_UTIL +void +grub_halt_init (void) +{ + grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH, + "halt [OPTIONS...]", + "Halt the system, if possible using APM", options); +} + +void +grub_halt_fini (void) +{ + grub_unregister_command ("halt"); +} +#else /* ! GRUB_UTIL */ +GRUB_MOD_INIT +{ + (void)mod; /* To stop warning. */ + grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH, + "halt [OPTIONS...]", + "Halt the system, if possible using APM", options); +} + +GRUB_MOD_FINI +{ + grub_unregister_command ("halt"); +} +#endif /* ! GRUB_UTIL */ diff --git a/commands/i386/pc/reboot.c b/commands/i386/pc/reboot.c new file mode 100644 index 000000000..d9d68f386 --- /dev/null +++ b/commands/i386/pc/reboot.c @@ -0,0 +1,63 @@ +/* reboot.c - command to reboot the computer. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +static grub_err_t +grub_cmd_reboot (struct grub_arg_list *state __attribute__ ((unused)), + int argc __attribute__ ((unused)), + char **args __attribute__ ((unused))) + +{ + grub_reboot (); + return 0; +} + + + +#ifdef GRUB_UTIL +void +grub_reboot_init (void) +{ + grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH, + "reboot", "Reboot the computer", 0); +} + +void +grub_reboot_fini (void) +{ + grub_unregister_command ("reboot"); +} +#else /* ! GRUB_UTIL */ +GRUB_MOD_INIT +{ + (void)mod; /* To stop warning. */ + grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH, + "reboot", "Reboot the computer", 0); +} + +GRUB_MOD_FINI +{ + grub_unregister_command ("reboot"); +} +#endif /* ! GRUB_UTIL */ diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk index 09cbd3291..018bcb3ea 100644 --- a/conf/i386-pc.rmk +++ b/conf/i386-pc.rmk @@ -73,7 +73,8 @@ grub_emu_SOURCES = kern/main.c kern/device.c fs/fshelp.c \ commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c \ util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/iso9660.c \ normal/cmdline.c normal/command.c normal/main.c normal/menu.c normal/arg.c \ - util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c disk/loopback.c + util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c commands/help.c \ + disk/loopback.c grub_emu_LDFLAGS = -lncurses # For genmoddep. @@ -83,7 +84,7 @@ genmoddep_SOURCES = util/genmoddep.c pkgdata_MODULES = _chain.mod _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \ hfs.mod jfs.mod normal.mod hello.mod vga.mod font.mod _multiboot.mod ls.mod \ boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod multiboot.mod \ - amiga.mod apple.mod pc.mod loopback.mod + amiga.mod apple.mod pc.mod loopback.mod reboot.mod halt.mod help.mod # For _chain.mod. _chain_mod_SOURCES = loader/i386/pc/chainloader.c @@ -163,6 +164,18 @@ cmp_mod_CFLAGS = $(COMMON_CFLAGS) cat_mod_SOURCES = commands/cat.c cat_mod_CFLAGS = $(COMMON_CFLAGS) +# For help.mod. +help_mod_SOURCES = commands/help.c +help_mod_CFLAGS = $(COMMON_CFLAGS) + +# For reboot.mod. +reboot_mod_SOURCES = commands/i386/pc/reboot.c +reboot_mod_CFLAGS = $(COMMON_CFLAGS) + +# For halt.mod. +halt_mod_SOURCES = commands/i386/pc/halt.c +halt_mod_CFLAGS = $(COMMON_CFLAGS) + # For vga.mod. vga_mod_SOURCES = term/i386/pc/vga.c vga_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/conf/powerpc-ieee1275.rmk b/conf/powerpc-ieee1275.rmk index 9103e8d76..b29d88cff 100644 --- a/conf/powerpc-ieee1275.rmk +++ b/conf/powerpc-ieee1275.rmk @@ -41,7 +41,7 @@ grub_emu_SOURCES = kern/main.c kern/device.c \ normal/cmdline.c normal/command.c normal/main.c normal/menu.c \ normal/arg.c kern/partition.c \ util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c \ - kern/env.c disk/loopback.c commands/ls.c \ + kern/env.c disk/loopback.c commands/ls.c commands/help.c \ commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c grub_emu_LDFLAGS = -lncurses @@ -65,7 +65,7 @@ genmoddep_SOURCES = util/genmoddep.c pkgdata_MODULES = _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \ hfs.mod jfs.mod normal.mod hello.mod font.mod \ boot.mod cmp.mod cat.mod terminal.mod fshelp.mod amiga.mod apple.mod \ - pc.mod suspend.mod loopback.mod reboot.mod halt.mod + pc.mod suspend.mod loopback.mod help.mod reboot.mod halt.mod # For fshelp.mod. fshelp_mod_SOURCES = fs/fshelp.c @@ -168,3 +168,7 @@ reboot_mod_CFLAGS = $(COMMON_CFLAGS) # For halt.mod halt_mod_SOURCES = commands/ieee1275/halt.c halt_mod_CFLAGS = $(COMMON_CFLAGS) + +# For help.mod. +help_mod_SOURCES = commands/help.c +help_mod_CFLAGS = $(COMMON_CFLAGS) diff --git a/include/grub/i386/pc/init.h b/include/grub/i386/pc/init.h index a130bd9ad..328391f58 100644 --- a/include/grub/i386/pc/init.h +++ b/include/grub/i386/pc/init.h @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002, 2004 Free Software Foundation, Inc. + * Copyright (C) 2002, 2004, 2005 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 @@ -54,4 +54,12 @@ grub_uint32_t grub_get_mmap_entry (struct grub_machine_mmap_entry *entry, /* Turn on/off Gate A20. */ void grub_gate_a20 (int on); +/* Reboot the machine. */ +void EXPORT_FUNC (grub_reboot) (void); + +/* Halt the system, using APM if possible. If NO_APM is true, don't + * use APM even if it is available. */ +void EXPORT_FUNC (grub_halt) (int no_apm); + + #endif /* ! GRUB_INIT_MACHINE_HEADER */ diff --git a/include/grub/normal.h b/include/grub/normal.h index 2976c8604..39a5b1b15 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -1,7 +1,7 @@ /* normal.h - prototypes for the normal mode */ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2002,2003,2005 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 @@ -141,6 +141,7 @@ void grub_command_init (void); void grub_normal_init_page (void); int grub_arg_parse (grub_command_t parser, int argc, char **argv, struct grub_arg_list *usr, char ***args, int *argnum); +void grub_arg_show_help (grub_command_t cmd); #ifdef GRUB_UTIL @@ -160,6 +161,8 @@ void grub_terminal_init (void); void grub_terminal_fini (void); void grub_loop_init (void); void grub_loop_fini (void); +void grub_help_init (void); +void grub_help_fini (void); #endif #endif /* ! GRUB_NORMAL_HEADER */ diff --git a/normal/arg.c b/normal/arg.c index e66045c91..60b25f27a 100644 --- a/normal/arg.c +++ b/normal/arg.c @@ -101,8 +101,8 @@ show_usage (grub_command_t cmd) grub_printf ("Usage: %s\n", cmd->summary); } -static void -show_help (grub_command_t cmd) +void +grub_arg_show_help (grub_command_t cmd) { static void showargs (const struct grub_arg_option *opt) { @@ -140,7 +140,7 @@ parse_option (grub_command_t cmd, int key, char *arg, struct grub_arg_list *usr) switch (key) { case 'h': - show_help (cmd); + grub_arg_show_help (cmd); return -1; case 'u': diff --git a/normal/cmdline.c b/normal/cmdline.c index 5088532ad..694d33133 100644 --- a/normal/cmdline.c +++ b/normal/cmdline.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. + * Copyright (C) 1999,2000,2001,2002,2003,2004,2005 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 @@ -459,7 +459,7 @@ grub_cmdline_run (int nested) /* Get a command-line. If ECHO_CHAR is not zero, echo it instead of input characters. If READLINE is non-zero, readline-like key bindings are - available. If ESC is pushed, return non-zero, otherwise return zero. */ + available. If ESC is pushed, return zero, otherwise return non-zero. */ /* FIXME: The dumb interface is not supported yet. */ int grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, diff --git a/normal/command.c b/normal/command.c index e6c397ce9..66630e658 100644 --- a/normal/command.c +++ b/normal/command.c @@ -1,6 +1,6 @@ /* * GRUB -- GRand Unified Bootloader - * Copyright (C) 2003 Free Software Foundation, Inc. + * Copyright (C) 2003, 2005 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 @@ -316,10 +316,10 @@ grub_command_init (void) "rescue", "Enter into the rescue mode.", 0); grub_register_command ("set", set_command, GRUB_COMMAND_FLAG_BOTH, - "unset ENVVAR", "Set an environment variable.", 0); + "set [ENVVAR=VALUE]", "Set an environment variable.", 0); grub_register_command ("unset", unset_command, GRUB_COMMAND_FLAG_BOTH, - "set [ENVVAR=VALUE]", "Remove an environment variable.", 0); + "unset ENVVAR", "Remove an environment variable.", 0); grub_register_command ("insmod", insmod_command, GRUB_COMMAND_FLAG_BOTH, "insmod MODULE|FILE", "Insert a module.", 0); diff --git a/util/grub-emu.c b/util/grub-emu.c index 8acff857d..b0a80e398 100644 --- a/util/grub-emu.c +++ b/util/grub-emu.c @@ -177,6 +177,7 @@ main (int argc, char *argv[]) grub_cat_init (); grub_terminal_init (); grub_loop_init (); + grub_help_init (); /* XXX: Should normal mode be started by default? */ grub_normal_init (); @@ -184,6 +185,7 @@ main (int argc, char *argv[]) /* Start GRUB! */ grub_main (); + grub_help_fini (); grub_loop_fini (); grub_util_biosdisk_fini (); grub_normal_fini ();