]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2001,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 | |
2bd0ea18 | 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 | |
2bd0ea18 NS |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
2bd0ea18 NS |
20 | #include "command.h" |
21 | #include "help.h" | |
22 | #include "output.h" | |
23 | ||
24 | static void help_all(void); | |
25 | static void help_onecmd(const char *cmd, const cmdinfo_t *ct); | |
26 | static int help_f(int argc, char **argv); | |
27 | static void help_oneline(const char *cmd, const cmdinfo_t *ct); | |
28 | ||
29 | static const cmdinfo_t help_cmd = | |
9ee7055c AM |
30 | { "help", "?", help_f, 0, 1, 0, N_("[command]"), |
31 | N_("help for one or all commands"), NULL }; | |
2bd0ea18 NS |
32 | |
33 | static void | |
34 | help_all(void) | |
35 | { | |
36 | const cmdinfo_t *ct; | |
37 | ||
38 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) | |
39 | help_oneline(ct->name, ct); | |
9ee7055c | 40 | dbprintf(_("\nUse 'help commandname' for extended help.\n")); |
2bd0ea18 NS |
41 | } |
42 | ||
43 | static int | |
44 | help_f( | |
45 | int argc, | |
46 | char **argv) | |
47 | { | |
48 | const cmdinfo_t *ct; | |
49 | ||
50 | if (argc == 1) { | |
51 | help_all(); | |
52 | return 0; | |
53 | } | |
54 | ct = find_command(argv[1]); | |
55 | if (ct == NULL) { | |
9ee7055c | 56 | dbprintf(_("command %s not found\n"), argv[1]); |
2bd0ea18 NS |
57 | return 0; |
58 | } | |
59 | help_onecmd(argv[1], ct); | |
60 | return 0; | |
61 | } | |
62 | ||
63 | void | |
64 | help_init(void) | |
65 | { | |
66 | add_command(&help_cmd); | |
67 | } | |
68 | ||
69 | static void | |
70 | help_onecmd( | |
71 | const char *cmd, | |
72 | const cmdinfo_t *ct) | |
73 | { | |
74 | help_oneline(cmd, ct); | |
75 | if (ct->help) | |
76 | ct->help(); | |
77 | } | |
78 | ||
79 | static void | |
80 | help_oneline( | |
81 | const char *cmd, | |
82 | const cmdinfo_t *ct) | |
83 | { | |
84 | if (cmd) | |
85 | dbprintf("%s ", cmd); | |
86 | else { | |
87 | dbprintf("%s ", ct->name); | |
88 | if (ct->altname) | |
9ee7055c | 89 | dbprintf(_("(or %s) "), ct->altname); |
2bd0ea18 NS |
90 | } |
91 | if (ct->args) | |
92 | dbprintf("%s ", ct->args); | |
93 | dbprintf("-- %s\n", ct->oneline); | |
94 | } |