]>
Commit | Line | Data |
---|---|---|
990cf3aa | 1 | /* help.c - command to show a help text. */ |
2 | /* | |
3 | * GRUB -- GRand Unified Bootloader | |
58bc8bd5 | 4 | * Copyright (C) 2005,2007,2008,2009 Free Software Foundation, Inc. |
990cf3aa | 5 | * |
5a79f472 | 6 | * GRUB is free software: you can redistribute it and/or modify |
990cf3aa | 7 | * it under the terms of the GNU General Public License as published by |
5a79f472 | 8 | * the Free Software Foundation, either version 3 of the License, or |
990cf3aa | 9 | * (at your option) any later version. |
10 | * | |
5a79f472 | 11 | * GRUB is distributed in the hope that it will be useful, |
990cf3aa | 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. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
5a79f472 | 17 | * along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
990cf3aa | 18 | */ |
19 | ||
990cf3aa | 20 | #include <grub/dl.h> |
990cf3aa | 21 | #include <grub/misc.h> |
47f908ab | 22 | #include <grub/term.h> |
b1b797cb | 23 | #include <grub/extcmd.h> |
ec5f98ab | 24 | #include <grub/i18n.h> |
33937904 | 25 | #include <grub/mm.h> |
26 | #include <grub/normal.h> | |
51963451 | 27 | #include <grub/charset.h> |
990cf3aa | 28 | |
990cf3aa | 29 | static grub_err_t |
b1b797cb | 30 | grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, |
990cf3aa | 31 | char **args) |
990cf3aa | 32 | { |
33 | int cnt = 0; | |
34 | char *currarg; | |
b39f9d20 | 35 | |
990cf3aa | 36 | auto int print_command_info (grub_command_t cmd); |
37 | auto int print_command_help (grub_command_t cmd); | |
38 | ||
39 | int print_command_info (grub_command_t cmd) | |
40 | { | |
b1b797cb | 41 | if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && |
42 | (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)) | |
990cf3aa | 43 | { |
51963451 VS |
44 | struct grub_term_output *term; |
45 | const char *summary_translated = _(cmd->summary); | |
33937904 | 46 | char *command_help; |
33937904 | 47 | grub_uint32_t *unicode_command_help; |
48 | grub_uint32_t *unicode_last_position; | |
33937904 | 49 | |
61eb45ee | 50 | command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated); |
2d49abe9 VS |
51 | if (!command_help) |
52 | return 1; | |
33937904 | 53 | |
54 | grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help, | |
55 | &unicode_last_position); | |
33937904 | 56 | |
51963451 | 57 | FOR_ACTIVE_TERM_OUTPUTS(term) |
3be7f8de | 58 | { |
51963451 VS |
59 | unsigned stringwidth; |
60 | grub_uint32_t *unicode_last_screen_position; | |
61 | ||
62 | unicode_last_screen_position = unicode_command_help; | |
63 | ||
64 | stringwidth = 0; | |
65 | ||
66 | while (unicode_last_screen_position < unicode_last_position && | |
67 | stringwidth < ((grub_term_width (term) / 2) - 2)) | |
68 | { | |
69 | stringwidth | |
70 | += grub_term_getcharwidth (term, | |
71 | *unicode_last_screen_position); | |
72 | unicode_last_screen_position++; | |
73 | } | |
74 | ||
75 | grub_print_ucs4 (unicode_command_help, | |
76 | unicode_last_screen_position, term); | |
77 | if (!(cnt % 2)) | |
78 | grub_print_spaces (term, grub_term_width (term) / 2 | |
79 | - stringwidth); | |
3be7f8de | 80 | } |
51963451 | 81 | if (cnt % 2) |
f4c623e1 | 82 | grub_printf ("\n"); |
51963451 | 83 | cnt++; |
33937904 | 84 | |
85 | grub_free (command_help); | |
86 | grub_free (unicode_command_help); | |
990cf3aa | 87 | } |
990cf3aa | 88 | return 0; |
89 | } | |
90 | ||
91 | int print_command_help (grub_command_t cmd) | |
92 | { | |
761319cf | 93 | if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) |
990cf3aa | 94 | { |
5822ff87 | 95 | if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg))) |
96 | { | |
97 | if (cnt++ > 0) | |
98 | grub_printf ("\n\n"); | |
b39f9d20 | 99 | |
b1b797cb | 100 | if (cmd->flags & GRUB_COMMAND_FLAG_EXTCMD) |
101 | grub_arg_show_help ((grub_extcmd_t) cmd->data); | |
102 | else | |
fdcdbb66 | 103 | grub_printf ("%s %s %s\n%s\b", _("Usage:"), cmd->name, _(cmd->summary), |
ec5f98ab | 104 | _(cmd->description)); |
5822ff87 | 105 | } |
990cf3aa | 106 | } |
107 | return 0; | |
108 | } | |
b39f9d20 | 109 | |
990cf3aa | 110 | if (argc == 0) |
3be7f8de VS |
111 | { |
112 | grub_command_iterate (print_command_info); | |
113 | if (!(cnt % 2)) | |
114 | grub_printf ("\n"); | |
115 | } | |
990cf3aa | 116 | else |
117 | { | |
118 | int i; | |
b39f9d20 | 119 | |
990cf3aa | 120 | for (i = 0; i < argc; i++) |
121 | { | |
122 | currarg = args[i]; | |
b1b797cb | 123 | grub_command_iterate (print_command_help); |
990cf3aa | 124 | } |
125 | } | |
b39f9d20 | 126 | |
990cf3aa | 127 | return 0; |
128 | } | |
129 | ||
b1b797cb | 130 | static grub_extcmd_t cmd; |
990cf3aa | 131 | \f |
6d099807 | 132 | GRUB_MOD_INIT(help) |
990cf3aa | 133 | { |
b1b797cb | 134 | cmd = grub_register_extcmd ("help", grub_cmd_help, |
135 | GRUB_COMMAND_FLAG_CMDLINE, | |
fdcdbb66 | 136 | N_("[PATTERN ...]"), |
ec5f98ab | 137 | N_("Show a help message."), 0); |
990cf3aa | 138 | } |
139 | ||
6d099807 | 140 | GRUB_MOD_FINI(help) |
990cf3aa | 141 | { |
b1b797cb | 142 | grub_unregister_extcmd (cmd); |
990cf3aa | 143 | } |