]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
e246ba5f | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2003-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
e246ba5f NS |
5 | */ |
6 | ||
dcabd4e7 | 7 | #include "platform_defs.h" |
6b803e5a | 8 | #include "command.h" |
b20b6c22 | 9 | #include "../quota/init.h" |
e246ba5f NS |
10 | |
11 | static cmdinfo_t help_cmd; | |
12 | static void help_onecmd(const char *cmd, const cmdinfo_t *ct); | |
13 | static void help_oneline(const char *cmd, const cmdinfo_t *ct); | |
14 | ||
15 | static void | |
16 | help_all(void) | |
17 | { | |
18 | const cmdinfo_t *ct; | |
19 | ||
20 | for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) | |
21 | help_oneline(ct->name, ct); | |
22 | printf(_("\nUse 'help commandname' for extended help.\n")); | |
23 | } | |
24 | ||
25 | static int | |
26 | help_f( | |
27 | int argc, | |
28 | char **argv) | |
29 | { | |
30 | const cmdinfo_t *ct; | |
31 | ||
32 | if (argc == 1) { | |
33 | help_all(); | |
34 | return 0; | |
35 | } | |
36 | ct = find_command(argv[1]); | |
37 | if (ct == NULL) { | |
38 | printf(_("command %s not found\n"), argv[1]); | |
39 | return 0; | |
40 | } | |
41 | help_onecmd(argv[1], ct); | |
42 | return 0; | |
43 | } | |
44 | ||
45 | static void | |
46 | help_onecmd( | |
47 | const char *cmd, | |
48 | const cmdinfo_t *ct) | |
49 | { | |
50 | help_oneline(cmd, ct); | |
51 | if (ct->help) | |
52 | ct->help(); | |
53 | } | |
54 | ||
55 | static void | |
56 | help_oneline( | |
57 | const char *cmd, | |
58 | const cmdinfo_t *ct) | |
59 | { | |
60 | if (cmd) | |
61 | printf("%s ", cmd); | |
62 | else { | |
63 | printf("%s ", ct->name); | |
64 | if (ct->altname) | |
65 | printf("(or %s) ", ct->altname); | |
66 | } | |
67 | if (ct->args) | |
68 | printf("%s ", ct->args); | |
69 | printf("-- %s\n", ct->oneline); | |
70 | } | |
71 | ||
72 | void | |
73 | help_init(void) | |
74 | { | |
ad765595 AM |
75 | help_cmd.name = "help"; |
76 | help_cmd.altname = "?"; | |
e246ba5f NS |
77 | help_cmd.cfunc = help_f; |
78 | help_cmd.argmin = 0; | |
79 | help_cmd.argmax = 1; | |
92058d25 | 80 | help_cmd.flags = CMD_FLAG_ONESHOT | CMD_FLAG_LIBRARY; |
e246ba5f NS |
81 | help_cmd.args = _("[command]"); |
82 | help_cmd.oneline = _("help for one or all commands"); | |
83 | ||
84 | add_command(&help_cmd); | |
85 | } |