diff --git a/.gitignore b/.gitignore index a642095..a4aa8ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ + +/bin + # Prerequisites *.d diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fcb19a3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,53 @@ +{ + "files.associations": { + "*.html": "html", + "*.jsste": "plaintext", + "string": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/makefile b/makefile index 87aa1cd..deb14b4 100644 --- a/makefile +++ b/makefile @@ -1,3 +1,6 @@ all: - g++ -std=c++11 ./src/main.cpp -o ./src/autom - ./src/autom test \ No newline at end of file + mkdir -p bin + g++ -c ./src/main.cpp + g++ -c ./src/command.cpp + g++ -std=c++11 main.o command.o -o ./bin/autom + ./bin/autom help \ No newline at end of file diff --git a/src/autom b/src/autom deleted file mode 100644 index b2107ae..0000000 Binary files a/src/autom and /dev/null differ diff --git a/src/command.cpp b/src/command.cpp new file mode 100644 index 0000000..2383ee9 --- /dev/null +++ b/src/command.cpp @@ -0,0 +1,29 @@ +#include "command.h" +#include + +Command::Command() {} + +Command::~Command() {} + +void Command::addCommand(std::string name, void (*func)(char *argv[])) +{ + commands[name] = func; +} + +void Command::addDefaultCommand(void (*func)(char *argv[])) +{ + defaultCommand = func; +} + +void Command::runCommand(char *name, char *argv[]) +{ + std::cout << "Running command: " << name << std::endl; + if (commands.count(name) > 0) + { + commands[name](argv); + } + else + { + defaultCommand(argv); + } +} diff --git a/src/command.h b/src/command.h new file mode 100644 index 0000000..c193222 --- /dev/null +++ b/src/command.h @@ -0,0 +1,21 @@ +#ifndef COMMAND_H +#define COMMAND_H + +#include +#include + +class Command +{ +public: + Command(void); + ~Command(void); + void addCommand(std::string name, void (*func)(char *argv[])); + void addDefaultCommand(void (*func)(char *argv[])); + void runCommand(char *name, char *argv[]); + +private: + std::map commands; + void (*defaultCommand)(char *argv[]); +}; + +#endif // COMMAND_H \ No newline at end of file diff --git a/src/inputparser.h b/src/inputparser.h new file mode 100644 index 0000000..d318f04 --- /dev/null +++ b/src/inputparser.h @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + + +class InputParser +{ + std::map args; + public: + InputParser(int argc, char *argv[]) { + for (int i = 1; i < argc; i++) { + std::string arg(argv[i]); + if (arg.find("-") == 0) { + std::string key = arg.substr(1); + if (i + 1 < argc) { + std::string value(argv[i + 1]); + if (value.find("-") != 0) { + args[key] = value; + i++; + } else { + args[key] = ""; + } + } else { + args[key] = ""; + } + } + } + } + std::string getValue(std::string key) { + return args[key]; + } + bool hasKey(std::string key) { + return args.count(key) > 0; + } +}; diff --git a/src/main.cpp b/src/main.cpp index b42c6db..a2dc8ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,35 @@ -#include -#include -#include +#include "main.h" int main(int argc, char *argv[]) { - - // make dir in ~/autom - std::string home = getenv("HOME"); - std::string dir = home + "/autom"; - // std::cout << "dir: " << dir << std::endl; mkdir(dir.c_str(), 0777); - - if (argc > 1 && argv[1][0] != '-') - { - std::string pre_script = "cd " + dir + " && "; - std::string script = pre_script + dir + "/" + argv[1]; - system(script.c_str()); - } - // else{ - // std::cout << "Usage: autom