00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <str.h>
00034
00035 #include "config.h"
00036 #include "entry.h"
00037 #include "help.h"
00038 #include "cmds.h"
00039 #include "modules.h"
00040 #include "builtins.h"
00041 #include "errors.h"
00042 #include "util.h"
00043
00044 static const char *cmdname = "help";
00045 extern const char *progname;
00046
00047 #define HELP_IS_COMMANDS 2
00048 #define HELP_IS_MODULE 1
00049 #define HELP_IS_BUILTIN 0
00050 #define HELP_IS_RUBBISH -1
00051
00052 volatile int mod_switch = -1;
00053
00054
00055 static int is_mod_or_builtin(char *cmd)
00056 {
00057 int rc = HELP_IS_RUBBISH;
00058
00059 if (str_cmp(cmd, "commands") == 0)
00060 return HELP_IS_COMMANDS;
00061
00062 rc = is_builtin(cmd);
00063 if (rc > -1) {
00064 mod_switch = rc;
00065 return HELP_IS_BUILTIN;
00066 }
00067 rc = is_module(cmd);
00068 if (rc > -1) {
00069 mod_switch = rc;
00070 return HELP_IS_MODULE;
00071 }
00072
00073 return HELP_IS_RUBBISH;
00074 }
00075
00076 void help_cmd_help(unsigned int level)
00077 {
00078 if (level == HELP_SHORT) {
00079 printf(
00080 "\n %s [command] <extended>\n"
00081 " Use help [command] extended for detailed help on [command] "
00082 ", even `help'\n\n", cmdname);
00083 } else {
00084 printf(
00085 "\n `%s' - shows help for commands\n"
00086 " Examples:\n"
00087 " %s [command] Show help for [command]\n"
00088 " %s [command] extended Show extended help for [command]\n"
00089 "\n If no argument is given to %s, a list of commands are shown\n\n",
00090 cmdname, cmdname, cmdname, cmdname);
00091 }
00092
00093 return;
00094 }
00095
00096 static void help_commands(void)
00097 {
00098 builtin_t *cmd;
00099 module_t *mod;
00100 unsigned int i;
00101
00102 printf("\n Bdsh built-in commands:\n");
00103 printf(" ------------------------------------------------------------\n");
00104
00105
00106 for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
00107 if (is_builtin_alias(cmd->name))
00108 printf(" %-16s\tAlias for `%s'\n", cmd->name,
00109 alias_for_builtin(cmd->name));
00110 else
00111 printf(" %-16s\t%s\n", cmd->name, cmd->desc);
00112 }
00113
00114 i = 0;
00115
00116
00117 for (mod = modules; mod->name != NULL; mod++, i++) {
00118 if (is_module_alias(mod->name))
00119 printf(" %-16s\tAlias for `%s'\n", mod->name,
00120 alias_for_module(mod->name));
00121 else
00122 printf(" %-16s\t%s\n", mod->name, mod->desc);
00123 }
00124
00125 printf("\n Try %s %s for more information on how `%s' works.\n\n",
00126 cmdname, cmdname, cmdname);
00127 }
00128
00130 static void help_survival(void)
00131 {
00132 printf("Don't panic!\n\n");
00133
00134 printf("This is Bdsh, the Brain dead shell, currently "
00135 "the primary user interface to HelenOS. Bdsh allows you to enter "
00136 "commands and supports history (Up, Down arrow keys), "
00137 "line editing (Left Arrow, Right Arrow, Home, End, Backspace), "
00138 "selection (Shift + movement keys), copy and paste (Ctrl-C, "
00139 "Ctrl-V), similar to common desktop environments.\n\n");
00140
00141 printf("The most basic filesystem commands are Bdsh builtins. Type "
00142 "'help commands' [Enter] to see the list of Bdsh builtin commands. "
00143 "Other commands are external executables located in the /app and "
00144 "/srv directories. Type 'ls /app' [Enter] and 'ls /srv' [Enter] "
00145 "to see their list. You can execute an external command simply "
00146 "by entering its name (e.g. type 'tetris' [Enter]).\n\n");
00147
00148 printf("HelenOS has virtual consoles (VCs). You can switch between "
00149 "these using the F1-F11 keys.\n\n");
00150
00151 printf("This is but a small glimpse of what you can do with HelenOS. "
00152 "To learn more please point your browser to the HelenOS User's "
00153 "Guide: http://trac.helenos.org/trac.fcgi/wiki/UsersGuide\n\n");
00154 }
00155
00156 int cmd_help(char *argv[])
00157 {
00158 int rc = 0;
00159 int argc;
00160 int level = HELP_SHORT;
00161
00162 argc = cli_count_args(argv);
00163
00164 if (argc > 3) {
00165 printf("\nToo many arguments to `%s', try:\n", cmdname);
00166 help_cmd_help(HELP_SHORT);
00167 return CMD_FAILURE;
00168 }
00169
00170 if (argc == 3) {
00171 if (!str_cmp("extended", argv[2]))
00172 level = HELP_LONG;
00173 else
00174 level = HELP_SHORT;
00175 }
00176
00177 if (argc > 1) {
00178 rc = is_mod_or_builtin(argv[1]);
00179 switch (rc) {
00180 case HELP_IS_RUBBISH:
00181 printf("Invalid topic %s\n", argv[1]);
00182 return CMD_FAILURE;
00183 case HELP_IS_COMMANDS:
00184 help_commands();
00185 return CMD_SUCCESS;
00186 case HELP_IS_MODULE:
00187 help_module(mod_switch, level);
00188 return CMD_SUCCESS;
00189 case HELP_IS_BUILTIN:
00190 help_builtin(mod_switch, level);
00191 return CMD_SUCCESS;
00192 }
00193 }
00194
00195 help_survival();
00196
00197 return CMD_SUCCESS;
00198 }