diff --git a/commands.cpp b/commands.cpp index b140c3d..23ad5c2 100644 --- a/commands.cpp +++ b/commands.cpp @@ -3,8 +3,6 @@ Shell::Commands::Commands(Shell* s) : commands(), threadCommands() { parent = s; - if(created) throw CommandsAlreadyCreatedException(); - created=true; } void Shell::Commands::add(Command* cmd, bool isthread){ @@ -25,6 +23,4 @@ int Shell::Commands::launch(const vector* args, bool launchThread){ throw CommandNotFoundException(); } -bool Shell::Commands::created = false; - diff --git a/main.cpp b/main.cpp index 20c9752..6629e48 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ int main(int argc, char **argv) return EXIT_SUCCESS; } -void setup(Shell *){ +void setup(Shell *s){ cout << "Now entering in test shell...\n" << endl; + s->executeCmd("stty -ctlecho"); } diff --git a/shell.cpp b/shell.cpp index facf731..d97c065 100644 --- a/shell.cpp +++ b/shell.cpp @@ -20,11 +20,12 @@ void Shell::setName(const string &value) name = value; } -Shell::Shell( string n, string ps,void (*s)(Shell*)) : cmds(this) +Shell::Shell( string n, string ps,void (*s)(Shell*), void (*pss)(Shell*)) : cmds(this) { shellSetup = s; name = n; this->ps = ps; + shellPostSetup = pss; notLoop = false; } @@ -60,6 +61,9 @@ void Shell::launch(){ status = executeCmd(args); delete args; } while (status); + if(shellPostSetup!=0) { + shellPostSetup(this); + } } int Shell::launchCmd(vector* args) @@ -129,6 +133,23 @@ void Shell::EofHandler(int){ undoingLine = true; } +void Shell::setShellSetup(void (*s)(Shell *)){ + shellSetup=s; +} + +void (*Shell::getShellSetup())(Shell*) { + return shellSetup; +} + +void Shell::setShellPostSetup(void (*s)(Shell *)){ + shellPostSetup=s; +} + +void (*Shell::getShellPostSetup())(Shell*) { + return shellPostSetup; +} + + void setEofHandler(void (*funcptr)(int)){ struct sigaction *sa = new struct sigaction(); sa->sa_handler = funcptr; diff --git a/shell.h b/shell.h index 26e57ca..192a0d8 100644 --- a/shell.h +++ b/shell.h @@ -29,11 +29,6 @@ class Shell : public CommandExecutor vector commands; //commands that work the same thread of the shell vector threadCommands; //commands that work on a different thread - //just one instance of the object - static bool created; - Commands(const Commands&); - Commands operator=(const Commands&); - public: Commands(Shell*); void add(Command*, bool isthread=false); @@ -45,6 +40,7 @@ class Shell : public CommandExecutor string ps; string name; void (*shellSetup)(Shell *); + void (*shellPostSetup)(Shell *); bool notLoop; int launchCmd(vector* args); @@ -55,21 +51,23 @@ class Shell : public CommandExecutor class IsUndoingLineException {}; public: - Shell(string n="msh", string ps="MSH$", void (*s)(Shell*)=0); + Shell(string n="msh", string ps="MSH$", void (*s)(Shell*)=0, void (*pss)(Shell*)=0); string getPs() const; void setPs(const string &value); string getName() const; void setName(const string &value); void launch(); - + void setShellSetup(void (*)(Shell *)); + void (*getShellSetup())(Shell*); + void setShellPostSetup(void (*)(Shell *)); + void (*getShellPostSetup())(Shell*); //for in-shell commands void addCmd(Command *cmd, bool isThread=false); size_t howManyCmds() const; int executeCmd(vector* args); int executeCmd(const string& args); - //exceptions - class CommandsAlreadyCreatedException{}; + //excepsetions class CommandNotFoundException{}; class ShellLaunchInSetupException{}; };