]>
Commit | Line | Data |
---|---|---|
e246ba5f | 1 | /* |
f72d20ad | 2 | * Copyright (c) 2003-2004 Silicon Graphics, Inc. All Rights Reserved. |
dfc130f3 | 3 | * |
e246ba5f NS |
4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
dfc130f3 | 7 | * |
e246ba5f NS |
8 | * This program is distributed in the hope that it would be useful, but |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
dfc130f3 | 11 | * |
e246ba5f NS |
12 | * Further, this software is distributed without any warranty that it is |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
dfc130f3 | 18 | * |
e246ba5f NS |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
dfc130f3 | 22 | * |
e246ba5f NS |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
24 | * Mountain View, CA 94043, or: | |
dfc130f3 RC |
25 | * |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
e246ba5f NS |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ |
31 | */ | |
32 | ||
1d7e80ee | 33 | #include <xfs/libxfs.h> |
e246ba5f NS |
34 | #include "command.h" |
35 | ||
36 | static cmdinfo_t help_cmd; | |
37 | static void help_onecmd(const char *cmd, const cmdinfo_t *ct); | |
38 | static void help_oneline(const char *cmd, const cmdinfo_t *ct); | |
39 | ||
40 | static void | |
41 | help_all(void) | |
42 | { | |
43 | const cmdinfo_t *ct; | |
44 | ||
45 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) | |
46 | help_oneline(ct->name, ct); | |
47 | printf(_("\nUse 'help commandname' for extended help.\n")); | |
48 | } | |
49 | ||
50 | static int | |
51 | help_f( | |
52 | int argc, | |
53 | char **argv) | |
54 | { | |
55 | const cmdinfo_t *ct; | |
56 | ||
57 | if (argc == 1) { | |
58 | help_all(); | |
59 | return 0; | |
60 | } | |
61 | ct = find_command(argv[1]); | |
62 | if (ct == NULL) { | |
63 | printf(_("command %s not found\n"), argv[1]); | |
64 | return 0; | |
65 | } | |
66 | help_onecmd(argv[1], ct); | |
67 | return 0; | |
68 | } | |
69 | ||
70 | static void | |
71 | help_onecmd( | |
72 | const char *cmd, | |
73 | const cmdinfo_t *ct) | |
74 | { | |
75 | help_oneline(cmd, ct); | |
76 | if (ct->help) | |
77 | ct->help(); | |
78 | } | |
79 | ||
80 | static void | |
81 | help_oneline( | |
82 | const char *cmd, | |
83 | const cmdinfo_t *ct) | |
84 | { | |
85 | if (cmd) | |
86 | printf("%s ", cmd); | |
87 | else { | |
88 | printf("%s ", ct->name); | |
89 | if (ct->altname) | |
90 | printf("(or %s) ", ct->altname); | |
91 | } | |
92 | if (ct->args) | |
93 | printf("%s ", ct->args); | |
94 | printf("-- %s\n", ct->oneline); | |
95 | } | |
96 | ||
97 | void | |
98 | help_init(void) | |
99 | { | |
100 | help_cmd.name = _("help"); | |
101 | help_cmd.altname = _("?"); | |
102 | help_cmd.cfunc = help_f; | |
103 | help_cmd.argmin = 0; | |
104 | help_cmd.argmax = 1; | |
f72d20ad | 105 | help_cmd.foreign = 1; |
e246ba5f NS |
106 | help_cmd.args = _("[command]"); |
107 | help_cmd.oneline = _("help for one or all commands"); | |
108 | ||
109 | add_command(&help_cmd); | |
110 | } |