2016-03-11 16:45:15 +00:00
|
|
|
#ifndef SHELL_H
|
|
|
|
#define SHELL_H
|
|
|
|
#include <iostream>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <cstring>
|
|
|
|
#include <vector>
|
|
|
|
#include <csignal>
|
2016-03-12 17:58:01 +00:00
|
|
|
#include "command.h"
|
2016-03-13 16:16:34 +00:00
|
|
|
//#include "commands.h"
|
|
|
|
#include "commandexecutor.h"
|
2016-03-11 16:45:15 +00:00
|
|
|
using std::string;
|
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
using std::cerr;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
using std::istringstream;
|
|
|
|
using std::nullptr_t;
|
|
|
|
|
2016-03-13 16:16:34 +00:00
|
|
|
class Shell : public CommandExecutor
|
2016-03-11 16:45:15 +00:00
|
|
|
{
|
2016-03-12 17:58:01 +00:00
|
|
|
class Commands
|
|
|
|
{
|
2016-03-13 16:16:34 +00:00
|
|
|
Shell* parent;
|
|
|
|
vector<Command*> commands; //commands that work the same thread of the shell
|
|
|
|
vector<Command*> threadCommands; //commands that work on a different thread
|
|
|
|
|
2016-03-12 17:58:01 +00:00
|
|
|
public:
|
2016-03-13 16:16:34 +00:00
|
|
|
Commands(Shell*);
|
|
|
|
void add(Command*, bool isthread=false);
|
|
|
|
size_t howMany() const;
|
|
|
|
int launch(const vector<string>* args, bool launchThread=false);
|
2016-03-12 17:58:01 +00:00
|
|
|
};
|
2016-03-11 16:45:15 +00:00
|
|
|
static bool undoingLine;
|
|
|
|
Commands cmds;
|
|
|
|
string ps;
|
|
|
|
string name;
|
|
|
|
void (*shellSetup)(Shell *);
|
2016-03-16 09:01:24 +00:00
|
|
|
void (*shellPostSetup)(Shell *);
|
2016-03-12 17:58:01 +00:00
|
|
|
bool notLoop;
|
2016-03-11 16:45:15 +00:00
|
|
|
|
2016-03-13 16:16:34 +00:00
|
|
|
int launchCmd(vector<string>* args);
|
2016-03-11 16:45:15 +00:00
|
|
|
static void EofHandler(int);
|
|
|
|
string* read_line();
|
2016-03-13 16:16:34 +00:00
|
|
|
vector<string>* split_line(const string* line);
|
2016-03-12 17:58:01 +00:00
|
|
|
|
|
|
|
class IsUndoingLineException {};
|
|
|
|
|
2016-03-11 16:45:15 +00:00
|
|
|
public:
|
2016-03-16 09:01:24 +00:00
|
|
|
Shell(string n="msh", string ps="MSH$", void (*s)(Shell*)=0, void (*pss)(Shell*)=0);
|
2016-03-11 16:45:15 +00:00
|
|
|
string getPs() const;
|
|
|
|
void setPs(const string &value);
|
|
|
|
string getName() const;
|
|
|
|
void setName(const string &value);
|
2016-03-12 17:58:01 +00:00
|
|
|
void launch();
|
2016-03-16 09:01:24 +00:00
|
|
|
void setShellSetup(void (*)(Shell *));
|
|
|
|
void (*getShellSetup())(Shell*);
|
|
|
|
void setShellPostSetup(void (*)(Shell *));
|
|
|
|
void (*getShellPostSetup())(Shell*);
|
2016-03-11 16:45:15 +00:00
|
|
|
//for in-shell commands
|
2016-03-13 16:16:34 +00:00
|
|
|
void addCmd(Command *cmd, bool isThread=false);
|
|
|
|
size_t howManyCmds() const;
|
|
|
|
int executeCmd(vector<string>* args);
|
|
|
|
int executeCmd(const string& args);
|
2016-03-12 17:58:01 +00:00
|
|
|
|
2016-03-16 09:01:24 +00:00
|
|
|
//excepsetions
|
2016-03-12 17:58:01 +00:00
|
|
|
class CommandNotFoundException{};
|
|
|
|
class ShellLaunchInSetupException{};
|
2016-03-11 16:45:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SHELL_H
|