Skip to contentSkip to conversation

New commands (reboot, halt, help)

PATCH Marco Gerards 4 participants 15 messages Jan 28, 2005 – Jan 30, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

Here is a patch to add the commands reboot, halt (i386/pc) and reboot (i386/pc). The halt and reboot commands for the PPC will follow later.

I will commit this patch on Monday, if there are no problems with it.

Thanks,
Marco

2005-01-28 Marco Gerards <[email protected]>

* commands/help.c: New file.
* commands/i386/pc/halt.c: New file.
* commands/i386/pc/reboot.c: New file.
* 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_iterate_commands): Export function. (grub_help_init): New prototype.
(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.

commands/help.c +74 -0
diff -upNr grub2/commands/help.c grub2.cmds/commands/help.c
@@ -0,0 +1,74 @@
+/* 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 <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/misc.h>
+
+static int
+print_command_info (grub_command_t cmd)
+{
+  if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE
+      || cmd->flags & GRUB_COMMAND_FLAG_BOTH)
+    grub_printf ("%s\t\t%s\n", cmd->name, cmd->description);
+  return 0;
+}
+
+static grub_err_t
+grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+
+{
+  grub_printf ("All GRUB commands accept `--help'.\n\n");
+  
+  grub_iterate_commands (print_command_info);
+  return 0;
+}
+
+
+
+#ifdef GRUB_UTIL
+void
+grub_help_init (void)
+{
+  grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_BOTH,
+			 "help", "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_BOTH,
+			 "help", "Shows a help message", 0);
+}
+
+GRUB_MOD_FINI
+{
+  grub_unregister_command ("help");
+}
+#endif /* ! GRUB_UTIL */
commands/i386/pc/halt.c +74 -0

74 lines not on this page · raw message

commands/i386/pc/reboot.c +63 -0

63 lines not on this page · raw message

conf/i386-pc.rmk +15 -2
diff -upNr grub2/conf/i386-pc.rmk grub2.cmds/conf/i386-pc.rmk
@@ -73,7 +73,8 @@ grub_emu_SOURCES = kern/main.c kern/devi
 	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)
conf/powerpc-ieee1275.rmk +6 -2
diff -upNr grub2/conf/powerpc-ieee1275.rmk grub2.cmds/conf/powerpc-ieee1275.rmk
@@ -41,7 +41,7 @@ grub_emu_SOURCES = kern/main.c kern/devi
 	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
+	pc.mod suspend.mod loopback.mod help.mod
 
 # For fshelp.mod.
 fshelp_mod_SOURCES = fs/fshelp.c
@@ -160,3 +160,7 @@ loopback_mod_CFLAGS = $(COMMON_CFLAGS)
 # For suspend.mod
 suspend_mod_SOURCES = commands/ieee1275/suspend.c
 suspend_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For help.mod.
+help_mod_SOURCES = commands/help.c
+help_mod_CFLAGS = $(COMMON_CFLAGS)
include/grub/i386/pc/init.h +9 -1
diff -upNr grub2/include/grub/i386/pc/init.h grub2.cmds/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 (struc
 /* 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 */
include/grub/normal.h +4 -2
diff -upNr grub2/include/grub/normal.h grub2.cmds/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
@@ -135,7 +135,7 @@ void EXPORT_FUNC(grub_register_command) 
 void EXPORT_FUNC(grub_unregister_command) (const char *name);
 grub_command_t grub_command_find (char *cmdline);
 grub_err_t grub_set_history (int newsize);
-int grub_iterate_commands (int (*iterate) (grub_command_t));
+int EXPORT_FUNC(grub_iterate_commands) (int (*iterate) (grub_command_t));
 int grub_command_execute (char *cmdline);
 void grub_command_init (void);
 void grub_normal_init_page (void);
@@ -160,6 +160,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 */
normal/cmdline.c +2 -2
diff -upNr grub2/normal/cmdline.c grub2.cmds/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,
normal/command.c +3 -3
diff -upNr grub2/normal/command.c grub2.cmds/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);
util/grub-emu.c +2 -0
diff -upNr grub2/util/grub-emu.c grub2.cmds/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 ();
#1 lore raw
Quoted 7 lines · Marco Gerards

