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
33class 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 */
Result
Result codes.
Definition Application.h:54
Efficient key -> value lookups.
Definition HashTable.h:45
POSIX-compatible application.
Builtin command for the Shell.
System command shell interpreter.
Definition Shell.h:34
void prompt() const
Output a prompt.
Definition Shell.cpp:289
Result runInteractive()
Executes the Shell by entering an infinite loop.
Definition Shell.cpp:135
void registerCommand(ShellCommand *command)
Register a new ShellCommand.
Definition Shell.cpp:322
ShellCommand * getCommand(const char *name)
Get shell command.
Definition Shell.cpp:317
HashTable< String, ShellCommand * > & getCommands()
Get all shell commands.
Definition Shell.cpp:312
char * getInput() const
Fetch a command text from standard input.
Definition Shell.cpp:239
HashTable< String, ShellCommand * > m_commands
All known ShellCommands.
Definition Shell.h:131
int executeInput(const Size argc, const char **argv, const bool background)
Executes the given input.
Definition Shell.cpp:161
virtual ~Shell()
Destructor.
Definition Shell.cpp:54
virtual Result exec()
Execute the application.
Definition Shell.cpp:62
Size parse(char *cmdline, char **argv, Size maxArgv, bool *background)
Parses an input string into separate pieces.
Definition Shell.cpp:327
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128