]>
Commit | Line | Data |
---|---|---|
e246ba5f | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2003-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
e246ba5f | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
e246ba5f NS |
17 | */ |
18 | ||
dcabd4e7 | 19 | #include "platform_defs.h" |
6b803e5a | 20 | #include "command.h" |
b20b6c22 | 21 | #include "../quota/init.h" |
e246ba5f NS |
22 | |
23 | static cmdinfo_t help_cmd; | |
24 | static void help_onecmd(const char *cmd, const cmdinfo_t *ct); | |
25 | static void help_oneline(const char *cmd, const cmdinfo_t *ct); | |
26 | ||
27 | static void | |
28 | help_all(void) | |
29 | { | |
30 | const cmdinfo_t *ct; | |
31 | ||
32 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) | |
33 | help_oneline(ct->name, ct); | |
34 | printf(_("\nUse 'help commandname' for extended help.\n")); | |
35 | } | |
36 | ||
37 | static int | |
38 | help_f( | |
39 | int argc, | |
40 | char **argv) | |
41 | { | |
42 | const cmdinfo_t *ct; | |
43 | ||
44 | if (argc == 1) { | |
45 | help_all(); | |
46 | return 0; | |
47 | } | |
48 | ct = find_command(argv[1]); | |
49 | if (ct == NULL) { | |
50 | printf(_("command %s not found\n"), argv[1]); | |
51 | return 0; | |
52 | } | |
53 | help_onecmd(argv[1], ct); | |
54 | return 0; | |
55 | } | |
56 | ||
57 | static void | |
58 | help_onecmd( | |
59 | const char *cmd, | |
60 | const cmdinfo_t *ct) | |
61 | { | |
62 | help_oneline(cmd, ct); | |
63 | if (ct->help) | |
64 | ct->help(); | |
65 | } | |
66 | ||
67 | static void | |
68 | help_oneline( | |
69 | const char *cmd, | |
70 | const cmdinfo_t *ct) | |
71 | { | |
72 | if (cmd) | |
73 | printf("%s ", cmd); | |
74 | else { | |
75 | printf("%s ", ct->name); | |
76 | if (ct->altname) | |
77 | printf("(or %s) ", ct->altname); | |
78 | } | |
79 | if (ct->args) | |
80 | printf("%s ", ct->args); | |
81 | printf("-- %s\n", ct->oneline); | |
82 | } | |
83 | ||
84 | void | |
85 | help_init(void) | |
86 | { | |
ad765595 AM |
87 | help_cmd.name = "help"; |
88 | help_cmd.altname = "?"; | |
e246ba5f NS |
89 | help_cmd.cfunc = help_f; |
90 | help_cmd.argmin = 0; | |
91 | help_cmd.argmax = 1; | |
92058d25 | 92 | help_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_LIBRARY; |
e246ba5f NS |
93 | help_cmd.args = _("[command]"); |
94 | help_cmd.oneline = _("help for one or all commands"); | |
95 | ||
96 | add_command(&help_cmd); | |
97 | } |