source: mainline/uspace/app/bdsh/cmds/modules/help/help.c

Last change on this file was 14b2ac7, checked in by Martin Decky <martin@…>, 10 months ago

Change relevant URLs from HTTP to HTTPS

The helenos.org web site (including many of the subdomains) is
accessible using HTTPS. While the redirections from HTTP are available,
HTTPS is generally prefered now.

Note that switching to HTTPS unconditionally in all cases is not
possible yet due to various limitations.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2008 Tim Post
3 * Copyright (c) 2011 Martin Sucha
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <stddef.h>
33#include <str.h>
34#include <fmtutil.h>
35
36#include "config.h"
37#include "entry.h"
38#include "help.h"
39#include "cmds.h"
40#include "modules.h"
41#include "builtins.h"
42#include "errors.h"
43#include "util.h"
44
45static const char *cmdname = "help";
46extern const char *progname;
47
48#define HELP_IS_COMMANDS 2
49#define HELP_IS_MODULE 1
50#define HELP_IS_BUILTIN 0
51#define HELP_IS_RUBBISH -1
52
53volatile int mod_switch = -1;
54
55/* Just use a pointer here, no need for mod_switch */
56static int is_mod_or_builtin(char *cmd)
57{
58 int rc = HELP_IS_RUBBISH;
59
60 if (str_cmp(cmd, "commands") == 0)
61 return HELP_IS_COMMANDS;
62
63 rc = is_builtin(cmd);
64 if (rc > -1) {
65 mod_switch = rc;
66 return HELP_IS_BUILTIN;
67 }
68 rc = is_module(cmd);
69 if (rc > -1) {
70 mod_switch = rc;
71 return HELP_IS_MODULE;
72 }
73
74 return HELP_IS_RUBBISH;
75}
76
77void help_cmd_help(unsigned int level)
78{
79 if (level == HELP_SHORT) {
80 printf(
81 "\n %s [command] <extended>\n"
82 " Use help [command] extended for detailed help on [command] "
83 ", even `help'\n\n", cmdname);
84 } else {
85 printf(
86 "\n `%s' - shows help for commands\n"
87 " Examples:\n"
88 " %s [command] Show help for [command]\n"
89 " %s [command] extended Show extended help for [command]\n"
90 "\n If no argument is given to %s, a list of commands are shown\n\n",
91 cmdname, cmdname, cmdname, cmdname);
92 }
93
94 return;
95}
96
97static void help_commands(void)
98{
99 builtin_t *cmd;
100 module_t *mod;
101
102 printf("\n Bdsh built-in commands:\n");
103 printf(" ------------------------------------------------------------\n");
104
105 /* First, show a list of built in commands that are available in this mode */
106 for (cmd = builtins; cmd->name != NULL; cmd++) {
107 if (is_builtin_alias(cmd->name))
108 printf(" %-16s\tAlias for `%s'\n", cmd->name,
109 alias_for_builtin(cmd->name));
110 else
111 printf(" %-16s\t%s\n", cmd->name, cmd->desc);
112 }
113
114 /* Now, show a list of module commands that are available in this mode */
115 for (mod = modules; mod->name != NULL; mod++) {
116 if (is_module_alias(mod->name))
117 printf(" %-16s\tAlias for `%s'\n", mod->name,
118 alias_for_module(mod->name));
119 else
120 printf(" %-16s\t%s\n", mod->name, mod->desc);
121 }
122
123 printf("\n Try %s %s for more information on how `%s' works.\n\n",
124 cmdname, cmdname, cmdname);
125}
126
127/** Display survival tips. ('help' without arguments) */
128static void help_survival(void)
129{
130 print_wrapped_console(
131 "Don't panic!\n\n"
132
133 "This is Bdsh, the Brain dead shell, the HelenOS "
134 "command-line interface. Bdsh allows you to enter "
135 "commands and supports history (Up, Down arrow keys), "
136 "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
137 "selection (Shift + movement keys), copy and paste (Ctrl-C, "
138 "Ctrl-V). You can also click your mouse within the input line "
139 "to seek and use your mouse wheel to scroll through history.\n\n"
140
141 "The most basic filesystem commands are Bdsh builtins. Type "
142 "'help commands' [Enter] to see the list of Bdsh builtin commands. "
143 "Other commands are external executables located in the /app "
144 "directory. Type 'ls /app' [Enter] to see their list. "
145 "You can execute an external command simply "
146 "by entering its name. E.g., type 'nav' [Enter] to start "
147 "Navigator, HelenOS interactive file manager).\n\n"
148
149 "If you are not running in GUI mode, (where you can start "
150 "multiple Terminal windows,) HelenOS console supports "
151 "virtual consoles (VCs). You can switch between "
152 "these using the F1-F11 keys.\n\n"
153
154 "This is but a small glimpse of what you can do with HelenOS. "
155 "To learn more please point your browser to the HelenOS User's "
156 "Guide: https://www.helenos.org/wiki/UsersGuide\n\n",
157 ALIGN_LEFT);
158}
159
160int cmd_help(char *argv[])
161{
162 int rc = 0;
163 int argc;
164 int level = HELP_SHORT;
165
166 argc = cli_count_args(argv);
167
168 if (argc > 3) {
169 printf("\nToo many arguments to `%s', try:\n", cmdname);
170 help_cmd_help(HELP_SHORT);
171 return CMD_FAILURE;
172 }
173
174 if (argc == 3) {
175 if (!str_cmp("extended", argv[2]))
176 level = HELP_LONG;
177 else
178 level = HELP_SHORT;
179 }
180
181 if (argc > 1) {
182 rc = is_mod_or_builtin(argv[1]);
183 switch (rc) {
184 case HELP_IS_RUBBISH:
185 printf("Invalid topic %s\n", argv[1]);
186 return CMD_FAILURE;
187 case HELP_IS_COMMANDS:
188 help_commands();
189 return CMD_SUCCESS;
190 case HELP_IS_MODULE:
191 help_module(mod_switch, level);
192 return CMD_SUCCESS;
193 case HELP_IS_BUILTIN:
194 help_builtin(mod_switch, level);
195 return CMD_SUCCESS;
196 }
197 }
198
199 help_survival();
200
201 return CMD_SUCCESS;
202}
Note: See TracBrowser for help on using the repository browser.