Hi,

Here is a patch to add the commands reboot, halt (i386/pc) and reboot (i386/pc). The halt and reboot commands for the PPC will follow later.

I will commit this patch on Monday, if there are no problems with it.

Just a suggestion, halt is quite unixish way for saying shutdown. So would shutdown command be more intuitive to non unix users?

Thanks,
Vesa Jääskeläinen

#2 lore raw
Quoted 9 lines · chaac
Quoted 5 lines · Marco Gerards

Hi,
Here is a patch to add the commands reboot, halt (i386/pc) and reboot (i386/pc). The halt and reboot commands for the PPC will follow later.
I will commit this patch on Monday, if there are no problems with it.

Just a suggestion, halt is quite unixish way for saying shutdown. So would shutdown command be more intuitive to non unix users?

Perhaps. On GRUB Legacy the command was halt so I just used that. It doesn't really matter to me what will be used. Shutdown sounds to me like a lot needs to be done before the system will stop. And halt is what people are used to.

--
Marco

#4 lore raw
In reply to Marco Gerards

commands/help.c line 33

Quoted 8 lines · Marco Gerards
commands/help.c +8 -0
+static int
+print_command_info (grub_command_t cmd)
+{
+  if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE
+      || cmd->flags & GRUB_COMMAND_FLAG_BOTH)
+    grub_printf ("%s\t\t%s\n", cmd->name, cmd->description);
+  return 0;
+}

Why do you test the flags with GRUB_COMMAND_FLAG_BOTH?

BTW, I prefer a two-column format like GRUB Legacy and BASH. Otherwise, it can emit too many lines.

commands/help.c line 45

Quoted 11 lines
commands/help.c +11 -0
+static grub_err_t
+grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+
+{
+  grub_printf ("All GRUB commands accept `--help'.\n\n");
+
+  grub_iterate_commands (print_command_info);
+  return 0;
+}

Please make it possible to specify arguments (e.g help ls).

Quoted 3 lines

+ grub_register_command ("help", grub_cmd_help,
GRUB_COMMAND_FLAG_BOTH, + "help", "Shows a help message", 0);
+}

I think GRUB_COMMAND_FLAG_CMDLINE should be used for this command. I cannot think of any case where help is useful in the menu interface.

Quoted 9 lines

EXPORT_FUNC(grub_register_command)
void EXPORT_FUNC(grub_unregister_command) (const char *name); grub_command_t grub_command_find (char *cmdline); grub_err_t grub_set_history (int newsize);

(quoted diff) +1 -1
-int grub_iterate_commands (int (*iterate) (grub_command_t));
+int EXPORT_FUNC(grub_iterate_commands) (int (*iterate)

(grub_command_t)); int grub_command_execute (char *cmdline);
void grub_command_init (void);
void grub_normal_init_page (void);

This is strange. You don't have to specify EXPORT_FUNC in normal.h, because the function is defined in a module but not in a kernel. EXPORT_* are required only by the kernel (because the kernel may not be an ELF object).

Okuji

#5 lore raw
Quoted 11 lines · Yoshinori K. Okuji

commands/help.c line 33

Quoted 8 lines · Marco Gerards
commands/help.c +8 -0
+static int
+print_command_info (grub_command_t cmd)
+{
+  if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE
+      || cmd->flags & GRUB_COMMAND_FLAG_BOTH)
+    grub_printf ("%s\t\t%s\n", cmd->name, cmd->description);
+  return 0;
+}

Why do you test the flags with GRUB_COMMAND_FLAG_BOTH?

