00001
00007
00008
00009 #include <kernel.h>
00010 #include <shell.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013
00024 command xsh_help(ushort stdin, ushort stdout, ushort stderr,
00025 ushort nargs, char *args[])
00026 {
00027 uchar i;
00028 char *command_args[2];
00029
00030
00031 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00032 {
00033 fprintf(stdout, "Usage: help [command]\n");
00034 fprintf(stdout, "Provides a list of commands for the shell.\n");
00035 fprintf(stdout, "If command is provided, help information will ");
00036 fprintf(stdout, "be provided for the specified command; equivalent ");
00037 fprintf(stdout, "to entering 'command --help' into the shell.\n");
00038 fprintf(stdout, "\t--help\t display this help and exit\n");
00039 return OK;
00040 }
00041
00042
00043 if (nargs > 2)
00044 {
00045 fprintf(stderr, "help: too many arguments\n");
00046 fprintf(stderr, "Try 'help --help' for more information.\n");
00047 return SYSERR;
00048 }
00049
00050
00051 if (nargs == 2)
00052 {
00053 for ( i = 0; i < ncommand; i++)
00054 {
00055 if (strncmp(args[1],commandtab[i].name,6) == 0)
00056 {
00057 command_args[0] = args[2];
00058 command_args[1] = "--help";
00059 (*commandtab[i].procedure)(stdin, stdout, stderr,
00060 2, command_args);
00061 return OK;
00062 }
00063 }
00064 fprintf(stdout, "help: no help topics match '%s'. Try 'help --help'");
00065 fprintf(stdout, "for more information.\n");
00066 return SYSERR;
00067 }
00068
00069
00070 fprintf(stdout, "Shell Commands:\n");
00071 for( i = 0; i < ncommand; i++)
00072 { fprintf(stdout, "\t%s\n", commandtab[i].name); }
00073
00074 return OK;
00075 }