* commands/cat.c (GRUB_MOD_INIT): Use better documentation.
(grub_cat_init): Likewise.
* loader/i386/pc/chainloader_normal.c (GRUB_MOD_INIT): Likewise.
(options): Likewise.
* commands/configfile.c (GRUB_MOD_INIT): Likewise.
(grub_configfile_init): Likewise.
* font/manager.c (GRUB_MOD_INIT): Likewise.
* commands/help.c (GRUB_MOD_INIT): Likewise.
(grub_help_init): Likewise.
* normal/command.c (grub_command_init): Likewise.
* loader/i386/pc/linux_normal.c (GRUB_MOD_INIT): Likewise.
* disk/loopback.c (grub_loop_init): Likewise.
(GRUB_MOD_INIT): Likewise.
* commands/ls.c (grub_ls_init): Likewise.
(GRUB_MOD_INIT): Likewise.
(options): Likewise.
* commands/boot.c (grub_boot_init): Likewise.
(GRUB_MOD_INIT): Likewise.
* loader/i386/pc/multiboot_normal.c (GRUB_MOD_INIT): Likewise.
* commands/i386/pc/reboot.c (grub_reboot_init): Likewise.
(GRUB_MOD_INIT): Likewise.
* commands/cmp.c (grub_cmp_init): Likewise.
(GRUB_MOD_INIT): Likewise.
* normal/arg.c: Use <> instead of "" to include header files.
(SHORT_ARG_HELP): New macro.
(SHORT_ARG_USAGE): Likewise.
(help_options): Specify SHORT_ARG_HELP and SHORT_ARG_USAGE instead
of 'h' and 'u' for help and usage, respectively. Use more GNU-like
descriptions.
(find_short): Check if C is 'h' or 'u' explicitly.
(grub_arg_show_help): Use space characters instead of tabs. Treat
SHORT_ARG_HELP and SHORT_ARG_USAGE exceptionally so that -h and -u
are shown with --help and --usage only if they are not used for
the command itself.
(parse_option): Use SHORT_ARG_HELP and SHORT_ARG_USAGE instead of
'h' and 'u'.
* include/grub/arg.h (struct grub_arg_option): Add the qualifier
const into "longarg". Change the type of "shortarg" to int.
+2005-07-17 Yoshinori Okuji <okuji@enbug.org>
+
+ * commands/cat.c (GRUB_MOD_INIT): Use better documentation.
+ (grub_cat_init): Likewise.
+ * loader/i386/pc/chainloader_normal.c (GRUB_MOD_INIT): Likewise.
+ (options): Likewise.
+ * commands/configfile.c (GRUB_MOD_INIT): Likewise.
+ (grub_configfile_init): Likewise.
+ * font/manager.c (GRUB_MOD_INIT): Likewise.
+ * commands/help.c (GRUB_MOD_INIT): Likewise.
+ (grub_help_init): Likewise.
+ * normal/command.c (grub_command_init): Likewise.
+ * loader/i386/pc/linux_normal.c (GRUB_MOD_INIT): Likewise.
+ * disk/loopback.c (grub_loop_init): Likewise.
+ (GRUB_MOD_INIT): Likewise.
+ * commands/ls.c (grub_ls_init): Likewise.
+ (GRUB_MOD_INIT): Likewise.
+ (options): Likewise.
+ * commands/boot.c (grub_boot_init): Likewise.
+ (GRUB_MOD_INIT): Likewise.
+ * loader/i386/pc/multiboot_normal.c (GRUB_MOD_INIT): Likewise.
+ * commands/i386/pc/reboot.c (grub_reboot_init): Likewise.
+ (GRUB_MOD_INIT): Likewise.
+ * commands/cmp.c (grub_cmp_init): Likewise.
+ (GRUB_MOD_INIT): Likewise.
+
+ * normal/arg.c: Use <> instead of "" to include header files.
+ (SHORT_ARG_HELP): New macro.
+ (SHORT_ARG_USAGE): Likewise.
+ (help_options): Specify SHORT_ARG_HELP and SHORT_ARG_USAGE instead
+ of 'h' and 'u' for help and usage, respectively. Use more GNU-like
+ descriptions.
+ (find_short): Check if C is 'h' or 'u' explicitly.
+ (grub_arg_show_help): Use space characters instead of tabs. Treat
+ SHORT_ARG_HELP and SHORT_ARG_USAGE exceptionally so that -h and -u
+ are shown with --help and --usage only if they are not used for
+ the command itself.
+ (parse_option): Use SHORT_ARG_HELP and SHORT_ARG_USAGE instead of
+ 'h' and 'u'.
+
+ * include/grub/arg.h (struct grub_arg_option): Add the qualifier
+ const into "longarg". Change the type of "shortarg" to int.
+
2005-07-17 Yoshinori Okuji <okuji@enbug.org>
* boot/i386/pc/boot.S (boot_drive_check): New label.
/* boot.c - command to boot an operating system */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003,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
grub_boot_init (void)
{
grub_register_command ("boot", grub_cmd_boot, GRUB_COMMAND_FLAG_BOTH,
- "boot", "Boot an operating system", 0);
+ "boot", "Boot an operating system.", 0);
}
void
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
- (void)mod; /* To stop warning. */
+ (void) mod; /* To stop warning. */
grub_register_command ("boot", grub_cmd_boot, GRUB_COMMAND_FLAG_BOTH,
- "boot", "Boot an operating system", 0);
+ "boot", "Boot an operating system.", 0);
}
GRUB_MOD_FINI
/* cat.c - command to show the contents of a file */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003,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
grub_cat_init (void)
{
grub_register_command ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH,
- "cat FILE", "Show the contents of a file", 0);
+ "cat FILE", "Show the contents of a file.", 0);
}
void
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
- (void)mod; /* To stop warning. */
+ (void) mod; /* To stop warning. */
grub_register_command ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH,
- "cat FILE", "Show the contents of a file", 0);
+ "cat FILE", "Show the contents of a file.", 0);
}
GRUB_MOD_FINI
/* cmd.c - command to cmp an operating system */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003,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
grub_cmp_init (void)
{
grub_register_command ("cmp", grub_cmd_cmp, GRUB_COMMAND_FLAG_BOTH,
- "cmp FILE1 FILE2", "Compare two files", 0);
+ "cmp FILE1 FILE2", "Compare two files.", 0);
}
void
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
- (void)mod; /* To stop warning. */
+ (void) mod; /* To stop warning. */
grub_register_command ("cmp", grub_cmd_cmp, GRUB_COMMAND_FLAG_BOTH,
- "cmp FILE1 FILE2", "Compare two files", 0);
+ "cmp FILE1 FILE2", "Compare two files.", 0);
}
GRUB_MOD_FINI
{
grub_register_command ("configfile", grub_cmd_configfile,
GRUB_COMMAND_FLAG_BOTH, "configfile FILE",
- "Load config file", 0);
+ "Load another config file.", 0);
}
void
#else /* ! GRUB_UTIL */
GRUB_MOD_INIT
{
- (void)mod; /* To stop warning. */
+ (void) mod; /* To stop warning. */
grub_register_command ("configfile", grub_cmd_configfile,
GRUB_COMMAND_FLAG_BOTH, "configfile FILE",
- "Load config file", 0);
+ "Load another config file.", 0);
}
GRUB_MOD_FINI
grub_help_init (void)
{
grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE,
- "help [PATTERN ...]", "Shows a help message", 0);
+ "help [PATTERN ...]", "Show a help message.", 0);
}
void
{
(void)mod; /* To stop warning. */
grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE,
- "help [PATTERN ...]", "Shows a help message", 0);
+ "help [PATTERN ...]", "Show a help message.", 0);
}
GRUB_MOD_FINI
static const struct grub_arg_option options[] =
{
- {"no-apm", 'n', 0, "Don't use APM to halt the computer", 0, 0},
+ {"no-apm", 'n', 0, "do not use APM to halt the computer", 0, 0},
{0, 0, 0, 0, 0, 0}
};
{
(void)mod; /* To stop warning. */
grub_register_command ("halt", grub_cmd_halt, GRUB_COMMAND_FLAG_BOTH,
- "halt [OPTIONS...]",
+ "halt [-n]",
"Halt the system, if possible using APM", options);
}
grub_reboot_init (void)
{
grub_register_command ("reboot", grub_cmd_reboot, GRUB_COMMAND_FLAG_BOTH,
- "reboot", "Reboot the computer", 0);
+ "reboot", "Reboot the computer.", 0);
}
void
static const struct grub_arg_option options[] =
{
- {"long", 'l', 0, "Show a long list with more detailed information", 0, 0},
- {"human-readable", 'h', 0, "Print sizes in a human readable format", 0, 0},
- {"all", 'a', 0, "List all files", 0, 0},
+ {"long", 'l', 0, "show a long list with more detailed information", 0, 0},
+ {"human-readable", 'h', 0, "print sizes in a human readable format", 0, 0},
+ {"all", 'a', 0, "list all files", 0, 0},
{0, 0, 0, 0, 0, 0}
};
grub_ls_init (void)
{
grub_register_command ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH,
- "ls [OPTIONS...] [DIR]",
- "List devices and files", options);
+ "ls [-l|-h|-a] [FILE]",
+ "List devices and files.", options);
}
void
{
(void)mod; /* To stop warning. */
grub_register_command ("ls", grub_cmd_ls, GRUB_COMMAND_FLAG_BOTH,
- "ls [OPTIONS...] [DIR]",
- "List devices and files", options);
+ "ls [-l|-h|-a] [FILE]",
+ "List devices and files.", options);
}
GRUB_MOD_FINI
static const struct grub_arg_option options[] =
{
- {"delete", 'd', 0, "Delete the loopback device entry", 0, 0},
- {"partitions", 'p', 0, "Set that the drive has partitions to"
+ {"delete", 'd', 0, "delete the loopback device entry", 0, 0},
+ {"partitions", 'p', 0, "set that the drive has partitions to"
" simulate a harddrive", 0, 0},
{0, 0, 0, 0, 0, 0}
};
grub_loop_init (void)
{
grub_register_command ("loopback", grub_cmd_loopback, GRUB_COMMAND_FLAG_BOTH,
- "loopback [OPTIONS] DEVICENAME FILE", "Makes a device of a file", options);
+ "loopback [-d|-p] DEVICENAME FILE",
+ "Make a device of a file.", options);
grub_disk_dev_register (&grub_loopback_dev);
}
{
(void)mod; /* To stop warning. */
grub_register_command ("loopback", grub_cmd_loopback, GRUB_COMMAND_FLAG_BOTH,
- "loopback [OPTIONS] DEVICENAME FILE", "Makes a device of a file", options);
+ "loopback [-d|-p] DEVICENAME FILE",
+ "Make a device of a file.", options);
grub_disk_dev_register (&grub_loopback_dev);
}
/*
* 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
{
(void) mod; /* Stop warning. */
grub_register_command ("font", font_command, GRUB_COMMAND_FLAG_BOTH,
- "font FILE...", "Specify a font file to display.", 0);
+ "font FILE...",
+ "Specify one or more font files to display.", 0);
}
GRUB_MOD_FINI
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003,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
struct grub_arg_option
{
- char *longarg;
- char shortarg;
+ const char *longarg;
+ int shortarg;
int flags;
char *doc;
char *arg;
static const struct grub_arg_option options[] =
{
- {"force", 'f', 0, "Skip bootsector magic number test.", 0, 0},
+ {"force", 'f', 0, "skip bootsector magic number test", 0, 0},
{0, 0, 0, 0, 0, 0}
};
(void) mod; /* To stop warning. */
grub_register_command ("chainloader", chainloader_command,
GRUB_COMMAND_FLAG_BOTH,
- "chainloader [options] FILE",
- "Prepare to boot another boot loader", options);
+ "chainloader [-f] FILE",
+ "Prepare to boot another boot loader.", options);
}
GRUB_MOD_FINI
/* linux_normal.c - boot another boot loader */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2004 Free Software Foundation, Inc.
+ * Copyright (C) 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
grub_register_command ("linux", grub_normal_linux_command,
GRUB_COMMAND_FLAG_BOTH,
"linux FILE [ARGS...]",
- "Load linux", 0);
+ "Load a linux kernel.", 0);
grub_register_command ("initrd", grub_normal_initrd_command,
GRUB_COMMAND_FLAG_BOTH,
"initrd FILE",
- "Load initrd", 0);
+ "Load an initrd.", 0);
}
GRUB_MOD_FINI
/* multiboot_normal.c - boot another boot loader */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2004 Free Software Foundation, Inc.
+ * Copyright (C) 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
grub_register_command ("multiboot", grub_normal_cmd_multiboot,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE,
"multiboot FILE [ARGS...]",
- "Load a multiboot kernel", 0);
+ "Load a Multiboot kernel.", 0);
grub_register_command ("module", grub_normal_cmd_module,
GRUB_COMMAND_FLAG_BOTH | GRUB_COMMAND_FLAG_NO_ARG_PARSE,
"module FILE [ARGS...]",
- "Load a multiboot module", 0);
+ "Load a Multiboot module.", 0);
}
GRUB_MOD_FINI
/* arg.c - argument parser */
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+ * Copyright (C) 2003,2004,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
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include "grub/arg.h"
-#include "grub/misc.h"
-#include "grub/mm.h"
-#include "grub/err.h"
-#include "grub/normal.h"
+#include <grub/arg.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/normal.h>
+#include <grub/term.h>
+
+/* Built-in parser for default options. */
+#define SHORT_ARG_HELP -100
+#define SHORT_ARG_USAGE -101
-/* Build in parser for default 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},
+ {"help", SHORT_ARG_HELP, 0,
+ "display this help and exit", 0, ARG_TYPE_NONE},
+ {"usage", SHORT_ARG_USAGE, 0,
+ "display the usage of this command and exit", 0, ARG_TYPE_NONE},
{0, 0, 0, 0, 0, 0}
};
if (options)
found = fnd_short (options);
+
if (! found)
- found = fnd_short (help_options);
+ {
+ switch (c)
+ {
+ case 'h':
+ found = (struct grub_arg_option *) help_options;
+ break;
+
+ case 'u':
+ found = (struct grub_arg_option *) (help_options + 1);
+ break;
+
+ default:
+ break;
+ }
+ }
return found;
}
{
while (opt->doc)
{
- if (opt->longarg && !grub_strcmp (opt->longarg, s))
+ if (opt->longarg && ! grub_strcmp (opt->longarg, s))
return (struct grub_arg_option *) opt;
opt++;
}
if (options)
found = fnd_long (options);
- if (!found)
+
+ if (! found)
found = fnd_long (help_options);
return found;
void
grub_arg_show_help (grub_command_t cmd)
{
- static void showargs (const struct grub_arg_option *opt)
+ auto void showargs (const struct grub_arg_option *opt);
+ int h_is_used = 0;
+ int u_is_used = 0;
+
+ auto void showargs (const struct grub_arg_option *opt)
{
for (; opt->doc; opt++)
{
+ int spacing = 20;
+
if (opt->shortarg && grub_isgraph (opt->shortarg))
grub_printf ("-%c%c ", opt->shortarg, opt->longarg ? ',':' ');
+ else if (opt->shortarg == SHORT_ARG_HELP && ! h_is_used)
+ grub_printf ("-h, ");
+ else if (opt->shortarg == SHORT_ARG_USAGE && ! u_is_used)
+ grub_printf ("-u, ");
else
grub_printf (" ");
+
if (opt->longarg)
{
grub_printf ("--%s", opt->longarg);
+ spacing -= grub_strlen (opt->longarg);
+
if (opt->arg)
- grub_printf ("=%s", opt->arg);
+ {
+ grub_printf ("=%s", opt->arg);
+ spacing -= grub_strlen (opt->arg) + 1;
+ }
}
- else
- grub_printf ("\t");
- grub_printf ("\t\t%s\n", opt->doc);
+ while (spacing-- > 0)
+ grub_putchar (' ');
+
+ grub_printf ("%s\n", opt->doc);
+
+ switch (opt->shortarg)
+ {
+ case 'h':
+ h_is_used = 1;
+ break;
+
+ case 'u':
+ u_is_used = 1;
+ break;
+
+ default:
+ break;
+ }
}
}
{
switch (key)
{
- case 'h':
+ case SHORT_ARG_HELP:
grub_arg_show_help (cmd);
return -1;
- case 'u':
+ case SHORT_ARG_USAGE:
show_usage (cmd);
return -1;
while (1)
{
opt = find_short (cmd->options, *curshort);
- if (!opt)
+ if (! opt)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unknown argument `-%c'\n", *curshort);
arg = longarg;
opt = find_long (cmd->options, arg + 2);
- if (!opt)
+ if (! opt)
{
grub_error (GRUB_ERR_BAD_ARGUMENT, "Unknown argument `%s'\n", arg);
goto fail;
}
if (! (opt->type == ARG_TYPE_NONE
- || (!option && (opt->flags & GRUB_ARG_OPTION_OPTIONAL))))
+ || (! option && (opt->flags & GRUB_ARG_OPTION_OPTIONAL))))
{
- if (!option)
+ if (! option)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"Missing mandatory option for `%s'\n", opt->longarg);
/*
* GRUB -- GRand Unified Bootloader
- * Copyright (C) 2003, 2005 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
grub_register_command ("title", 0, GRUB_COMMAND_FLAG_TITLE, 0, 0, 0);
grub_register_command ("rescue", rescue_command, GRUB_COMMAND_FLAG_BOTH,
- "rescue", "Enter into the rescue mode.", 0);
+ "rescue", "Go back to the rescue mode.", 0);
grub_register_command ("set", set_command, GRUB_COMMAND_FLAG_BOTH,
- "set [ENVVAR=VALUE]", "Set an environment variable.", 0);
+ "set [ENVVAR=VALUE]",
+ "Set an environment variable.", 0);
grub_register_command ("unset", unset_command, GRUB_COMMAND_FLAG_BOTH,
"unset ENVVAR", "Remove an environment variable.", 0);
grub_register_command ("insmod", insmod_command, GRUB_COMMAND_FLAG_BOTH,
- "insmod MODULE|FILE", "Insert a module.", 0);
+ "insmod MODULE",
+ "Insert a module. The argument can be a file or a module name.",
+ 0);
grub_register_command ("rmmod", rmmod_command, GRUB_COMMAND_FLAG_BOTH,
"rmmod MODULE", "Remove a module.", 0);