Not all commands, for example `title', should be printed.

Quoted 2 lines

BTW, I prefer a two-column format like GRUB Legacy and BASH. Otherwise, it can emit too many lines.

This is a two column format. The output is, for example:

boot            Boot an operating system
cat             Show the contents of a file
cmp             Compare two files
help            Shows a help message
insmod          Insert a module.
loopback        Makes a device of a file
ls              List devices and files
lsmod           Show loaded modules.
rescue          Enter into the rescue mode.
rmmod           Remove a module.
set             Set an environment variable.
terminal        Select a terminal.
unset           Remove an environment variable.
Quoted 5 lines
Quoted 5 lines
commands/help.c +5 -0
+static grub_err_t
+grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)),
+	       int argc __attribute__ ((unused)),
+	       char **args __attribute__ ((unused)))
+
Quoted 8 lines

commands/help.c line 45

Quoted 6 lines
commands/help.c +6 -0
+{
+  grub_printf ("All GRUB commands accept `--help'.\n\n");
+
+  grub_iterate_commands (print_command_info);
+  return 0;
+}

Please make it possible to specify arguments (e.g help ls).

Ok.

Quoted 6 lines
Quoted 3 lines

+ grub_register_command ("help", grub_cmd_help,
GRUB_COMMAND_FLAG_BOTH, + "help", "Shows a help message", 0);
+}

I think GRUB_COMMAND_FLAG_CMDLINE should be used for this command. I cannot think of any case where help is useful in the menu interface.

Ok.

Quoted 6 lines
Quoted 6 lines

EXPORT_FUNC(grub_register_command)
void EXPORT_FUNC(grub_unregister_command) (const char *name); grub_command_t grub_command_find (char *cmdline); grub_err_t grub_set_history (int newsize);

(quoted diff) +1 -1
-int grub_iterate_commands (int (*iterate) (grub_command_t));
+int EXPORT_FUNC(grub_iterate_commands) (int (*iterate)
Quoted 8 lines
Quoted 3 lines

(grub_command_t)); int grub_command_execute (char *cmdline);
void grub_command_init (void);
void grub_normal_init_page (void);

This is strange. You don't have to specify EXPORT_FUNC in normal.h, because the function is defined in a module but not in a kernel. EXPORT_* are required only by the kernel (because the kernel may not be an ELF object).

Ok. Perhaps I was confused because the other functions were exported.

Thanks,
Marco

#6 lore raw
Quoted 3 lines · Marco Gerards
Quoted 1 line

Why do you test the flags with GRUB_COMMAND_FLAG_BOTH?

Not all commands, for example `title', should be printed.

Why?

And, do you know that GRUB_COMMAND_FLAG_BOTH is a sum of GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU? The conditional is at least redundant.

Quoted 1 line

This is a two column format. The output is, for example:

[snip]

It's not a two-column format. Try help on bash. You will see what I mean.

Okuji

#7 lore raw
Quoted 6 lines · Yoshinori K. Okuji
Quoted 3 lines · Marco Gerards
Quoted 1 line

Why do you test the flags with GRUB_COMMAND_FLAG_BOTH?

Not all commands, for example `title', should be printed.

Why?

I was under the impression title was a special case. It does not even have a description.

Quoted 3 lines

And, do you know that GRUB_COMMAND_FLAG_BOTH is a sum of GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU? The conditional is at least redundant.

Right. What the code does is making sure GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU commands and commands with both set are shown. I fail to see the redundancy.

What do you propose?

Quoted 5 lines
Quoted 1 line

This is a two column format. The output is, for example:

[snip]

It's not a two-column format. Try help on bash. You will see what I mean.

Right, I see. I can make this change so it works more like GRUB Legacy.

Is it ok if I add a --description so it works like the patch as it is now? It's how I like it, that's why I added it this way, but if you don't like it I just remove it.

Thanks,
Marco

#8 lore raw
Quoted 7 lines

Right. What the code does is making sure GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU commands and commands with both set are shown. I fail to see the redundancy.

In normal.h:
/* Can be run in the command-line. */
#define GRUB_COMMAND_FLAG_CMDLINE 0x1
/* Can be run in the menu. */
#define GRUB_COMMAND_FLAG_MENU 0x2
/* Can be run in both interfaces. */
#define GRUB_COMMAND_FLAG_BOTH 0x3
so GRUB_COMMAND_FLAG_BOTH is 11 in binary, so x&GRUB_COMMAND_FLAG_BOTH will not be zero if and only if bit 0 *or* bit 1 is set Example
GRUB_COMMAND_FLAG_CMDLINE &GRUB_COMMAND_FLAG_BOTH=1
GRUB_COMMAND_FLAG_MENU&GRUB_COMMAND_FLAG_BOTH=2
GRUB_COMMAND_FLAG_BOTH&GRUB_COMMAND_FLAG_BOTH=3
*GRUB_COMMAND_FLAG_BOTH&GRUB_COMMAND_FLAG_CMDLINE=1*
The last example shows that for command with attribute GRUB_COMMAND_FLAG_BOTH already

