|
FreeNOS
|
System command shell interpreter. More...
#include <Shell.h>
Public Member Functions | |
| Shell (int argc, char **argv) | |
| Constructor. More... | |
| virtual | ~Shell () |
| Destructor. More... | |
| virtual Result | exec () |
| Execute the application. More... | |
| ShellCommand * | getCommand (const char *name) |
| Get shell command. More... | |
| HashTable< String, ShellCommand * > & | getCommands () |
| Get all shell commands. More... | |
| void | registerCommand (ShellCommand *command) |
| Register a new ShellCommand. More... | |
| int | executeInput (const Size argc, const char **argv, const bool background) |
| Executes the given input. More... | |
| int | executeInput (char *cmdline) |
| Executes the given input. More... | |
Public Member Functions inherited from POSIXApplication | |
| POSIXApplication (int argc, char **argv) | |
| Class constructor. More... | |
| virtual | ~POSIXApplication () |
| Class destructor. More... | |
Public Member Functions inherited from Application | |
| Application (int argc, char **argv) | |
| Class constructor. More... | |
| virtual | ~Application () |
| Class destructor. More... | |
| virtual int | run () |
| Run the application. More... | |
Private Member Functions | |
| Result | runInteractive () |
| Executes the Shell by entering an infinite loop. More... | |
| char * | getInput () const |
| Fetch a command text from standard input. More... | |
| void | prompt () const |
| Output a prompt. More... | |
| Size | parse (char *cmdline, char **argv, Size maxArgv, bool *background) |
| Parses an input string into separate pieces. More... | |
Private Attributes | |
| HashTable< String, ShellCommand * > | m_commands |
| All known ShellCommands. More... | |
Additional Inherited Members | |
Public Types inherited from Application | |
| enum | Result { Success, NotFound, IOError, InvalidArgument, ShowUsage, TimedOut, OutOfMemory } |
| Result codes. More... | |
Protected Member Functions inherited from POSIXApplication | |
| virtual Result | output (const char *string) const |
| Print text to output. More... | |
| int | runProgram (const char *path, const char **argv) |
| Runs an external program. More... | |
Protected Member Functions inherited from Application | |
| virtual Result | initialize () |
| Initialize the application. More... | |
| virtual Result | output (String &string) const |
| Print string to output. More... | |
| ArgumentParser & | parser () |
| Get program arguments parser. More... | |
| const ArgumentParser & | parser () const |
| Get constant program arguments parser. More... | |
| const ArgumentContainer & | arguments () const |
| Get program arguments. More... | |
| void | setVersion (const String &version) |
| Set program version. More... | |
Protected Attributes inherited from Application | |
| int | m_argc |
| Input argument count. More... | |
| char ** | m_argv |
| Input argument values. More... | |
| Shell::Shell | ( | int | argc, |
| char ** | argv | ||
| ) |
Constructor.
Definition at line 40 of file Shell.cpp.
References Application::parser(), registerCommand(), ArgumentParser::registerPositional(), and ArgumentParser::setDescription().
|
virtual |
Destructor.
Definition at line 54 of file Shell.cpp.
References HashIterator< K, V >::hasCurrent(), and m_commands.
|
virtual |
Execute the application.
Implements Application.
Definition at line 62 of file Shell.cpp.
References Application::arguments(), Vector< T >::count(), errno, ERROR, executeInput(), fclose(), fopen(), fread(), ArgumentContainer::getPositionals(), ListIterator< T >::hasCurrent(), NULL, printf(), runInteractive(), String::split(), stat::st_size, stat(), strerror(), and Application::Success.
| int Shell::executeInput | ( | char * | cmdline | ) |
Executes the given input.
| cmdline | Full commandline input to execute. |
Definition at line 220 of file Shell.cpp.
References executeInput(), EXIT_SUCCESS, MAX_ARGV, parse(), and strlen().
| int Shell::executeInput | ( | const Size | argc, |
| const char ** | argv, | ||
| const bool | background | ||
| ) |
Executes the given input.
| argc | Argument count |
| argv | Argument values |
| background | True to run program without waiting for termination |
Definition at line 161 of file Shell.cpp.
References DEBUG, errno, ERROR, ShellCommand::execute(), EXIT_FAILURE, EXIT_SUCCESS, getCommand(), ShellCommand::getMinimumParams(), ShellCommand::getName(), POSIXApplication::runProgram(), snprintf(), strerror(), and waitpid().
Referenced by exec(), TimeCommand::execute(), executeInput(), and runInteractive().
| ShellCommand * Shell::getCommand | ( | const char * | name | ) |
Get shell command.
| name | ShellCommand name. |
Definition at line 317 of file Shell.cpp.
References HashTable< K, V >::get(), m_commands, and ZERO.
Referenced by executeInput().
| HashTable< String, ShellCommand * > & Shell::getCommands | ( | ) |
Get all shell commands.
Definition at line 312 of file Shell.cpp.
References m_commands.
Referenced by HelpCommand::execute().
|
private |
Parses an input string into separate pieces.
| cmdline | Command input string. |
| argv | Argument list buffer. |
| maxArgv | Maximum number of entries in argv. |
| background | True if process must run in the background. |
Definition at line 327 of file Shell.cpp.
References ZERO.
Referenced by executeInput().
|
private |
Output a prompt.
Definition at line 289 of file Shell.cpp.
References BLUE, getcwd(), gethostname(), GREEN, NULL, printf(), and WHITE.
Referenced by runInteractive().
| void Shell::registerCommand | ( | ShellCommand * | command | ) |
Register a new ShellCommand.
| command | ShellCommand object pointer. |
Definition at line 322 of file Shell.cpp.
References ShellCommand::getName(), HashTable< K, V >::insert(), and m_commands.
Referenced by Shell().
|
private |
Executes the Shell by entering an infinite loop.
Definition at line 135 of file Shell.cpp.
References executeInput(), getInput(), prompt(), strlen(), and Application::Success.
Referenced by exec().
|
private |
All known ShellCommands.
Definition at line 131 of file Shell.h.
Referenced by getCommand(), getCommands(), registerCommand(), and ~Shell().
1.8.17