FreeNOS
Shell.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __BIN_SH_SHELL
19 #define __BIN_SH_SHELL
20 
21 #include <Types.h>
22 #include <POSIXApplication.h>
23 #include "ShellCommand.h"
24 
33 class Shell : public POSIXApplication
34 {
35  public:
36 
43  Shell(int argc, char **argv);
44 
48  virtual ~Shell();
49 
55  virtual Result exec();
56 
63  ShellCommand * getCommand(const char *name);
64 
71 
77  void registerCommand(ShellCommand *command);
78 
88  int executeInput(const Size argc, const char **argv, const bool background);
89 
96  int executeInput(char *cmdline);
97 
98  private:
99 
106 
111  char * getInput() const;
112 
116  void prompt() const;
117 
126  Size parse(char *cmdline, char **argv, Size maxArgv, bool *background);
127 
128  private:
129 
132 };
133 
138 #endif /* __BIN_SH_SHELL */
Shell::~Shell
virtual ~Shell()
Destructor.
Definition: Shell.cpp:54
Shell::exec
virtual Result exec()
Execute the application.
Definition: Shell.cpp:62
Shell::m_commands
HashTable< String, ShellCommand * > m_commands
All known ShellCommands.
Definition: Shell.h:131
HashTable< String, ShellCommand * >
Types.h
Shell::prompt
void prompt() const
Output a prompt.
Definition: Shell.cpp:289
ShellCommand
Builtin command for the Shell.
Definition: ShellCommand.h:38
POSIXApplication
POSIX-compatible application.
Definition: POSIXApplication.h:35
Shell
System command shell interpreter.
Definition: Shell.h:33
ShellCommand.h
Shell::executeInput
int executeInput(const Size argc, const char **argv, const bool background)
Executes the given input.
Definition: Shell.cpp:161
Shell::registerCommand
void registerCommand(ShellCommand *command)
Register a new ShellCommand.
Definition: Shell.cpp:322
POSIXApplication.h
Shell::Shell
Shell(int argc, char **argv)
Constructor.
Definition: Shell.cpp:40
Shell::getCommands
HashTable< String, ShellCommand * > & getCommands()
Get all shell commands.
Definition: Shell.cpp:312
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Shell::parse
Size parse(char *cmdline, char **argv, Size maxArgv, bool *background)
Parses an input string into separate pieces.
Definition: Shell.cpp:327
Application::Result
Result
Result codes.
Definition: Application.h:53
Shell::runInteractive
Result runInteractive()
Executes the Shell by entering an infinite loop.
Definition: Shell.cpp:135
Shell::getInput
char * getInput() const
Fetch a command text from standard input.
Definition: Shell.cpp:239
Shell::getCommand
ShellCommand * getCommand(const char *name)
Get shell command.
Definition: Shell.cpp:317