cmd->flags & GRUB_COMMAND_FLAG_CMDLINE will be true

#9 lore raw
Quoted 23 lines · Serbinenko Vladimir
Quoted 6 lines

Right. What the code does is making sure GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU commands and commands with both set are shown. I fail to see the redundancy.

In normal.h:
/* Can be run in the command-line. */
#define GRUB_COMMAND_FLAG_CMDLINE 0x1
/* Can be run in the menu. */
#define GRUB_COMMAND_FLAG_MENU 0x2
/* Can be run in both interfaces. */
#define GRUB_COMMAND_FLAG_BOTH 0x3
so GRUB_COMMAND_FLAG_BOTH is 11 in binary, so x&GRUB_COMMAND_FLAG_BOTH will not be zero if and only if bit 0 *or* bit 1 is set Example
GRUB_COMMAND_FLAG_CMDLINE &GRUB_COMMAND_FLAG_BOTH=1 GRUB_COMMAND_FLAG_MENU&GRUB_COMMAND_FLAG_BOTH=2 GRUB_COMMAND_FLAG_BOTH&GRUB_COMMAND_FLAG_BOTH=3 *GRUB_COMMAND_FLAG_BOTH&GRUB_COMMAND_FLAG_CMDLINE=1*
The last example shows that for command with attribute GRUB_COMMAND_FLAG_BOTH already

Quoted 1 line

cmd->flags & GRUB_COMMAND_FLAG_CMDLINE will be true

Right I know that and what you described was exactly my intention. I wanted it to be true for all these 3 cases. As you can see GRUB_COMMAND_FLAG_TITLE is set to 4. And these commands will not be shown and that was also my intention.

So I am under the impression that my code is right. However, perhaps you don't think it is clean, in that case you could say what would be better.

Or if you don't agree with how it works, only showing the commands used in the menu and the command line while not showing title, we can talk about that.

I hope I was clearer now. Sometimes English makes the communication about such things a bit difficult for me.

Thanks,
Marco

#10 lore raw
In reply to Marco Gerards
Quoted 8 lines · Marco Gerards

What do you propose?

Quoted 5 lines
Quoted 1 line

This is a two column format. The output is, for example:

[snip]

It's not a two-column format. Try help on bash. You will see what I mean.

Quoted 6 lines

Right, I see. I can make this change so it works more like GRUB Legacy.

Is it ok if I add a --description so it works like the patch as it is now? It's how I like it, that's why I added it this way, but if you don't like it I just remove it.

BTW. That is how it works in rescue mode. So if help only has the behavior you described both will be completely different.

Thanks,
Marco

#11 lore raw
Quoted 2 lines · Marco Gerards

BTW. That is how it works in rescue mode. So if help only has the behavior you described both will be completely different.

I don't care. Rescue mode has different requirements. I want to make rescue mode resemble normal mode as much as possible, but the code size is the most important in rescue mode.

Okuji

#12 lore raw
In reply to Marco Gerards
Quoted 5 lines · Marco Gerards

Right. What the code does is making sure GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU commands and commands with both set are shown. I fail to see the redundancy.

What do you propose?

Help should show only commands available on the command-line interface.

Quoted 3 lines

Is it ok if I add a --description so it works like the patch as it is now? It's how I like it, that's why I added it this way, but if you don't like it I just remove it.

I have no strong objection, but how useful? You could get all information by "help COMMAND".

Okuji

#13 lore raw
Quoted 8 lines · Yoshinori K. Okuji
Quoted 5 lines · Marco Gerards

