From e96a300f8e220641a2ab3b18d8dd7a59cb938214 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 16 Mar 2016 21:20:15 +0100 Subject: [PATCH] Removed old files --- .gitignore | 14 ++++ Msh.pro | 17 ---- cmds.cpp | 28 ------- cmds.h | 17 ---- command.cpp | 34 -------- command.h | 28 ------- commandexecutor.cpp | 6 -- commandexecutor.h | 15 ---- commands.cpp | 26 ------ main.cpp | 28 ------- shell.cpp | 196 -------------------------------------------- shell.h | 75 ----------------- 12 files changed, 14 insertions(+), 470 deletions(-) delete mode 100644 Msh.pro delete mode 100644 cmds.cpp delete mode 100644 cmds.h delete mode 100644 command.cpp delete mode 100644 command.h delete mode 100644 commandexecutor.cpp delete mode 100644 commandexecutor.h delete mode 100644 commands.cpp delete mode 100644 main.cpp delete mode 100644 shell.cpp delete mode 100644 shell.h diff --git a/.gitignore b/.gitignore index 33e6b18..1a755a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ +#kate directory files +*.directory + #Qt creator .pro.user *.pro.user +*.cbp +*.txt.user # Compiled Object files *.slo @@ -29,3 +34,12 @@ *.exe *.out *.app + +# cmake + +CMakeCache.txt +CMakeFiles +CMakeScripts +Makefile +cmake_install.cmake +install_manifest.txt diff --git a/Msh.pro b/Msh.pro deleted file mode 100644 index dcb25ea..0000000 --- a/Msh.pro +++ /dev/null @@ -1,17 +0,0 @@ -TEMPLATE = app -CONFIG += console c++11 -CONFIG -= app_bundle -CONFIG -= qt - -SOURCES += main.cpp \ - command.cpp \ - commands.cpp \ - cmds.cpp \ - shell.cpp \ - commandexecutor.cpp - -HEADERS += \ - command.h \ - shell.h \ - cmds.h \ - commandexecutor.h diff --git a/cmds.cpp b/cmds.cpp deleted file mode 100644 index 6ed319e..0000000 --- a/cmds.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/** - builtin commands -*/ - -#include "cmds.h" - -using namespace std; - -int Cmds::cdExecute(const vector* args, CommandExecutor*){ - if (args->operator[](1) == "\0") { - cerr << "expected argument to \"cd\"\n"; - } else { - if (chdir(args->operator[](1).c_str()) != 0) { - cerr << "error"; - } - } - return 1; -} - -int Cmds::exitExecute(const vector*, CommandExecutor*){ - return 0; //TODO: better exit signal giving -} - -int Cmds::helpExecute(const vector*, CommandExecutor*){ - cout << " info" << endl; - return 1; -} - diff --git a/cmds.h b/cmds.h deleted file mode 100644 index 9b6eec9..0000000 --- a/cmds.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CMDS_H -#define CMDS_H -#include "commandexecutor.h" -#include -#include -#include -#include -using std::string; -using std::vector; - -namespace Cmds { - int cdExecute(const vector* args, CommandExecutor*); - int exitExecute(const vector*, CommandExecutor*); - int helpExecute(const vector*, CommandExecutor*); -} - -#endif // CMDS_H diff --git a/command.cpp b/command.cpp deleted file mode 100644 index 93f0b7e..0000000 --- a/command.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "shell.h" - -Command::Command(const string& n, int (*funcptr)(const vector* args, CommandExecutor*)) : name(n) , funcCommand(funcptr){ - checkObj(); - numCom++; -} - -int Command::execute(const vector* args, CommandExecutor* ciao){ - if(args==nullptr) return -1; - return (*funcCommand)(args, ciao); -} - -string Command::getName(){ - return this->name; -} - -Command::Command(const Command& old) : name(old.name) , funcCommand(old.funcCommand){ - checkObj(); - numCom++; -} - -void Command::checkObj(){ - for(unsigned int i=0; i'a'&&name[i]<'z')||(name[i]>'A'&&name[i]<'Z'))){ - throw CommandNameNotValidException(); - } - } -} - -Command::~Command(){ - numCom--; -} - -unsigned int Command::numCom = 0; diff --git a/command.h b/command.h deleted file mode 100644 index ddf56a9..0000000 --- a/command.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef COMMAND_H -#define COMMAND_H -#include -#include -#include "shell.h" -#include "commandexecutor.h" - -using std::string; -using std::vector; - -class Command -{ - const string name; - static unsigned int numCom; - int (*funcCommand)(const vector*,CommandExecutor*); - void checkObj(); - -public: - Command(const string& n, int (*funcptr)(const vector* args, CommandExecutor*)); - Command(const Command&); - ~Command(); - string getName(); - int execute(const vector*, CommandExecutor* ciao); -}; - -class CommandNameNotValidException{}; - -#endif // COMMAND_H diff --git a/commandexecutor.cpp b/commandexecutor.cpp deleted file mode 100644 index 978d62f..0000000 --- a/commandexecutor.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "commandexecutor.h" - -CommandExecutor::CommandExecutor() -{ - -} diff --git a/commandexecutor.h b/commandexecutor.h deleted file mode 100644 index 5a54499..0000000 --- a/commandexecutor.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COMMANDEXECUTOR_H -#define COMMANDEXECUTOR_H -#include -#include - -class CommandExecutor -{ -public: - virtual int executeCmd(std::vector* args) = 0; - virtual int executeCmd(const std::string& args) = 0; - virtual size_t howManyCmds() const = 0; - CommandExecutor(); -}; - -#endif // COMMANDEXECUTOR_H diff --git a/commands.cpp b/commands.cpp deleted file mode 100644 index 23ad5c2..0000000 --- a/commands.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "shell.h" - -Shell::Commands::Commands(Shell* s) : commands(), threadCommands() -{ - parent = s; -} - -void Shell::Commands::add(Command* cmd, bool isthread){ - if(!isthread) commands.push_back(cmd); - else threadCommands.push_back(cmd); -} - -size_t Shell::Commands::howMany() const{ - return commands.size(); -} - -int Shell::Commands::launch(const vector* args, bool launchThread){ - for(unsigned int i=0; i<(launchThread ? threadCommands.size() : commands.size()); i++){ - if((launchThread ? threadCommands[i]->getName() : commands[i]->getName())==args->operator [](0)){ - return (launchThread ? threadCommands[i]->execute(args, parent) : commands[i]->execute(args, parent)); - } - } - throw CommandNotFoundException(); -} - - diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 6629e48..0000000 --- a/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include "shell.h" -#include "command.h" -#include "cmds.h" -using namespace std; -using namespace Cmds; - -static void setup(Shell *); - -int main(int argc, char **argv) -{ - string c = "msh-console-test"; - string ps = "[msh-console-test]:"; - Shell mshConsoleTest(c, ps, &setup); - - //add builtin commands - mshConsoleTest.addCmd(new Command("cd", &cdExecute)); - mshConsoleTest.addCmd(new Command("exit", &exitExecute)); - mshConsoleTest.addCmd(new Command("help", &helpExecute)); - mshConsoleTest.launch(); - return EXIT_SUCCESS; -} - -void setup(Shell *s){ - cout << "Now entering in test shell...\n" << endl; - s->executeCmd("stty -ctlecho"); -} diff --git a/shell.cpp b/shell.cpp deleted file mode 100644 index d97c065..0000000 --- a/shell.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "shell.h" - -string Shell::getPs() const -{ - return ps; -} - -void Shell::setPs(const string &value) -{ - ps = value; -} - -string Shell::getName() const -{ - return name; -} - -void Shell::setName(const string &value) -{ - name = value; -} - -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; -} - -void Shell::launch(){ - //launch setup - if(notLoop) { - throw ShellLaunchInSetupException(); - return; - } - if(shellSetup!=0) { - notLoop = true; - (*shellSetup)(this); - notLoop = false; - } - //launch loop - string* line; - vector* args; - int status; - do { - bool readSuccess; - do{ - cout << ps << " "; - try{ - line = read_line(); - readSuccess = true; - } - catch (IsUndoingLineException){ - cout << "\n"; - readSuccess = false; - } - }while(!readSuccess); - args = split_line(line); - status = executeCmd(args); - delete args; - } while (status); - if(shellPostSetup!=0) { - shellPostSetup(this); - } -} - -int Shell::launchCmd(vector* args) -{ - int status; - - pid_t pid = fork(); - if (pid == 0) { - //child process - - //execute threadCommand - int a; - try { - a=cmds.launch(args, true); - } - catch (CommandNotFoundException){ - //execute bash command or program - vector argv(args->size() + 1); - size_t i; - for (i = 0; i != args->size()-1; ++i) - { - argv[i] = &(args->operator[](i)[0]); - } - argv[i] = NULL; - if((a=execvp(argv[0], argv.data())) == -1) { - cerr << name <<": command " << args->operator [](0) << " not found\n"; - } - exit(EXIT_FAILURE); - } - exit(EXIT_SUCCESS); - } - else if (pid < 0) { - // Error forking - cerr << name <<": error forking the process\n"; - } - else { - // Parent process - do { - //wait until child finished - waitpid(pid, &status, WUNTRACED); - } while (!WIFEXITED(status) && !WIFSIGNALED(status)); - } - return 1; -} - -int Shell::executeCmd(vector* args) -{ - if (args->operator [](0) == "\0") { - // An empty command was entered. - return 1; - } - int ret; - try { - ret = cmds.launch(args, false); - } - catch(CommandNotFoundException) { - ret = launchCmd(args); - } - return ret; -} - -inline int Shell::executeCmd(const std::string &args){ - return executeCmd(split_line(&args)); -} - -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; - sa->sa_flags = 0; // not SA_RESTART!; - sigaction(SIGINT, sa, NULL); - delete sa; -} - -string* Shell::read_line() -{ - string* buffer = new string(); - setEofHandler(EofHandler); - getline(cin,*buffer); // get command - cin.clear(); // clear flags - - if(undoingLine){ - undoingLine=false; - throw IsUndoingLineException(); - } - return buffer; -} - -vector* Shell::split_line(const string* line) -{ - vector* tokens = new vector(); - string ln = *line; - istringstream is(ln); - int i; - for(i=0; getline(is, ln, ' '); i++){ - tokens->push_back(ln); - } - tokens->push_back("\0"); - return tokens; -} - -bool Shell::undoingLine = false; - -void Shell::addCmd(Command* cmd, bool isthread){ - cmds.add(cmd, isthread); -} - -size_t Shell::howManyCmds() const{ - return cmds.howMany(); -} diff --git a/shell.h b/shell.h deleted file mode 100644 index 192a0d8..0000000 --- a/shell.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef SHELL_H -#define SHELL_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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 commands; //commands that work the same thread of the shell - vector 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* args, bool launchThread=false); - }; - static bool undoingLine; - Commands cmds; - string ps; - string name; - void (*shellSetup)(Shell *); - void (*shellPostSetup)(Shell *); - bool notLoop; - - int launchCmd(vector* args); - static void EofHandler(int); - string* read_line(); - vector* 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* args); - int executeCmd(const string& args); - - //excepsetions - class CommandNotFoundException{}; - class ShellLaunchInSetupException{}; -}; - -#endif // SHELL_H