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

serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3b1660a was 3b1660a, checked in by Jiri Svoboda <jiri@…>, 4 years ago

Bdsh help is a little bit rusty

  • Property mode set to 100644
File size: 6.0 KB
RevLine 
[36ab7c7]1/*
2 * Copyright (c) 2008 Tim Post
[22cf42d9]3 * Copyright (c) 2011 Martin Sucha
[216d6fc]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
[36ab7c7]7 * modification, are permitted provided that the following conditions
8 * are met:
[216d6fc]9 *
[36ab7c7]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.
[216d6fc]17 *
[36ab7c7]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.
[216d6fc]28 */
29
30#include <stdio.h>
31#include <stdlib.h>
[582a0b8]32#include <stddef.h>
[19f857a]33#include <str.h>
[22cf42d9]34#include <fmtutil.h>
[43e02a6]35
36#include "config.h"
[216d6fc]37#include "entry.h"
38#include "help.h"
39#include "cmds.h"
40#include "modules.h"
41#include "builtins.h"
42#include "errors.h"
[43e02a6]43#include "util.h"
[216d6fc]44
[a000878c]45static const char *cmdname = "help";
[216d6fc]46extern const char *progname;
47
[4deb8b5]48#define HELP_IS_COMMANDS 2
49#define HELP_IS_MODULE 1
50#define HELP_IS_BUILTIN 0
51#define HELP_IS_RUBBISH -1
[216d6fc]52
53volatile int mod_switch = -1;
54
55/* Just use a pointer here, no need for mod_switch */
[b510d52]56static int is_mod_or_builtin(char *cmd)
[216d6fc]57{
58 int rc = HELP_IS_RUBBISH;
59
[4deb8b5]60 if (str_cmp(cmd, "commands") == 0)
61 return HELP_IS_COMMANDS;
62
[216d6fc]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
[809813d]77void help_cmd_help(unsigned int level)
[216d6fc]78{
79 if (level == HELP_SHORT) {
80 printf(
[1433ecda]81 "\n %s [command] <extended>\n"
82 " Use help [command] extended for detailed help on [command] "
83 ", even `help'\n\n", cmdname);
[216d6fc]84 } else {
85 printf(
[1433ecda]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);
[216d6fc]92 }
93
[809813d]94 return;
[216d6fc]95}
96
[4deb8b5]97static void help_commands(void)
[216d6fc]98{
99 builtin_t *cmd;
[4deb8b5]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 */
[136ce60]106 for (cmd = builtins; cmd->name != NULL; cmd++) {
[1433ecda]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);
[4deb8b5]112 }
113
114 /* Now, show a list of module commands that are available in this mode */
[136ce60]115 for (mod = modules; mod->name != NULL; mod++) {
[1433ecda]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);
[4deb8b5]121 }
122
123 printf("\n Try %s %s for more information on how `%s' works.\n\n",
[1433ecda]124 cmdname, cmdname, cmdname);
[4deb8b5]125}
126
127/** Display survival tips. ('help' without arguments) */
128static void help_survival(void)
129{
[22cf42d9]130 print_wrapped_console(
131 "Don't panic!\n\n"
[4deb8b5]132
[3b1660a]133 "This is Bdsh, the Brain dead shell, the HelenOS "
134 "command-line interface. Bdsh allows you to enter "
[4deb8b5]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, "
[3b1660a]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"
[4deb8b5]140
[22cf42d9]141 "The most basic filesystem commands are Bdsh builtins. Type "
[4deb8b5]142 "'help commands' [Enter] to see the list of Bdsh builtin commands. "
[3b1660a]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 "
[22cf42d9]152 "these using the F1-F11 keys.\n\n"
[4deb8b5]153
[22cf42d9]154 "This is but a small glimpse of what you can do with HelenOS. "
[4deb8b5]155 "To learn more please point your browser to the HelenOS User's "
[25c1b2c]156 "Guide: http://trac.helenos.org/wiki/UsersGuide\n\n",
[6045ecf]157 ALIGN_LEFT);
[4deb8b5]158}
159
160int cmd_help(char *argv[])
161{
[216d6fc]162 int rc = 0;
163 int argc;
164 int level = HELP_SHORT;
165
[43e02a6]166 argc = cli_count_args(argv);
[216d6fc]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) {
[92fd52d7]175 if (!str_cmp("extended", argv[2]))
[216d6fc]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:
[4deb8b5]185 printf("Invalid topic %s\n", argv[1]);
[216d6fc]186 return CMD_FAILURE;
[4deb8b5]187 case HELP_IS_COMMANDS:
188 help_commands();
189 return CMD_SUCCESS;
[216d6fc]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
[4deb8b5]199 help_survival();
[216d6fc]200
201 return CMD_SUCCESS;
202}
Note: See TracBrowser for help on using the repository browser.