Right. What the code does is making sure GRUB_COMMAND_FLAG_CMDLINE and GRUB_COMMAND_FLAG_MENU commands and commands with both set are shown. I fail to see the redundancy.

What do you propose?

Help should show only commands available on the command-line interface.

Ok, fine for me. :)

I will update the patch and send in a new one tomorrow. I still hope I can apply that one on Monday because after Monday I won't be hacking for a while. I will still be on the list but I just won't hack that much anymore for some weeks, I think. :-/

Quoted 6 lines
Quoted 3 lines

Is it ok if I add a --description so it works like the patch as it is now? It's how I like it, that's why I added it this way, but if you don't like it I just remove it.

I have no strong objection, but how useful? You could get all information by "help COMMAND".

I will think more about this when working on it.

Thanks,
Marco

#14 lore raw
In reply to Marco Gerards
Quoted 7 lines · Marco Gerards

Hi,

Here is a patch to add the commands reboot, halt (i386/pc) and reboot (i386/pc). The halt and reboot commands for the PPC will follow later.

I will commit this patch on Monday, if there are no problems with it.

Here is an updated patch. The only changes are to hello.mod. It now prints the help output in two columns.

It can also print help output for the patterns passed as arguments. So:

help l t

Will show help output (the same as --help) for all arguments starting with l' and t', just like with GRUB Legacy.

I will commit this patch tomorrow evening if I don't hear complaints. :)

Thanks,
Marco

2005-01-30 Marco Gerards <[email protected]>

* 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: New file.
* 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.

commands/help.c +115 -0
diff -upNr --exclude=CVS grub2/commands/help.c grub2.cmds/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 <grub/normal.h>
+#include <grub/dl.h>
+#include <grub/arg.h>
+#include <grub/misc.h>
+
+/* 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 */
commands/i386/pc/halt.c +74 -0

74 lines not on this page · raw message

commands/i386/pc/reboot.c +63 -0

63 lines not on this page · raw message

conf/i386-pc.rmk +15 -2
diff -upNr --exclude=CVS grub2/conf/i386-pc.rmk grub2.cmds/conf/i386-pc.rmk
@@ -73,7 +73,8 @@ grub_emu_SOURCES = kern/main.c kern/devi
 	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)
conf/powerpc-ieee1275.rmk +6 -2
diff -upNr --exclude=CVS grub2/conf/powerpc-ieee1275.rmk grub2.cmds/conf/powerpc-ieee1275.rmk
@@ -41,7 +41,7 @@ grub_emu_SOURCES = kern/main.c kern/devi
 	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
+	pc.mod suspend.mod loopback.mod help.mod
 
 # For fshelp.mod.
 fshelp_mod_SOURCES = fs/fshelp.c
@@ -160,3 +160,7 @@ loopback_mod_CFLAGS = $(COMMON_CFLAGS)
 # For suspend.mod
 suspend_mod_SOURCES = commands/ieee1275/suspend.c
 suspend_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For help.mod.
+help_mod_SOURCES = commands/help.c
+help_mod_CFLAGS = $(COMMON_CFLAGS)

Binary files grub2/core.img and grub2.cmds/core.img differ

include/grub/i386/pc/init.h +9 -1
diff -upNr --exclude=CVS grub2/include/grub/i386/pc/init.h grub2.cmds/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 (struc
 /* 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 */
include/grub/normal.h +4 -1
diff -upNr --exclude=CVS grub2/include/grub/normal.h grub2.cmds/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 */
normal/arg.c +3 -3
diff -upNr --exclude=CVS grub2/normal/arg.c grub2.cmds/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 ke
   switch (key)
     {
     case 'h':
-      show_help (cmd);
+      grub_arg_show_help (cmd);
       return -1;
       
     case 'u':
normal/cmdline.c +2 -2
diff -upNr --exclude=CVS grub2/normal/cmdline.c grub2.cmds/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,
normal/command.c +3 -3
diff -upNr --exclude=CVS grub2/normal/command.c grub2.cmds/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);
util/grub-emu.c +2 -0
diff -upNr --exclude=CVS grub2/util/grub-emu.c grub2.cmds/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 ();