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.
This commit is contained in:
okuji 2005-07-17 20:26:07 +00:00
parent f806d18efd
commit 502c87e80e
17 changed files with 174 additions and 72 deletions

View File

@ -1,3 +1,46 @@
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.

View File

@ -1,7 +1,7 @@
/* 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
@ -43,7 +43,7 @@ void
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
@ -54,9 +54,9 @@ grub_boot_fini (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

View File

@ -1,7 +1,7 @@
/* 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
@ -74,7 +74,7 @@ void
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
@ -85,9 +85,9 @@ grub_cat_fini (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

View File

@ -1,7 +1,7 @@
/* 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
@ -106,7 +106,7 @@ void
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
@ -117,9 +117,9 @@ grub_cmp_fini (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

View File

@ -45,7 +45,7 @@ grub_configfile_init (void)
{
grub_register_command ("configfile", grub_cmd_configfile,
GRUB_COMMAND_FLAG_BOTH, "configfile FILE",
"Load config file", 0);
"Load another config file.", 0);
}
void
@ -56,10 +56,10 @@ grub_configfile_fini (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

View File

@ -99,7 +99,7 @@ void
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
@ -112,7 +112,7 @@ 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);
"help [PATTERN ...]", "Show a help message.", 0);
}
GRUB_MOD_FINI

View File

@ -25,7 +25,7 @@
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}
};
@ -63,7 +63,7 @@ GRUB_MOD_INIT
{
(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);
}

View File

@ -40,7 +40,7 @@ void
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

View File

@ -33,9 +33,9 @@
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}
};
@ -241,8 +241,8 @@ void
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
@ -255,8 +255,8 @@ GRUB_MOD_INIT
{
(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

View File

@ -38,8 +38,8 @@ static struct grub_loopback *loopback_list;
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}
};
@ -245,7 +245,8 @@ void
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);
}
@ -260,7 +261,8 @@ GRUB_MOD_INIT
{
(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);
}

View File

@ -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
@ -236,7 +236,8 @@ GRUB_MOD_INIT
{
(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

View File

@ -1,6 +1,6 @@
/*
* 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
@ -49,8 +49,8 @@ typedef enum grub_key_type grub_arg_key_type_t;
struct grub_arg_option
{
char *longarg;
char shortarg;
const char *longarg;
int shortarg;
int flags;
char *doc;
char *arg;

View File

@ -25,7 +25,7 @@
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}
};
@ -47,8 +47,8 @@ GRUB_MOD_INIT
(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

View File

@ -1,7 +1,7 @@
/* 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
@ -46,12 +46,12 @@ GRUB_MOD_INIT
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

View File

@ -1,7 +1,7 @@
/* 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
@ -46,12 +46,12 @@ GRUB_MOD_INIT
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

View File

@ -1,7 +1,7 @@
/* 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
@ -18,17 +18,23 @@
* 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}
};
@ -51,8 +57,23 @@ find_short (const struct grub_arg_option *options, char c)
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;
}
@ -80,7 +101,7 @@ find_long (const struct grub_arg_option *options, char *s)
{
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++;
}
@ -89,7 +110,8 @@ find_long (const struct grub_arg_option *options, char *s)
if (options)
found = fnd_long (options);
if (!found)
if (! found)
found = fnd_long (help_options);
return found;
@ -104,24 +126,55 @@ show_usage (grub_command_t cmd)
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;
}
}
}
@ -141,11 +194,11 @@ parse_option (grub_command_t cmd, int key, char *arg, struct grub_arg_list *usr)
{
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;
@ -221,7 +274,7 @@ grub_arg_parse (grub_command_t cmd, int argc, char **argv,
while (1)
{
opt = find_short (cmd->options, *curshort);
if (!opt)
if (! opt)
{
grub_error (GRUB_ERR_BAD_ARGUMENT,
"Unknown argument `-%c'\n", *curshort);
@ -274,7 +327,7 @@ grub_arg_parse (grub_command_t cmd, int argc, char **argv,
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;
@ -282,9 +335,9 @@ grub_arg_parse (grub_command_t cmd, int argc, char **argv,
}
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);

View File

@ -1,6 +1,6 @@
/*
* 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
@ -382,16 +382,19 @@ grub_command_init (void)
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);