msh-console/shell.h

76 lines
1.9 KiB
C++

#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>
#include "command.h"
//#include "commands.h"
#include "commandexecutor.h"
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;
class Shell : public CommandExecutor
{
class Commands
{
Shell* parent;
vector<Command*> commands; //commands that work the same thread of the shell
vector<Command*> threadCommands; //commands that work on a different thread
public:
Commands(Shell*);
void add(Command*, bool isthread=false);
size_t howMany() const;
int launch(const vector<string>* args, bool launchThread=false);
};
static bool undoingLine;
Commands cmds;
string ps;
string name;
void (*shellSetup)(Shell *);
void (*shellPostSetup)(Shell *);
bool notLoop;
int launchCmd(vector<string>* args);
static void EofHandler(int);
string* read_line();
vector<string>* split_line(const string* line);
class IsUndoingLineException {};
public:
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<string>* args);
int executeCmd(const string& args);
//excepsetions
class CommandNotFoundException{};
class ShellLaunchInSetupException{};
};
#endif // SHELL_H