1 /* help.c - command to show a help text. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/normal.h>
23 #include <grub/misc.h>
24 #include <grub/term.h>
27 grub_cmd_help (struct grub_arg_list
*state
__attribute__ ((unused
)), int argc
,
34 auto int print_command_info (grub_command_t cmd
);
35 auto int print_command_help (grub_command_t cmd
);
37 int print_command_info (grub_command_t cmd
)
39 if (grub_command_find (cmd
->name
))
41 if (cmd
->flags
& GRUB_COMMAND_FLAG_CMDLINE
)
43 char description
[GRUB_TERM_WIDTH
/ 2];
44 int desclen
= grub_strlen (cmd
->summary
);
46 /* Make a string with a length of GRUB_TERM_WIDTH / 2 - 1 filled
47 with the description followed by spaces. */
48 grub_memset (description
, ' ', GRUB_TERM_WIDTH
/ 2 - 1);
49 description
[GRUB_TERM_WIDTH
/ 2 - 1] = '\0';
50 grub_memcpy (description
, cmd
->summary
,
51 (desclen
< GRUB_TERM_WIDTH
/ 2 - 1
52 ? desclen
: GRUB_TERM_WIDTH
/ 2 - 1));
54 grub_printf ("%s%s", description
, (cnt
++) % 2 ? "\n" : " ");
60 int print_command_help (grub_command_t cmd
)
62 if (grub_command_find (cmd
->name
))
64 if (! grub_strncmp (cmd
->name
, currarg
, grub_strlen (currarg
)))
69 grub_arg_show_help (cmd
);
76 grub_iterate_commands (print_command_info
);
81 for (i
= 0; i
< argc
; i
++)
84 grub_iterate_commands (print_command_help
);
95 (void)mod
; /* To stop warning. */
96 grub_register_command ("help", grub_cmd_help
, GRUB_COMMAND_FLAG_CMDLINE
,
97 "help [PATTERN ...]", "Show a help message.", 0);
102 grub_unregister_command ("help");