diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2023-10-29 18:34:27 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2023-11-12 15:03:34 +1300 |
| commit | f998705c5a0e50021875a811537962083b73ed26 (patch) | |
| tree | 113406756207737ca3cee23809d1b020ee001cab /commands.cpp | |
| parent | 5dacf6d6d24eab71994e02b6b3c4fc6f6e309958 (diff) | |
| download | YATwm-f998705c5a0e50021875a811537962083b73ed26.tar.gz YATwm-f998705c5a0e50021875a811537962083b73ed26.zip | |
feat: Pretty much done IPC
Still need to add a program that uses the IPC, this potentially
requires restructuring the files
Diffstat (limited to 'commands.cpp')
| -rw-r--r-- | commands.cpp | 121 |
1 files changed, 61 insertions, 60 deletions
diff --git a/commands.cpp b/commands.cpp index 54fe891..57cfd0b 100644 --- a/commands.cpp +++ b/commands.cpp @@ -5,6 +5,7 @@ #include <cctype> #include <iostream> #include <algorithm> +#include <iterator> #include <stdexcept> #include <string> #include <utility> @@ -143,70 +144,70 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA { switch(argTypes[i-1]) { - case STR: args[i-1].str = (char*)split[i].c_str(); break; - case NUM: - { - try - { - args[i-1].num = std::stoi(split[i]); - break; - } - catch(std::invalid_argument e) - { - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); - } - } - case MOVDIR: - { - if(lowercase(split[i]) == "up") - args[i-1].dir = UP; - else if(lowercase(split[i]) == "down") - args[i-1].dir = DOWN; - else if(lowercase(split[i]) == "left") - args[i-1].dir = LEFT; - else if(lowercase(split[i]) == "right") - args[i-1].dir = RIGHT; - else - { - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!"); - } - break; - } - case STR_REST: + case STR: args[i-1].str = (char*)split[i].c_str(); break; + case NUM: + { + try + { + args[i-1].num = std::stoi(split[i]); + break; + } + catch(std::invalid_argument e) + { + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); + } + } + case MOVDIR: + { + if(lowercase(split[i]) == "up") + args[i-1].dir = UP; + else if(lowercase(split[i]) == "down") + args[i-1].dir = DOWN; + else if(lowercase(split[i]) == "left") + args[i-1].dir = LEFT; + else if(lowercase(split[i]) == "right") + args[i-1].dir = RIGHT; + else + { + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a direction!"); + } + break; + } + case STR_REST: + { + string rest = ""; + for(int j = i; j < split.size(); j++) + { + rest += split[j]; + if(j != split.size() - 1) + rest += " "; + } + args[i-1].str = new char[rest.size()]; + strcpy(args[i-1].str, rest.c_str()); + return args; + } + case NUM_ARR_REST: + { + int* rest = new int[split.size() - i]; + for(int j = 0; j < split.size() - i; j++) + { + try { - string rest = ""; - for(int j = i; j < split.size(); j++) - { - rest += split[j]; - if(j != split.size() - 1) - rest += " "; - } - args[i-1].str = new char[rest.size()]; - strcpy(args[i-1].str, rest.c_str()); - return args; + rest[j] = std::stoi(split[j + i]); } - case NUM_ARR_REST: + catch(std::invalid_argument e) { - int* rest = new int[split.size() - i]; - for(int j = 0; j < split.size() - i; j++) - { - try - { - rest[j] = std::stoi(split[j + i]); - } - catch(std::invalid_argument e) - { - delete[] rest; - delete[] args; - throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); - } - } - args[i-1].numArr = {rest, (int) split.size() - i}; - return args; + delete[] rest; + delete[] args; + throw Err(CMD_ERR_WRONG_ARGS, split[i] + " is not a number!"); } - default: cout << "UH OH SOMETHING IS VERY WRONG" << endl; + } + args[i-1].numArr = {rest, (int) split.size() - i}; + return args; + } + default: cout << "UH OH SOMETHING IS VERY WRONG" << endl; } } return args; |
